Esempio n. 1
0
        public void JoinPhrasesZero()
        {
            PhraseParser  phraseParser = new PhraseParser();
            string        text         = File.ReadAllText("TestData" + Path.DirectorySeparatorChar + "GoodsAndServicesSample.txt");
            List <string> tokens       = Tokenizer.GetTokens(text, "games");

            phraseParser.JoinAllPhrases(ref tokens, 5, 10);


            Assert.AreEqual(0, tokens.Count);
        }
Esempio n. 2
0
        public void OnePairAtTheEnd()
        {
            PhraseParser phraseParser = new PhraseParser();
            string       text         = "Cat scratching pads; Coatstands; Costume stands; Deck chairs; Display boards; Display stands;scratching pads Filing cabinets; Furniture; Furniture, namely, showcases; scratching pads Inflatable furniture; Kennels for household pets; Magazine racks; Nesting boxes for household pets; Office furniture; scratching pads Pet cushions; Scratching posts for cats; Screens; Storage racks; Jewellery organizer displays; Non-metal trestles for supporting tables;scratching pads Shelving and component parts thereof, namely, shelves and brackets sold as a unit scratching pads";

            List <string> tokens = Tokenizer.GetTokens(text, "cats");

            phraseParser.JoinPhrases(ref tokens, 2, 2);

            Assert.AreEqual("scratching pads", tokens.Last());
        }
Esempio n. 3
0
        public void JoinPhrasesLowThreshold()
        {
            PhraseParser  phraseParser = new PhraseParser();
            string        text         = File.ReadAllText("TestData" + Path.DirectorySeparatorChar + "GoodsAndServicesSample.txt");
            List <string> tokens       = Tokenizer.GetTokens(text, "cat");

            phraseParser.JoinAllPhrases(ref tokens, 1, 1);


            Assert.IsNotNull(tokens);
        }
Esempio n. 4
0
        public void JoinPhrasesNone()
        {
            PhraseParser phraseParser = new PhraseParser();

            string        text       = File.ReadAllText("TestData" + Path.DirectorySeparatorChar + "GoodsAndServicesSample.txt");
            List <string> tokens     = Tokenizer.GetTokens(text, "qwertyuiop[]");
            int           firstCount = tokens.Count;

            phraseParser.JoinAllPhrases(ref tokens, 5, 10);


            Assert.AreEqual(firstCount, tokens.Count);
        }
Esempio n. 5
0
        static void RunQuery(string text)
        {
            List <string> tokens       = Tokenizer.GetTokens(text);
            PhraseParser  phraseParser = new PhraseParser();

            phraseParser.JoinAllPhrases(ref tokens, 2, 2);

            Console.WriteLine("Phrases used in the article:");
            tokens = WordService.RemoveStopwordPhrases(tokens);

            foreach (string t in tokens.Where(s => s.Contains(" ")).OrderBy(s => s.Length).Reverse().Distinct())
            {
                Console.WriteLine(t);
            }
        }
        public static (List <CountedWord> ImportantWords, List <SentenceFragment> ExampleFragments)   Search(string DatabaseFilepath,
                                                                                                             DateTime from,
                                                                                                             DateTime to,
                                                                                                             List <int> classes,
                                                                                                             string keyword,
                                                                                                             int selectLimit,
                                                                                                             bool useFilingDate,
                                                                                                             int maxWordsAround,
                                                                                                             int resultsLimit)
        {
            List <CountedWord>      importantWords   = new List <CountedWord>();
            List <SentenceFragment> exampleFragments = new List <SentenceFragment>();

            string text = DAO.GetText(DatabaseFilepath, from, to, classes, keyword, selectLimit, useFilingDate);

            if (text.Length > 0)
            {
                WordSequenceParser wordSequenceParser = new WordSequenceParser(new Stemmer(), maxWordsAround);
                var          words        = Tokenizer.GetTokens(text, keyword);
                PhraseParser phraseParser = new PhraseParser();
                phraseParser.JoinAllPhrases(ref words, 2, 1);

                List <SentenceFragment>   sentenceFragments = wordSequenceParser.FindSentenceFragments(new List <string>(words), keyword);
                IEnumerable <CountedWord> countedStems      = wordSequenceParser.CountWordOccurancesInSequences(sentenceFragments);

                importantWords = countedStems.Where(x => x.Count > 0 && !WordService.IsStopword(x.Word.FullWord) && x.Word.FullWord.Length > 2)
                                 .OrderBy(x => x, new CountedWordComparer())
                                 .Take(resultsLimit).ToList();

                exampleFragments = sentenceFragments.Where(s => s.ContainsAnyStems(importantWords.Select(w => w.Word)))
                                   .Distinct(new SentenceFragmentEqualityComparer())
                                   .Take(resultsLimit).ToList();
            }

            return(importantWords, exampleFragments);
        }
Esempio n. 7
0
        public void Start()
        {
            // Define commands
            ICommand[] commands = new ICommand[]
            {
                new OpenCommand("open Mozilla", @"C:\Program Files\Mozilla Firefox\firefox.exe"),
                new CloseCommand("close"),

                new KeyboardCommand("pause", System.Windows.Input.Key.Space),
                new KeyboardCommand("play", System.Windows.Input.Key.Space),

                new VlcCommand("skip [-200:200] [second|seconds|minute|minutes|hour|hours]", VlcCommandType.Skip),

                //new CommandLineCommand("shutdown", "shutdown /s /hybrid /f /t 0")
            };

            // Create grammars
            List <Grammar> grammars = commands.Select(x => new Grammar(PhraseParser.Parse(x.Phrase))
            {
                Name = x.Id
            }).ToList();

            // Fast searching for command
            Dictionary <string, ICommand> idToCommand = commands.ToDictionary(x => x.Id);

            using (IRecognizer recognizer = new MicrosoftRecognizer())
                using (ISynthesizer synthesizer = new MicrosoftSynthesizer(recognizer))
                {
                    // Load grammars
                    recognizer.LoadGrammar(grammars);

                    // Add free grammar to prevent false positive - other option is to decrease mic sensitivity
                    recognizer.LoadGrammar(new DictationGrammar()
                    {
                        Name = "___"
                    });

                    // Processing command on recognized
                    recognizer.OnRecognized = (recognizedArgs) =>
                    {
                        Console.WriteLine(recognizedArgs.Text + "\t" + recognizedArgs.Confidence + "\t" + recognizedArgs.Grammar.Name);

                        // Ignore not very accurate commands
                        if (recognizedArgs.Grammar.Name == "___")
                        {
                            return;
                        }

                        new Thread(() =>
                        {
                            idToCommand[recognizedArgs.Grammar.Name].Execute(recognizedArgs.Text);
                        })
                        {
                            IsBackground = true
                        }.Start();
                    };

                    // Start
                    recognizer.Start();

                    // Announce it
                    synthesizer.Speak("Now you can talk");

                    // Never ends
                    Thread.Sleep(int.MaxValue);
                }
        }