Ejemplo n.º 1
0
        private bool IsImportantMessageProc(string message)
        {
            var importantWordsConfig = ConfigurationManager.AppSettings["Important_Words"];

            if (string.IsNullOrEmpty(importantWordsConfig))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(message))
            {
                return(false);
            }

            var importantWords = new HashSet <string>(importantWordsConfig.ToLower().Split('|').Distinct());
            var words          = new WordParser().Parse(message)
                                 .Where(x => !string.IsNullOrEmpty(x))
                                 .Select(x => x.ToLower())
                                 .Distinct()
                                 .ToList();

            if (words.Any(x => importantWords.Contains(x)))
            {
                return(true);
            }
            return(false);
        }
        public override void Initialize(AnalysisContext context)
        {
            context.EnableConcurrentExecution();
            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);

            context.RegisterSymbolAction(context =>
            {
                var eventName = context.Symbol.Name;

                if (!eventName.StartsWith(BeforeKeyword, StringComparison.Ordinal) &&
                    !eventName.StartsWith(AfterKeyword, StringComparison.Ordinal))
                {
                    return;
                }

                var wordParse = new WordParser(eventName, WordParserOptions.SplitCompoundWords);

                if (wordParse.NextWord() is string firstWord &&
                    s_invalidPrefixes.Contains(firstWord) &&
                    wordParse.NextWord() is string) // Do not report if this is the only word
                {
                    context.ReportDiagnostic(context.Symbol.CreateDiagnostic(Rule));
                }
            }, SymbolKind.Event);
        }
Ejemplo n.º 3
0
        public override ProblemCollection Check(Resource resource)
        {
            using (MemoryStream mstream = new MemoryStream(resource.Data, false))
            {
                using (ResourceReader reader = new ResourceReader(mstream))
                {
                    foreach (DictionaryEntry entry in reader)
                    {
                        string s = entry.Value as string;
                        if (s != null)
                        {
                            foreach (String word in WordParser.Parse(s, WordParserOptions.None))
                            {
                                if (NamingService.DefaultNamingService.CheckSpelling(word) !=
                                    WordSpelling.SpelledCorrectly)
                                {
                                    this.Problems.Add(new Problem(this.GetResolution(word), word));
                                }
                            }
                        }
                    }
                }
            }

            return(this.Problems);
        }
Ejemplo n.º 4
0
    public void AddWord()
    {
        Word word = new Word(WordParser.GetRandomWord(), spawner.SpawnWord());

        words.Add(word);
        Debug.Log("Random word was spawned succesfully : " + word.text);
    }
