Beispiel #1
0
	public static void Run (Action<List<String>> fx, String[] args) {
		try {
			ExitCode=ExitCodes.InitError;  App.Init();
			ExitCode=ExitCodes.FxError;    fx(args.ToList());
			ExitCode=ExitCodes.ExitError;  App.Exit();
		} catch (Exception ex) {
			App.Crash(ex);
		}
	}
Beispiel #2
0
        public FileStructure(String[] rootFolders, List<StorageInformation> info)
        {
            if (_Index == null)
                _Index = new FileStructure();
            _Index.IndexRoots = new List<RootFolder>();

            _Index.algo = new UploadAlgorithm(info);
            _Index.InstantiateIndex(rootFolders.ToList<String>());
        }
 public int complexity(String s)
 {
     Sequitur alg = new Sequitur();
     List<String> strings = new List<string>();
     s.ToList().ForEach(c => strings.Add(c.ToString()));
     alg.Evaluate(strings);
     HashSet<Rule> rl = alg.getRules();
     int symbol_leght = 1; // start rule
     rl.ToList().ForEach(r => symbol_leght += r.Symbols.Count);
     return symbol_leght;
 }
        public static svm_node[] CreateNode(string x, IReadOnlyList<string> vocabulary)
        {
            var node = new List<svm_node>(vocabulary.Count);
            int sum = 0;
            List<string> allWords = new List<string>();
            x = x.Replace(",", "");
            Bigram b = new Bigram();

            String[] stopwords = new String[] { "hon.", "gentleman", "member", "friend", "lady", "a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "amoungst", "amount", "an", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "as", "at", "back", "be", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven", "else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "i", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own", "part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the" };
            List<String> stop = stopwords.ToList<String>();

            x = x.Replace(",", "");
            x = x.ToLower();
            String[] sp = x.Split(' ');
            String sent = "";
            for (int z = 0; z < sp.Length; z++)
            {
                String word = sp[z];
                if (stop.Contains(word))
                {
                    Debug.WriteLine("Stop Word");
                }
                else
                {
                    sent += word;
                    sent += " ";
                }
            }

            allWords = b.getNG(sent);

            string[] words = allWords.ToArray();

            for (int i = 0; i < vocabulary.Count; i++)
            {
                int occurenceCount = words.Count(s => String.Equals(s, vocabulary[i], StringComparison.OrdinalIgnoreCase));
                if (occurenceCount == 0)
                    continue;

                node.Add(new svm_node
                {
                    index = i + 1,
                    value = occurenceCount
                });
            }

                return node.ToArray();
        }
 public static string[] dirReduc(String[] arr)
 {
     List<string> directions = arr.ToList();
     List<string> input = new List<string>();
     for (int i = 0; i < directions.Count - 1; i++)
     {
         input = directions.GetRange(i, 2);
         if (input.OrderBy(s => s).SequenceEqual(EWPair.OrderBy(t => t)))
         {
             directions.RemoveRange(i, 2);
             directions = dirReduc(directions.ToArray()).ToList();
         }
         if (input.OrderBy(s => s).SequenceEqual(NSPair.OrderBy(t => t)))
         {
             directions.RemoveRange(i, 2);
             directions = dirReduc(directions.ToArray()).ToList(); ;
         }
     }
     return directions.ToArray();
 }
        public ActionResult Create(PromotionCreateModel promotion)
        {
            String[] stringList = new String[50];
            try
            {
                if (ModelState.IsValid)
                {
                    if (!String.IsNullOrEmpty(promotion.Tags))
                    {
                         stringList = promotion.Tags.Split(',');

                    }

                    using (var unitOfWork = new UnitOfWork())
                    {
                        var promId = unitOfWork.InsertPromotionDetailsByUsername(promotion.Price,promotion.Description,promotion.StartDate,promotion.EndDate,User.Identity.Name);
                        if (promId.HasValue)
                        {
                            foreach (var s in stringList.ToList())
                            {
                                if (!String.IsNullOrEmpty(s))
                                {
                                    var tag = s.Trim();
                                    unitOfWork.InsertPromotionTag(promId, tag);
                                }

                            }
                        }

                    }

                }

                    return RedirectToAction("Index");
            }
            catch(Exception ex)
            {
                return View();
            }
        }
        private static List<int> findSequence(String encodedText, String match)
        {
            int j = 0;
            List<Char> encodedTextSequence = encodedText.ToList();
            List<Char> matchTextSequence = match.ToList();
            List<int> sequence = new List<int>();
            while (sequence.Count < matchTextSequence.Count && j < encodedTextSequence.Count)
            {
                List<int> positions = matchTextSequence.Select((c, i) => new { character = c, index = i })
                         .Where(list => String.Compare(list.character.ToString(), encodedTextSequence[j].ToString(), true) == 0)
                         .Select(o => o.index).ToList();
                foreach (int pos in positions)
                {
                    if (!sequence.Contains(pos))
                    {
                        sequence.Add(pos);
                        break;
                    }
                }
                j++;

            }
            return sequence;
        }
		//public bool ImportData(String[] fileNamesToImport,
		//		Guid? foreignKeyToConnectTo = null,
		//		MaterialJPGForeignKeyConnectorenTyp foreignKeyTypToConnectTo = null)
		//	{
		//	List<MaterialJPG> NewMaterialJPGList = ImportData(fileNamesToImport,
		//		SelectedKoordinatenSource, SelectedMaterialJPGTyp, true,
		//		foreignKeyToConnectTo, foreignKeyTypToConnectTo);
		//	return (NewMaterialJPGList != null);
		//	}

		public List<MaterialJPG> ImportData(String[] fileNamesToImport, Ort selectedKoordinatenSource,
			MaterialJPGTyp selectedMaterialJPGTyp, bool showProgressUI, Guid? foreignKeyToConnectTo = null,
			MaterialJPGForeignKeyConnectorenTyp foreignKeyTypToConnectTo = null)
			{
			MaterialProgressDataModell ProgressModell = new MaterialProgressDataModell();
			Window ProgressWindow = new Window();
			if (showProgressUI)
				{
				ProgressModell = new MaterialProgressDataModell();
				ProgressModell.InsertProgressEntries(fileNamesToImport.ToList());
				ProgressWindow = new Window();
				ProgressWindow.Title = "ImportData gestarted";
				MaterialProgressView ProgressControl = new MaterialProgressView();
				ProgressControl.MaterialProgressDataModellInstance = ProgressModell;
				ProgressWindow.Content = ProgressControl;
				ProgressWindow.Show();
				}
			List<MaterialJPG> Result = new List<MaterialJPG>(); 
			ListOfFileNamesToImport = fileNamesToImport;
			int Index = 0;
			foreach (string fileNameToImport in ListOfFileNamesToImport)
				{
				if (showProgressUI)
					ProgressModell.SetStatus(Index, "Gestarted");
				MaterialJPG newMaterialRow = Data.DbServer3.Blob.MaterialienJPG.NewRow();
				newMaterialRow.Id = Guid.NewGuid();
				newMaterialRow.FullFileNameToLoadFrom = fileNameToImport.ToLower();
				FileInfo fileInfo = new FileInfo(fileNameToImport);

				newMaterialRow.Value = fileInfo.LoadAs_ByteArray();
				newMaterialRow.HashCode = newMaterialRow.Value.Sha1Hash().ConvertTo_Hex();
				newMaterialRow.ValueThumb = newMaterialRow.Value.ConvertTo_Image()
					.ResizeToMaximum(300, 200).ConvertTo_JpgByteArray(80);

				MaterialJPG[] EqualEntries = Data.DbServer3.Blob.MaterialienJPG.Load_AllForHashCode(newMaterialRow.HashCode);
				if (EqualEntries.Length > 0)
					{
					//MessageBox.Show("Es gibt einen Eintrag mit gleichem HashCode\r\n" +
					//                "gespeichert ist derzeit der File:\r\n\""
					//                + EqualEntries[0].FullFileNameToLoadFrom + "\"\r\n" +
					//                "der folgende File soll importiert werden:\r\n\"" +
					//                newMaterialRow.FullFileNameToLoadFrom + "\"\r\n" +
					//                "Dieser Eintrag wird übersprungen!!");
					if (showProgressUI)
						{
						ProgressModell.SetStatus(Index++, "Eintrag schon vorhanden");
						}

					Result.Add(EqualEntries[0]);
					continue;
					}
				newMaterialRow.LastWriteFileTime = fileInfo.LastWriteTime;
				newMaterialRow.TypId = selectedMaterialJPGTyp.Id;
				newMaterialRow.WLaengeOrt = selectedKoordinatenSource.WLaenge;
				newMaterialRow.WBreiteOrt = selectedKoordinatenSource.WBreite;
				String NamePart = Path.GetFileName(Path.GetDirectoryName(fileNameToImport)) + "\\"
				                  + Path.GetFileName(fileNameToImport);
				newMaterialRow.NameId = "Ort_" + fileInfo.LastWriteTime.ToString("yyyy-MM-dd_HH_mm") + "_" + NamePart;
				newMaterialRow.Description = "Ort_" + selectedKoordinatenSource.Bezeichnung;
				newMaterialRow.LastLoadTime = DateTime.Now;
				newMaterialRow.PictureTakenDateTime = fileInfo.LastWriteTime;
				Data.DbServer3.Blob.MaterialienJPG.Rows.Add(newMaterialRow);
				Data.DbServer3.Blob.SaveAnabolic(true);
				newMaterialRow.Value = null;
				Data.DbServer3.Blob.AcceptChanges();
				if (showProgressUI)
					ProgressModell.SetStatus(Index++, "Eintrag gespeichert");
				Result.Add(newMaterialRow);
				}
			if ((foreignKeyToConnectTo != null)
			    && (foreignKeyTypToConnectTo != null))
				{
				if (showProgressUI)
					{
					ProgressModell.CompletionStatus = "Bilder registriert";
					ProgressWindow.Title = "ImportData fertig, Die Daten werden jetzt verknüpft";
					}
				Index = 0;
				foreach (MaterialJPG materialJPG in Result)
					{
					MaterialJPGForeignKeyConnector foreignConnector
						= Data.DbServer3.Blob.MaterialJPGForeignKeyConnectoren.NewRow();
					foreignConnector.Id = Guid.NewGuid();
					foreignConnector.Description = materialJPG.Description;
					foreignConnector.ForeignId = foreignKeyToConnectTo;
					foreignConnector.JPGId = materialJPG.Id;
					foreignConnector.TypId = foreignKeyTypToConnectTo.Id;
					Data.DbServer3.Blob.MaterialJPGForeignKeyConnectoren.Rows.Add(foreignConnector);
					Data.DbServer3.Blob.SaveAnabolic();
					Data.DbServer3.Blob.AcceptChanges();
					if (showProgressUI)
						ProgressModell.SetStatus(Index++, "Eintrag verknüpft");
					}
				}
			if (showProgressUI)
				{
				ProgressModell.CompletionStatus = "Fertig";
				ProgressWindow.Title = "ImportData komplett fertig, Sie können dieses Fenster jetzt schließen";
				}
			return Result;
			}