Ejemplo n.º 5
0
        private static void Main(string[] args)
        {
            var filePath = args.Length > 0 ? args[0] : DefaultPath;

            try
            {
                var parser = new WordParser();
                parser.Parse(filePath);

                Console.WriteLine("Total words: {0}. Different words: {1}", parser.Result.TotalWordsCount, parser.Result.DifferentWordsCount);
                Console.WriteLine("Least used word: '{0}'. Usages count: {1}", parser.Result.LeastUsedWord.Word, parser.Result.LeastUsedWord.UsagesCount);
                Console.WriteLine("Most used word: '{0}'. Usages count: {1}", parser.Result.MostUsedWord.Word, parser.Result.MostUsedWord.UsagesCount);

                SaveResultToFile(ResultPath, parser.Result);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("File '{0}' could not be found. Please specify path to existing file or use 'Content\\input.txt' file", ex.FileName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method returns the Extensions
        /// </summary>
        public static List <string> GetExtensions(string text)
        {
            // initial value
            List <string> extensions = new List <string>();

            // If the text string exists
            if (TextHelper.Exists(text))
            {
                // only use commas or semicolons
                char[] delimiterChars = { ',', ';' };

                // Parse the words
                List <Word> words = WordParser.GetWords(text, delimiterChars);

                // if there are one or more words
                if (ListHelper.HasOneOrMoreItems(words))
                {
                    // Iterate the collection of Word objects
                    foreach (Word word in words)
                    {
                        // Add this extension
                        extensions.Add(word.Text);
                    }
                }
            }

            // return value
            return(extensions);
        }
Ejemplo n.º 7
0
        public override void Initialize(AnalysisContext analysisContext)
        {
            analysisContext.EnableConcurrentExecution();
            analysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);

            analysisContext.RegisterSymbolAction(context =>
            {
                var field = (IFieldSymbol)context.Symbol;

                if (field.ContainingType == null ||
                    field.ContainingType.TypeKind != TypeKind.Enum ||
                    !WordParser.ContainsWord(field.Name, WordParserOptions.SplitCompoundWords, reservedWords))
                {
                    return;
                }

                // FxCop compat: only analyze externally visible symbols by default.
                if (!field.MatchesConfiguredVisibility(context.Options, Rule, context.CancellationToken))
                {
                    return;
                }

                context.ReportDiagnostic(field.CreateDiagnostic(Rule, field.ContainingType.Name, field.Name));
            }, SymbolKind.Field);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns True if the text has incorrect spelling.
        /// </summary>
        /// <param name="element">
        /// The element containing the text we're checking.
        /// </param>
        /// <param name="text">
        /// The text to check.
        /// </param>
        /// <param name="spellingError">
        /// Returns a comma separated list of words encountered as spelling errors.
        /// </param>
        /// <returns>
        /// True if the text contains an incorrect spelling.
        /// </returns>
        private static bool TextContainsIncorectSpelling(CsElement element, string text, out string spellingError)
        {
            NamingService namingService = NamingService.GetNamingService(element.Document.SourceCode.Project.Culture);

            spellingError = string.Empty;

            if (namingService.SupportsSpelling)
            {
                WordParser parser = new WordParser(text, WordParserOptions.SplitCompoundWords);
                if (parser.PeekWord() != null)
                {
                    ICollection <string> recognizedWords = element.Document.SourceCode.Project.RecognizedWords;

                    string word = parser.NextWord();
                    do
                    {
                        // Ignore words starting and ending with '$'.
                        // Ignore if in our recognized words list or correct spelling
                        if ((word.StartsWith("$") && word.EndsWith("$")) || (recognizedWords.Contains(word) || IsSpelledCorrectly(namingService, word)))
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(spellingError))
                        {
                            spellingError += ", ";
                        }

                        spellingError += word;
                    }while ((word = parser.NextWord()) != null);
                }
            }

            return(!string.IsNullOrEmpty(spellingError));
        }
Ejemplo n.º 9
0
        public void TestUnderscoreCase1()
        {
            var result = WordParser.BreakWords("FIX_1");

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("FIX", result [0]);
            Assert.AreEqual("1", result [1]);
        }
Ejemplo n.º 10
0
        public void ParseAsyncは単語後のスペースを読み飛ばします()
        {
            var cursol = new Cursol("public ");
            var tested = new WordParser("public");

            var result = tested.Parse(cursol);

            result.cursol.Index.Is(7);
        }
Ejemplo n.º 11
0
        public void PopQuoteWord()
        {
            var words = new WordParser("one \"two bits\" three");

            Assert.Equal("one", words.Pop());
            Assert.Equal("two bits", words.Pop());
            Assert.Equal("three", words.Pop());
            Assert.Null(words.Pop());
        }
Ejemplo n.º 12
0
        public void ParseAsyncは指定していない単語を読み込みに失敗します()
        {
            var cursol = new Cursol("publi");
            var tested = new WordParser("public");

            var result = tested.Parse(cursol);

            result.isSuccess.IsFalse();
        }
Ejemplo n.º 13
0
        public void ParseAsyncは読み込みに成功した場合に単語の長さだけ進んだカーソルを返します()
        {
            var cursol = new Cursol("void");
            var tested = new WordParser("void");

            var result = tested.Parse(cursol);

            result.cursol.Index.Is(4);
        }
Ejemplo n.º 14
0
        public void ParseAsyncは指定した単語を読み込みます()
        {
            var cursol = new Cursol("public");
            var tested = new WordParser("public");

            var result = tested.Parse(cursol);

            result.parsed.Is("public");
        }
Ejemplo n.º 15
0
        public void ParseAsyncは読み込みに失敗した場合には進んでいないカーソルを返します()
        {
            var cursol = new Cursol("publi");
            var tested = new WordParser("public");

            var result = tested.Parse(cursol);

            result.cursol.Index.Is(0);
        }
Ejemplo n.º 16
0
        public void ParseAsyncは指定した単語を読み込みに成功します()
        {
            var cursol = new Cursol("public");
            var tested = new WordParser("public");

            var result = tested.Parse(cursol);

            result.isSuccess.IsTrue();
        }
Ejemplo n.º 17
0
        public void Pop()
        {
            var words = new WordParser("one two three");

            Assert.Equal("one", words.Pop());
            Assert.Equal("two", words.Pop());
            Assert.Equal("three", words.Pop());
            Assert.Null(words.Pop());
        }
Ejemplo n.º 18
0
        public void StartProcessTestMethod()
        {
            string testSentence  = "Where are you, going today?";
            string finalSentence = string.Empty;

            finalSentence = WordParser.start_Processing(testSentence);

            // Assert.AreSame("xyz", finalSentence);
            Assert.AreEqual("W3e a1e y1u, g3g t3y?", finalSentence);
        }
Ejemplo n.º 19
0
        [InlineData("gubernātōrem", "short:2 long:3 long:2 long:2 long:3")]  // gu.ˌber.naː.ˈtoː.rem
        public void GetSyllableTheory(string latin, string syllable)
        {
            var parser = new WordParser();
            var word   = parser.Parse(latin);

            new SyllableAnalyzer().Analyze(word);
            new AccentAnalyzer().Analyze(word);

            WordAssert.Field(word, "syllable", syllable);
        }
Ejemplo n.º 20
0
        public void TestUnderscore()
        {
            var result = WordParser.BreakWords("some_Very_long_NAME");

            Assert.AreEqual(4, result.Count);
            Assert.AreEqual("some", result [0]);
            Assert.AreEqual("Very", result [1]);
            Assert.AreEqual("long", result [2]);
            Assert.AreEqual("NAME", result [3]);
        }
Ejemplo n.º 21
0
        public void TestCamelCaseWords()
        {
            var result = WordParser.BreakWords("someVeryLongName");

            Assert.AreEqual(4, result.Count);
            Assert.AreEqual("some", result [0]);
            Assert.AreEqual("Very", result [1]);
            Assert.AreEqual("Long", result [2]);
            Assert.AreEqual("Name", result [3]);
        }
Ejemplo n.º 22
0
        [InlineData("gubernātōrem", "initial:2 tonic:3 pre-tonic:2 tonic:2 final:3")]   // gu.ˌber.naː.ˈtoː.rem
        public void GetAccentTheory(string latin, string accent)
        {
            var parser = new WordParser();
            var word   = parser.Parse(latin);

            new SyllableAnalyzer().Analyze(word);
            new AccentAnalyzer().Analyze(word);

            WordAssert.Field(word, "accent", accent);
        }
Ejemplo n.º 23
0
        public void TestUpperCaseSubWord()
        {
            var result = WordParser.BreakWords("someVeryLongXMLName");

            Assert.AreEqual(5, result.Count);
            Assert.AreEqual("some", result [0]);
            Assert.AreEqual("Very", result [1]);
            Assert.AreEqual("Long", result [2]);
            Assert.AreEqual("XML", result [3]);
            Assert.AreEqual("Name", result [4]);
        }
Ejemplo n.º 24
0
        private void WordEvaluator(string _inputexpr, string _inputresult)
        {
            var        tokens = Helper_ConvertStringToList(_inputexpr);
            int        _index = 0;
            WordParser p      = new WordParser(tokens, ref _index);

            var _actual   = p.word.expression;
            var _expected = _inputresult;

            Assert.AreEqual(_expected, _actual);
        }
Ejemplo n.º 25
0
        public void AnalyzeTheory(string graphical, string phonemic, string graphemic)
        {
            var analyzer = new WordParser();

            var latinWord = analyzer.Parse(graphical);

            var phonemes  = ParsePhonemic(phonemic);
            var graphemes = Core.Alignment.ParseIntervals(graphemic);

            Assert.Equal(phonemes, latinWord.Phonemes);
            Assert.Equal(graphemes, latinWord.GraphicalForms[0].Intervals);
        }
Ejemplo n.º 26
0
        private static ValueValidator?GetValueValidator(string name)
        {
            foreach (var valueValidator in s_tokensToValueValidator)
            {
                if (WordParser.ContainsWord(name, WordParserOptions.SplitCompoundWords, valueValidator.AcceptedTokens))
                {
                    return(valueValidator);
                }
            }

            return(null);
        }
Ejemplo n.º 27
0
    protected virtual void GenerateNewWord(Worker w)
    {
        List <char> bannedCharacters = new List <char>();

        for (int i = 0; i < workers.Count; i++)
        {
            if (!workers[i].Fired && !string.IsNullOrEmpty(workers[i].CurrentWord))
            {
                bannedCharacters.Add(workers[i].CurrentWord[0]);
            }
        }
        w.SetWord(WordParser.GetRandomWord(DifficultyManager.GetWordLength(), bannedCharacters.ToArray()));
    }
        private static bool HasCorrectPrefix(ISymbol symbol, char prefix)
        {
            WordParser parser = new WordParser(symbol.Name, WordParserOptions.SplitCompoundWords, prefix);

            string firstWord = parser.NextWord();

            if (firstWord == null || firstWord.Length > 1)
            {
                return(false);
            }

            return(firstWord[0] == prefix);
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Devis Machine Console");
            Console.WriteLine("=====================");

            Console.WriteLine("Caching...");
            Thread thread = new Thread(PreCacheParser <MockScope> .PreCache);

            thread.Priority = ThreadPriority.AboveNormal;
            thread.Start();

            Console.WriteLine("Scope creation...");
            MockScope scope = new MockScope {
                Id = 1, Text = "Hello World", FileName = "WordParser"
            };

            for (int i = 0; i < 10; i++)
            {
                scope.List.Add(new ABC {
                    Label = "Label" + i.ToString(), A = "A" + i.ToString(), B = "B" + i.ToString(), C = "C" + i.ToString()
                });
            }

            while (true)
            {
                WordParser <MockScope> parser = new WordParser <MockScope>(scope);
                Console.WriteLine("Parsing...");
                parser.Parse();
                int nbCache = 0;
                if (Expression <MockScope> .Cache != null)
                {
                    nbCache = Expression <MockScope> .Cache.Count;
                }
                Console.WriteLine("Mapping " + parser.Expressions.Count + " expression(s) with " + nbCache + " item(s) in cache");
                parser.Map();
                Console.WriteLine("Saving...");
                parser.Save();
                string fileName = Directory.GetCurrentDirectory() + "\\" + parser.TempFile;
                Console.WriteLine("Opening " + fileName);
                Process process = new Process();
                process.StartInfo.FileName = fileName;
                process.Start();
                if (parser.NbError > 0)
                {
                    Console.WriteLine(parser.NbError + " ERROR(S)");
                }
                Console.WriteLine("Press any key...");
                Console.ReadKey();
                Console.WriteLine();
            }
        }
Ejemplo n.º 30
0
        public void AddItems(int size)
        {
            NLBHT  table        = new NLBHT(new MultFunc((Math.Sqrt(5) - 1) / 2));
            string fileLocation = "../../../wikiwords.txt";
            var    tuples       = WordParser.ParseFromFile(fileLocation, numLines: size);

            foreach (var tuple in tuples)
            {
                table.Put(tuple.Item1, tuple.Item2);
            }
            // Assert.AreEqual(table.Count, 100);
            Console.WriteLine(table.TabSize);
            Console.WriteLine("Table load factor = {0}", table.LoadFactor);
        }
Ejemplo n.º 31
0
        public static bool SymbolNameContainsUriWords(this ISymbol symbol, CancellationToken cancellationToken)
        {
            if (symbol.Name == null || !symbol.SymbolNameContainsUriWordSubstring(cancellationToken))
            {
                // quick check failed
                return false;
            }

            string word;
            var parser = new WordParser(symbol.Name, WordParserOptions.SplitCompoundWords);
            while ((word = parser.NextWord()) != null)
            {
                if (s_uriWords.Contains(word))
                {
                    return true;
                }
            }

            return false;
        }