Beispiel #9
0
 /**
  * Joins array of strings to one string with glue
  *
  * @param what Array of string to join
  * @param glue Glue for joined strings
  * @return Joined string
  */
 public static String join(String[] what, String glue)
 {
     return join(what.ToList(), glue);
 }
Beispiel #10
0
        private void button_AddClick(object sender, EventArgs e)
        {
            String listboxname = "lbx" + tctrlSettings.TabPages[m_selectedTabIndex].Name;
            String txtboxaddname = "tbxAdd" + tctrlSettings.TabPages[m_selectedTabIndex].Name + "Name";
            String txtboxaddval = "tbxAdd" + tctrlSettings.TabPages[m_selectedTabIndex].Name + "Value";
            ListBox lstBox = (ListBox)tctrlSettings.TabPages[m_selectedTabIndex].Controls.Find(listboxname, true)[0];
            TextBox txtBoxAddname = (TextBox)tctrlSettings.TabPages[m_selectedTabIndex].Controls.Find(txtboxaddname, true)[0];
            TextBox txtBoxAddvalue = (TextBox)tctrlSettings.TabPages[m_selectedTabIndex].Controls.Find(txtboxaddval, true)[0];
            String attribute = tctrlSettings.TabPages[m_selectedTabIndex].Name;
            String setting = "";
            String value = "";
            if (lstBox == null)
                return;
            if (txtBoxAddname == null)
                return;
            setting = txtBoxAddname.Text;
            value = txtBoxAddvalue.Text;
            m_iniFile.Add(attribute, setting, value);

            lstBox.Items.Clear();
            String[] array = new String[m_iniFile.Attributes[attribute].Keys.Count];
            m_iniFile.Attributes[attribute].Keys.CopyTo(array, 0);
            var list = array.ToList<String>();
            list.Sort();
            foreach (String key in list)
                lstBox.Items.Add(key);
        }
Beispiel #11
0
        public bool SendEmail(string sentFrom, String[] sentTo, String[] ccList, string subject, ListDictionary replacements, string emailTemplateName)
        {
            string emailSendEnabledSetting = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailSendEnabled);

            if (emailSendEnabledSetting.ToLower() != "true")
            {
                mLog.Info("CMS setting 'SendEmailEnabled' is set to False.  Exiting SendEmail() method.");
                return false;
            }

            MailDefinition md = new MailDefinition();
            md.Subject = subject;
            md.From = sentFrom;

            StringBuilder emailTemplate = new StringBuilder();
            string filePath = GetMailDefinitionFilePath(emailTemplateName);

            if (!File.Exists(filePath))
            {
                mLog.Error("Could not find html file for email named '{0}'.", filePath);
                throw new FileNotFoundException(string.Format("Could not find html file for email named '{0}'.", filePath));
            }

            emailTemplate.Append(ReadEmailTemplate(filePath));
            MailMessage message = md.CreateMailMessage(string.Join(",", sentTo), replacements, emailTemplate.ToString(), new System.Web.UI.Control());
            message.IsBodyHtml = true;

            //message.From = new MailAddress(sentFrom);
            ccList.ToList().ForEach(message.CC.Add);

            SmtpClient client = new SmtpClient();
            client.Host = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailMailHost);

            try
            {
                //SEND!
                string testEmail = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailDefaultTest);

                if (IsValidEmailaddress(testEmail))
                {
                    InterceptEmail(message, testEmail);
                }

                mLog.Info("Sending email.{0}From = {1}{0}To = {2}{0}Cc = {3}{0}Host = {4}.",
                         Environment.NewLine, message.From, message.To, message.CC, client.Host);

                mLog.Verbose("{0}", message.Body);
                client.Send(message);
            }
            catch (Exception exception)
            {
                mLog.Error(exception.Message, exception, "Possible relay error");
                if (exception.InnerException != null)
                {
                    mLog.Error(exception.InnerException.Message, exception.InnerException, "Possible relay error inner exception.");
                }
            }

            return true;
        }
 //Eliminating duplicates(if it contains in the file)
 private String[] removeDuplicates(String[] arr)
 {
     List<String> list = arr.ToList();
     list = list.Distinct().ToList();
     return list.ToArray();
 }
 ///END: Instruction definitions
 //
 /// <summary>
 /// Accumulator - Parses through the contents of an instruction.
 /// </summary>
 /// <param name="input">An array of input generated from parserAccumulator</param>
 private void DoAccumulator(String[] input)
 {
     String[] args;
     //instrucitonCount += 1;
     switch (input[0])
     {
         case "LOAD":
             args = input[1].Split(new Char[] { '(', ')' });
             LOAD(int.Parse(args[0]), memoryPointer);
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "LOADI":
             args = input[1].Split(new Char[] { '(', ')' });
             LOADI(int.Parse(args[0]), int.Parse(args[1]), memoryPointer);
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "STORE":
              args = input[1].Split(new Char[] { '(', ')' });
             STORE(int.Parse(args[0]), memoryPointer);
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "STOREI":
             args = input[1].Split(new Char[] { '(', ')' });
             STOREI(int.Parse(args[0]), int.Parse(args[1]), memoryPointer);
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "ADD":
             args = input[1].Split(new Char[] { '(', ')' });
             ADD(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "ADDI":
             args = input[1].Split(new Char[] { '(', ')' });
             ADDI(int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "AND":
             args = input[1].Split(new Char[] { '(', ')' });
             AND(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "OR":
             args = input[1].Split(new Char[] { '(', ')' });
             OR(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "NOT":
             NOT();
             instrucitonCount += 1;
             break;
         case "XOR":
             args = input[1].Split(new Char[] { '(', ')' });
             XOR(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "JUMP":
             int vsl;
             if (int.TryParse(input[1],out vsl))
             {
                 JUMP(vsl);
             }
             else
                 JUMP(input[1]);
             instrucitonCount += 1;
             break;
         case "BZERO":
             args = input[1].Split(new Char[] { '(', ')' });
             BZERO(memoryPointer, int.Parse(args[0]));
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "SEQ":
             args = input[1].Split(new Char[] { '(', ')' });
             SEQ(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "SNE":
             args = input[1].Split(new Char[] { '(', ')' });
             SNE(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "SGT":
             args = input[1].Split(new Char[] { '(', ')' });
             SGT(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "SLT":
             args = input[1].Split(new Char[] { '(', ')' });
             SLT(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "SGE":
             args = input[1].Split(new Char[] { '(', ')' });
             SGE(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "SLE":
             args = input[1].Split(new Char[] { '(', ')' });
             SLE(memoryPointer, int.Parse(args[0]));
             instrucitonCount += 1;
             break;
         case "PUSH":
             if (input.Length == 2)
             {
                 args = input[1].Split(new Char[] { '(', ')' });
                 PUSH(memoryPointer, int.Parse(args[0]));
             }
             else
                 PUSH();
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "POP":
             POP();
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "CALL":
             args = input[1].Split(new Char[] { '(', ')' });
             CALL(memoryPointer, int.Parse(args[0]));
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         case "RET":
             RET();
             referenceCount += 1;
             instrucitonCount += 1;
             break;
         default:
             //Add the tag to if that is what it represents
             if (input[0].Contains(":"))
             {
                 List<string> tempInput = input.ToList();
                 tempInput.RemoveAt(0);
                 DoAccumulator(tempInput.ToArray());
                 break;
             }
             Console.WriteLine("An error has been found, cannot compute instruction at line {0}", currentCounter);
             break;
     }
 }
Beispiel #14
0
        static void Main()
        {
            const string dataFilePath = @"C:\Users\Rory\Desktop\Han.csv";
            List<String> negwords = new List<String>();
            List<String> poswords = new List<String>();
            sentC = new List<String>();
            //String negFile = "C:/Users/Rory/Desktop/negative-words.txt";
            //String posFile = "C:/Users/Rory/Desktop/positive-words.txt";
            //GetNeg(negwords, negFile);
            //GetNeg(poswords, posFile);

            String[] stopwords = new String[]{"hon.","gentleman","member","friend","lady","a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount",  "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as",  "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "i","ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"};
            List<String> stop = stopwords.ToList<String>();
            var dataTable = DataTable.New.ReadCsv(dataFilePath);
            List<string> x = dataTable.Rows.Select(row => row["Text"]).ToList();
            double[] y = dataTable.Rows.Select(row => double.Parse(row["IsPos"])).ToArray();

            //var vocab = x.SelectMany(GetWords).Distinct().OrderBy(word => word).ToList();

            Bigram b = new Bigram();
            List<String> v = new List<string>();

            String sent = "";

            for(int i = 0; i < x.Count; i++)
            {
                String c = x[i].ToString();

                c = c.Replace(",", "");
                c = c.ToLower();
                String[] sp = c.Split(' ');
                for (int z = 0; z < sp.Length; z++)
                {
                    String word = sp[z];
                    if(stop.Contains(word))
                    {
                        Debug.WriteLine("Stop Word");
                    }
                    else
                    {
                        sent += word;
                        sent += " ";
                    }
                }

                sent = sent.Trim();

                v.AddRange(b.getNG(sent));

                sent = "";
            }
              // int bound = v.Count();
              //v.AddRange(negwords);
              //  int nBound = v.Count();
              //v.AddRange(poswords);
              //  v = v.Distinct().ToList();
            var problemBuilder = new TextClassificationProblemBuilder();
            var problem = problemBuilder.CreateProblem(x, y, v);

            ProblemHelper.WriteProblem(@"C:\Users\Rory\Desktop\hanData.problem", problem);

            problem = ProblemHelper.ReadProblem(@"C:\Users\Rory\Desktop\hanData.problem");

            const int C = 1;
            var model = new C_SVC(problem, KernelHelper.LinearKernel(), C);

            var accuracy = model.GetCrossValidationAccuracy(10);
            Console.WriteLine("Accuracy of the model is {0:P}", accuracy);

            string userInput;
            _predictionDictionary = new Dictionary<int, string> { { -1, "Negative" }, { 1, "Positive" } };
            getSent();
            for (int i = 0; i < nText.Count; i++)
            {
                userInput = nText[i].ToString();
                var newX = TextClassificationProblemBuilder.CreateNode(userInput, v);
                var predictedY = model.Predict(newX);

                Console.WriteLine("The prediction is {0}", _predictionDictionary[(int)predictedY]);
                String pred = _predictionDictionary[(int)predictedY];
                Console.WriteLine(new string('=', 50));
               sentC.Add(pred);
            }

            addToO();
            getNumbers();
            forPeople();

            using(StreamWriter file = new StreamWriter(@"C:\Users\Rory\Desktop\Peop.csv"))
            {
                file.WriteLine("PersID,Name,Positive,Negative,Party");
                for(int i = 0; i < pl.Count; i++)
                {
                    String line = pl[i].getID().ToString() + "," + pl[i].getName().ToString() + "," + pl[i].getPos().ToString() + "," + pl[i].getNeg().ToString() + "," + pl[i].getParty().ToString();
                    //var json = JsonConvert.SerializeObject(pl[i]);
                    file.WriteLine(line);
                }
            }

            using (StreamWriter file = new StreamWriter(@"C:\Users\Rory\Desktop\PositiveSent.csv"))
            {
                file.WriteLine("SpeakerID,TargetID,Text,Sentiment");
                for (int i = 0; i < ps.Count; i++)
                {
                    String line = ps[i].getSID().ToString() + "," + ps[i].getAID().ToString() + "," + ps[i].getText().ToString() + "," + ps[i].getSent().ToString();
                    file.WriteLine(line);
                }
            }

            using (StreamWriter file = new StreamWriter(@"C:\Users\Rory\Desktop\NegativeSent.csv"))
            {
                file.WriteLine("SpeakerID,TargetID,Text,Sentiment");
                for (int i = 0; i < ns.Count; i++)
                {
                    String line = ns[i].getSID().ToString() + "," + ns[i].getAID().ToString() + "," + ns[i].getText().ToString() + "," + ns[i].getSent().ToString();
                    file.WriteLine(line);
                }
            }

            ns.AddRange(ps);
            doSwap();

            var json = "{\"nodes\":";
            json += JsonConvert.SerializeObject(pl);
            json += ",";

            var edge = "\"edges\":";
            edge += JsonConvert.SerializeObject(nss);
            edge += "}";

            var fullJSON = json + edge;
            Debug.Write(fullJSON);

            using (StreamWriter file = new StreamWriter(@"C:\Users\Rory\Desktop\Nodes2.JSON"))
            {
                file.Write(fullJSON);

            }

            getRels();
            List<Relationship> sl = rl.OrderBy(o=>o.source).ToList();
            var edges = "\"links\":";
            edges += JsonConvert.SerializeObject(sl);
            edges += "}";

            var fullJ = json + edges;

            using (StreamWriter file = new StreamWriter(@"C:\Users\Rory\Desktop\Rels2.JSON"))
            {
                file.Write(fullJ);

            }
        }
 public static String[] String_Array_Push(String[] _input,string item)
 {
     List<string> temp = _input.ToList();
     temp.Add(item);
     return temp.ToArray();
 }
        ///END: Instruciton definitions
        /// <summary>
        /// Accumulator - Parses through the contents of an instruction.
        /// </summary>
        /// <param name="input">An array of input generated from parserAccumulator</param>
        private void DoRegister(String[] input)
        {
            String[] args;
            int reg1 = 0;
            int reg2 = 0;
            int address = 0;

            switch (input[0])
            {
                case "LOAD":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    LOAD(ref reg1, int.Parse(args[0]), allRegisters.Reg[args[1]]);
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    referenceCount += 1;
                    break;
                case "LOADI":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    LOADI(ref reg1, int.Parse(args[0]), int.Parse(args[1]), allRegisters.Reg[args[2]]);
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    referenceCount += 1;
                    break;
                case "STORE":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    STORE(reg1, int.Parse(args[0]), address);
                    instrucitonCount += 1;
                    referenceCount += 1;
                    break;
                case "STOREI":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    STOREI(reg1, int.Parse(args[0]), int.Parse(args[1]), allRegisters.Reg[args[2]]);
                    instrucitonCount += 1;
                    referenceCount += 1;
                    break;
                case "ADD":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    ADD(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "ADDI":
                    reg1 = allRegisters.Reg[input[1]];
                    ADDI(ref reg1, int.Parse(input[2]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "AND":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    AND(ref reg1, int.Parse(args[1]), int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "OR":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    OR(ref reg1, int.Parse(args[1]), int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "NOT":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    NOT(ref reg1);
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "XOR":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    XOR(ref reg1, int.Parse(args[1]), int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "MOVE":
                    reg1 = allRegisters.Reg[input[1]];
                    reg2 = allRegisters.Reg[input[2]];
                    MOVE(ref reg1, ref reg2);
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "JUMP":
                    int vsl;
                    if (int.TryParse(input[1], out vsl))
                    {
                        JUMP(vsl);
                    }
                    else
                        JUMP(input[1]);
                    instrucitonCount += 1;
                    break;
                case "BZERO":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    BZERO(reg1, address, int.Parse(args[0]));
                    referenceCount += 1;
                    instrucitonCount += 1;
                    break;
                case "SEQ":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    SEQ(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "SNE":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    SNE(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "SGT":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    SGT(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "SLT":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    SLT(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "SLE":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    SLE(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "SGE":
                    args = input[2].Split(new Char[] { '(', ')' });
                    reg1 = allRegisters.Reg[input[1]];
                    address = allRegisters.Reg[args[1]];
                    SGE(ref reg1, address, int.Parse(args[0]));
                    allRegisters.Reg[input[1]] = reg1;
                    instrucitonCount += 1;
                    break;
                case "PUSH":
                    reg1 = allRegisters.Reg[input[1]];
                    PUSH(reg1);
                    referenceCount += 1;
                    instrucitonCount += 1;
                    break;
                case "POP":
                    reg1 = allRegisters.Reg[input[1]];
                    POP(ref reg1);
                    allRegisters.Reg[input[1]] = reg1;
                    referenceCount += 1;
                    instrucitonCount += 1;
                    break;
                case "CALL":
                    args = input[1].Split(new Char[] { '(', ')' });
                    address = allRegisters.Reg[args[1]];
                    CALL(address, int.Parse(args[0]));
                    referenceCount += 1;
                    instrucitonCount += 1;
                    break;
                case "RET":
                    RET();
                    referenceCount += 1;
                    instrucitonCount += 1;
                    break;
                default:
                    //Add the tag to if that is what it represents
                    if (input[0].Contains(":"))
                    {
                        List<string> tempInput = input.ToList();
                        tempInput.RemoveAt(0);
                        DoRegister(tempInput.ToArray());
                        break;
                    }
                    Console.WriteLine("An error has been found, cannot compute instruction at line {0}", currentCounter);
                    break;
            }
        }
Beispiel #17
0
        private void SetUserPassword(String value)
        {
            _UserPassword = new SecureString();

            value.ToList().ForEach(_UserPassword.AppendChar);
        }
        //Send notification to user via email.
        /// <summary>
        /// Uses SES to send an email to a user.
        /// </summary>
        /// <param name="userID">The user being sent the email</param>
        /// <param name="inputSubject">The subject of the email</param>
        /// <param name="inputBody">The body of the email</param>
        public static void SendEmail(int userID, string inputSubject, string inputBody)
        {
            try
            {
                String email = (from userprofiles in userDb.UserProfiles
                                where userprofiles.UserId == userID
                                select userprofiles.Email).FirstOrDefault(); ; //Find userID's email address.

                if (inputSubject == "")
                {
                    inputSubject = "The Cookbook - New Notification Waiting For You";
                }

                if (inputBody == "")
                {
                    inputBody = "You have received a new notification. Visit The Cookbook for more information.";
                }

                String[] arrayTO = new String[1];
                arrayTO[0] = email;

                List<string> listTO = arrayTO.ToList<String>();

                // Construct an object to contain the recipient address.
                Destination destination = new Destination().WithToAddresses(listTO);

                String FROM = "*****@*****.**";
                String SUBJECT = inputSubject;
                String BODY = inputBody;

                // Create the subject and body of the message.
                Content subject = new Content().WithData(SUBJECT);
                Content textBody = new Content().WithData(BODY);
                Body body = new Body().WithText(textBody);

                // Create a message with the specified subject and body.
                Message message = new Message().WithSubject(subject).WithBody(body);

                // Assemble the email.
                SendEmailRequest request = new SendEmailRequest().WithSource(FROM).WithDestination(destination).WithMessage(message);

                AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient();

                SendEmailResponse response = client.SendEmail(request);
                Console.WriteLine("Sent successfully.");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Returns the file name, if found, of the file corresponding to criteria
        /// </summary>
        /// <param name="files"></param>
        /// <param name="fileType"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private static String SearchFilename(String[] files, FugaIngestionFileType fileType, object parameter = null)
        {
            if (files == null || files.Length == 0)
            {
                return String.Empty;
            }
            var filesList = files.ToList();

            switch (fileType)
            {
                case FugaIngestionFileType.Attachment:
                    foreach (var file in filesList)
                    {
                        var nameExtension = file.Split('.').Last().ToLower();
                        if  (
                                !String.IsNullOrEmpty(nameExtension)
                                && String.Compare(nameExtension, "pdf", StringComparison.Ordinal) == 0
                            )
                        {
                            return file;
                        }
                    }
                    break;

                case FugaIngestionFileType.AudioTrack:
                    if (parameter != null)
                    {
                        var volumeIndex = ((KeyValuePair<int, int>)parameter).Key;
                        var trackIndex = ((KeyValuePair<int, int>)parameter).Value;
                        foreach (var file in filesList)
                        {
                            var nameExtension = file.Split('.').Last().ToLower();
                            if  (
                                    String.IsNullOrEmpty(nameExtension)
                                    ||
                                    (
                                        String.Compare(nameExtension, "wav", StringComparison.Ordinal) != 0
                                        && String.Compare(nameExtension, "aif", StringComparison.Ordinal) != 0
                                        && String.Compare(nameExtension, "aiff", StringComparison.Ordinal) != 0
                                    )
                                )
                            {
                                continue;
                            }
                            var nameLeft = file.Substring(0, file.Length - nameExtension.Length - 1);
                            var nameElements = nameLeft.Split('-');
                            var nameElementsCount = nameElements.ToList().Count();
                            if (nameElementsCount < 3)
                            {
                                continue;
                            }
                            int tryVolumeIndex;
                            int tryTrackIndex;
                            var convertVolume = int.TryParse(nameElements[nameElementsCount - 2], out tryVolumeIndex);
                            var convertTrack = int.TryParse(nameElements[nameElementsCount - 1], out tryTrackIndex);
                            if  (
                                    convertVolume
                                    && convertTrack
                                    && tryVolumeIndex.Equals(volumeIndex)
                                    && tryTrackIndex.Equals(trackIndex)
                                )
                            {
                                // Found !
                                return file;
                            }
                        }
                    }
                    break;

                case FugaIngestionFileType.Cover:
                    foreach (var file in filesList)
                    {
                        var nameExtension = file.Split('.').Last().ToLower();
                        if  (
                                !String.IsNullOrEmpty(nameExtension)
                                &&
                                (
                                    String.Compare(nameExtension, "jpg", StringComparison.Ordinal) == 0
                                    || String.Compare(nameExtension, "jpeg", StringComparison.Ordinal) == 0
                                    || String.Compare(nameExtension, "png", StringComparison.Ordinal) == 0
                                )
                            )
                        {
                            return file;
                        }
                    }
                    break;
            }
            return String.Empty;
        }
Beispiel #20
0
        private void RemoveDuplicatePasswordsClicked(object sender, EventArgs e)
        {
            String[] lines = new String[Auth.Passwords.Count];
            Auth.Passwords.CopyTo(lines, 0);
            List<string> newList = lines.ToList().Distinct().ToList();
            Auth.Passwords.Clear();

            foreach (String line in newList)
            {
                Auth.Passwords.Add(line);
            }

            MessageBox.Show(this, "Removed " + (lines.Length - newList.Count) + " duplicates.", "Removal Successful", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        //Send notification to user via email.
        /// <summary>
        /// Uses SES to send an email to a user.
        /// </summary>
        /// <param name="email">The email.</param>
        private void SendEmail(String email)
        {
            try
            {
                String[] arrayTO = new String[1];
                arrayTO[0] = email;

                List<string> listTO = arrayTO.ToList<String>();

                // Construct an object to contain the recipient address.
                Destination destination = new Destination().WithToAddresses(listTO);

                String FROM = "*****@*****.**";
                String SUBJECT = "Welcome to Cookbook!";
                String BODY = "Welcome to Cookbook! Thank you so much for joining us. We hope that you will enjoy using our website.";

                // Create the subject and body of the message.
                Content subject = new Content().WithData(SUBJECT);
                Content textBody = new Content().WithData(BODY);
                Body body = new Body().WithText(textBody);

                // Create a message with the specified subject and body.
                Message message = new Message().WithSubject(subject).WithBody(body);

                // Assemble the email.
                SendEmailRequest request = new SendEmailRequest().WithSource(FROM).WithDestination(destination).WithMessage(message);

                AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient();

                SendEmailResponse response = client.SendEmail(request);
                Console.WriteLine("Sent successfully.");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #22
0
        public Program(String[] program, String[] registers, String[] memory, Boolean isSingle, int cycleLimit)
        {
            this.instruction = new List<Instruction>();
            this.cycle = new List<Cycle>();
            this.registers = new List<Register>();
            this.memory = new List<Memory>();

            List<String> programList = program.ToList<String>();

            for (int i = 0; i < programList.Count(); i++)
            {
                Console.WriteLine(i + ":" + programList.ElementAt(i)+".");
            }

            for (int i = 0; i < programList.Count(); i++) 
            {
                //Console.WriteLine(i + ":" + programList.ElementAt(i));
                if (programList.ElementAt(i).Equals("") || programList.ElementAt(i).Equals(" ") || programList.ElementAt(i).Equals(13) || programList.ElementAt(i).Equals(0))
                {
                    //Console.WriteLine("Removed line i=" + i);
                    programList.RemoveAt(i);
                    i--;
                }
            }

            this.program = programList.ToArray();

            this.initializeInstructionArray(this.program);
            this.intializeRegisterArray(registers);
            this.intializeMemoryArray(memory);
            
            this.instructionsValid = this.isValid();
            this.registersValid = isRegistersValid();
            this.memoryValid = isMemoryValid();

            if (isProgramValid())
            {
                if (this.instructionsValid && hasBranch)
                {
                    this.setBranchOffsets();
                }

                for (int i = 0; i < instruction.Count(); i++)
                {
                    this.instruction[i].getOpcode().setHexOpcodeString();
                }
                //showAllOpcodes();
                showAllHexOpcodes();
                if (this.instructionsValid)
                {
                    if (isSingle)
                    {
                        this.singleExecPipeline(cycleLimit);
                    }
                    else
                    {
                        this.pipeline();
                    }
                }
                    
                    
            }              
        }
Beispiel #23
0
 protected int Value(String val)
 {
     return val.ToList().Sum(c => LETTERS.IndexOf(c) + 1);
 }
        protected void validateJSON(String json, String []functions, String[] expressions, Object[] expectedValues, String testid
            , String significance =null)
        {
            JSExcuteUtil.JsonValueSet jvset = new JSExcuteUtil.JsonValueSet();
            jvset.varname = "testdata";
            for (int expdone = 0; expdone < expressions.Length; expdone++)
            {
                jvset.expressions2ExpectedValue[expressions[expdone]]=expectedValues[expdone];
            }

            if (functions!=null)
            {
                jvset.extraFunctions = functions.ToList();
            }

            jvset.json = json;
            jvset.significance = significance;
            Dictionary<string, object> results = util.extractValuesFromJson(jvset, GetType().Name + "." +testid);
            for (int done = 0; done < expressions.Length; done++ )
            {
                Object expectedValue = expectedValues[done];
                String expression = expressions[done];
                object actualValue = results[expression];
                if (expectedValue !=null && (expectedValue is Char || expectedValue is char))
                {
                    expectedValue = expectedValue.ToString();
                }
                Assert.AreEqual(expectedValue, actualValue, "json=" + json + " expression=" + expression);
            }
        }