예제 #1
0
        public override string Execute(IWordDictionary wordDictionary)
        {
            var result = wordDictionary.Delete(Key, Values);

            if (result.Count == 0)
            {
                return($"Word:\"{Key}\" is not exists in dictionary.{Environment.NewLine}");
            }

            var sb = new StringBuilder();

            foreach (var item in result)
            {
                if (item.Value == false)
                {
                    sb.Append($"Word:\"{Key}\" value:\"{item.Key}\" is not exists in dictionary.{Environment.NewLine}");
                }
                else
                {
                    return($"Values of Word \"{Key}\" has been successfully deleted.");
                }
            }

            return(sb.ToString());
        }
예제 #2
0
        public IList <WordResult> Execute(IWordDictionary dictionary)
        {
            var result        = new WordResult("Length");
            var nospaceResult = new WordResult("Length (without word including space)");
            var list          = new List <WordResult>();

            if (_settings.IncludeSpace != "no")
            {
                list.Add(result);
            }

            if (_settings.IncludeSpace != "yes")
            {
                list.Add(nospaceResult);
            }

            foreach (var word in dictionary.Words)
            {
                var lengthStr = word.Length.ToString("0000");

                if (_settings.IncludeSpace != "no")
                {
                    result.CountUp(lengthStr);
                }

                if (_settings.IncludeSpace != "yes" && !word.Any(x => char.IsWhiteSpace(x)))
                {
                    nospaceResult.CountUp(lengthStr);
                }
            }

            return(list);
        }
예제 #3
0
        /// <summary>
        /// Converts HTML content returned by a dictionary to a <see cref="Section"/>.
        /// </summary>
        /// <param name="dictionary">The dictionary. It is neccessary to retrieve CSS files referenced by the HTML content.</param>
        /// <param name="htmlContent">The HTML to convert.</param>
        /// <returns>A <see cref="Section"/> that represents the HTML content.</returns>
        public Section ConvertHtmlContentToSection(IWordDictionary dictionary, string htmlContent)
        {
            Func <string, string, string> cssStyleSheetProvider = (cssFileName, refFileName) =>
            {
                if (dictionary.TryGetValue(cssFileName, out var entry))
                {
                    return(entry.Content);
                }
                else
                {
                    return(null);
                }
            };

            try
            {
                var section = (Section)_converter.Convert(htmlContent, false, cssStyleSheetProvider, null);
                return(section);
            }
            catch (Exception ex)
            {
            }


            return(null);
        }
예제 #4
0
        /// <summary>
        /// Input dictionary and text matching with result writting to Output in accordance with the formatting
        /// </summary>
        public void Check(ITextWriter writer, INeighborsFormater formater, int maxDistance)
        {
            this.writer   = writer;
            this.formater = formater;
            CreateComponent(this.dictionaryBuilder);
            CreateComponent(this.textBuilder);

            IText           text       = (IText)this.textBuilder.GetResult();
            IWordDictionary dictionary = (IWordDictionary)this.dictionaryBuilder.GetResult();

            for (int i = 0; i != text.LinesCount; i++)
            {
                var textLine = text.GetLine(i, out int[] whitespaces);
                for (int j = 0; j != textLine.Length; j++)
                {
                    Word word              = textLine[j];
                    var  neighbors         = dictionary.FindNearestСoincidence(word, maxDistance);
                    var  formatedNeighbors = this.formater.FormatNeighbors(word, neighbors);
                    Word editedWord        = new Word(formatedNeighbors);
                    textLine[j] = editedWord;
                }

                this.writer.WriteLine(textLine, whitespaces);
            }
        }
예제 #5
0
        private IWordDictionary GetDictionary(List <string> words = null)
        {
            IWordDictionary dictionary = words == null
                ? new WordDictionary()
                : new WordDictionary(words);

            return(dictionary);
        }
예제 #6
0
        public WordModulator(IWordDictionaryWithMonitor words)
        {
            if (words == null)
            {
                throw new ArgumentNullException(nameof(words));
            }

            this.words = words;
        }
        public void DeleteMethodTests()
        {
            _dictionary = _kernel.Get <IWordDictionary>();
            _dictionary.Add(Key, new[] { "v1", "v2", "v3" });
            _dictionary.Delete(Key, new[] { "v1" });
            var coll = _dictionary.Get(Key).ToList();

            CollectionAssert.DoesNotContain(coll, "v1");
        }
예제 #8
0
        public override string Execute(IWordDictionary wordDictionary)
        {
            var result = wordDictionary.Add(Key, Values.ToArray());
            var sb     = new StringBuilder();

            sb.Append("(");
            sb.Append(string.Join(",", result));
            sb.Append($"): values of word \"{Key}\" has been successfully added to dictionary.");
            return(sb.ToString());
        }
예제 #9
0
        public void SolveBoard_16_Test()
        {
            Puzzle puzzle = GeneratePuzzle("aynedhecrtcaibkl", 8, 8); // cupboard roof oval

            IWordDictionary dictionary = GetDictionary();
            IBoardCop       boardCop   = new BoardCop.BoardCop();
            IBoardSolver    solver     = new BoardSolver.BoardSolver(boardCop, dictionary);
            PuzzleSolution  solutions  = solver.SolvePuzzle(puzzle);

            Assert.IsNotNull(solutions);
        }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientObject"/> class.
 /// </summary>
 /// <param name="tcpTcpClient">
 /// The tcp tcp client.
 /// </param>
 /// <param name="wordDictionary">
 /// The word dictionary.
 /// </param>
 /// <param name="commandBuilder">
 /// The command builder.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public ClientObject(
     TcpClient tcpTcpClient,
     IWordDictionary wordDictionary,
     ICommandBuilder commandBuilder,
     ILogger logger)
 {
     _tcpClient      = tcpTcpClient;
     _wordDictionary = wordDictionary;
     _commandBuilder = commandBuilder;
     _logger         = logger;
 }
예제 #11
0
        public void SolveBoard_9_Test()
        {
            Puzzle puzzle = GeneratePuzzle("flfooirde", 4, 5); // roof field

            IWordDictionary dictionary = GetDictionary();
            IBoardCop       boardCop   = new BoardCop.BoardCop();
            IBoardSolver    solver     = new BoardSolver.BoardSolver(boardCop, dictionary);

            PuzzleSolution solutions = solver.SolvePuzzle(puzzle);

            Assert.IsNotNull(solutions);
        }
예제 #12
0
        public void SolveBoard_9_Test_WrongFirstChoice()
        {
            Puzzle puzzle = GeneratePuzzle("efdidlrie", 4, 5); // ride field

            IWordDictionary dictionary = GetDictionary();
            IBoardCop       boardCop   = new BoardCop.BoardCop();
            IBoardSolver    solver     = new BoardSolver.BoardSolver(boardCop, dictionary);

            PuzzleSolution solutions = solver.SolvePuzzle(puzzle);

            Assert.IsNotNull(solutions);
        }
예제 #13
0
        public void SolveBoard_4_Test()
        {
            Puzzle puzzle = GeneratePuzzle("cart", 4);

            IWordDictionary dictionary = GetDictionary();
            IBoardCop       boardCop   = new BoardCop.BoardCop();
            IBoardSolver    solver     = new BoardSolver.BoardSolver(boardCop, dictionary);

            PuzzleSolution ps = solver.SolvePuzzle(puzzle);

            Assert.IsNotNull(ps);
        }
예제 #14
0
        public void GetMethodTests()
        {
            _dictionary = _kernel.Get <IWordDictionary>();

            _dictionary.Add(Key, new[] { "v1", "v2", "v3" });
            var set        = _dictionary.Get(Key);
            var collection = set.ToList();

            CollectionAssert.Contains(collection, "v1");
            CollectionAssert.Contains(collection, "v2");
            CollectionAssert.Contains(collection, "v3");
            CollectionAssert.DoesNotContain(collection, "v4");
        }
예제 #15
0
        public IList <WordResult> Execute(IWordDictionary dictionary)
        {
            var result        = new WordResult("Using Character");
            var nospaceResult = new WordResult("Using Character (without word including space)");
            var list          = new List <WordResult>();

            if (_settings.IncludeSpace != "no")
            {
                list.Add(result);
            }

            if (_settings.IncludeSpace != "yes")
            {
                list.Add(nospaceResult);
            }

            foreach (var word in dictionary.Words)
            {
                var pairs = word.Aggregate(new Dictionary <char, int>(), (acc, x) =>
                {
                    if (acc.ContainsKey(x))
                    {
                        acc[x]++;
                    }
                    else
                    {
                        acc[x] = 1;
                    }
                    return(acc);
                });

                var nospace = !word.Any(x => char.IsWhiteSpace(x));
                foreach (var pair in pairs)
                {
                    var key = pair.Key.ToString();
                    if (_settings.IncludeSpace != "no")
                    {
                        result.AddCount(key, pair.Value);
                    }

                    if (_settings.IncludeSpace != "yes" && nospace)
                    {
                        nospaceResult.AddCount(key, pair.Value);
                    }
                }
            }

            return(list);
        }
예제 #16
0
        public override string Execute(IWordDictionary wordDictionary)
        {
            var result = wordDictionary.Get(Key);

            if (result.Length > 0)
            {
                var sb = new StringBuilder();
                sb.Append(string.Join(Environment.NewLine, result));
                return(sb.ToString());
            }
            else
            {
                return($"a word \"{Key}\" is missing in dictionary");
            }
        }
예제 #17
0
        public WordDictionaryWithMonitor(IWordDictionary core, IMonitorFactory monitorFactory)
        {
            if (core == null)
            {
                throw new ArgumentNullException(nameof(core));
            }
            if (monitorFactory == null)
            {
                throw new ArgumentNullException(nameof(monitorFactory));
            }

            this.core = core;

            this.wordTestCount = monitorFactory.OpenPerformanceCounter("Word Hit Ratio - Base");
            this.wordHitCount  = monitorFactory.OpenPerformanceCounter("Word Hit Ratio");
        }
예제 #18
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("WordStats (options) file");
            }
            else if (args.Any(x => x == "--help" || x == "-h"))
            {
                Console.WriteLine("WordStats");
                Console.WriteLine("  WordStats (options) file");
                Console.WriteLine();
                Console.WriteLine("  options:");
                Console.WriteLine("    --help, --h: this message");
                Console.WriteLine("    @(fileName): setting file name");
            }
            else
            {
                string?filePath        = null;
                string?settingFilePath = null;

                foreach (var item in args)
                {
                    if (item.StartsWith("@"))
                    {
                        settingFilePath = item.Substring(1);
                    }
                    else
                    {
                        filePath = item;
                    }
                }

                if (string.IsNullOrWhiteSpace(filePath))
                {
                    throw new ArgumentException($"invalid dictionary name: {filePath}");
                }

                WordStatsSettings settings   = GetSettings(settingFilePath);
                IWordDictionary   dictionary = GetDictionary(settings.Dictionary);
                dictionary.ReadFile(filePath);

                IList <IWordCategorizer> categorizers = GetCategorizers(settings.Categorizers);
                IWordStatistics          statistics   = GetStatistics(settings.Statistics, settings.Order);
                statistics.Dictionary = dictionary;
                statistics.Execute(categorizers);
            }
        }
        public static DictionaryLetter InitializeDictionaryLetter(char letter, IWordDictionary wordDictionary)
        {
            int           beginWith, endWith, avgCount;
            List <string> words, wordsBeginWith;

            try
            {
                words          = wordDictionary.GetDictionaryWordsStartingWith(letter);
                beginWith      = words.Count;
                wordsBeginWith = words;
            }
            catch (WordStartingNotFoundException)
            {
                words = wordDictionary.GetDictionaryWords();
                words = words.FindAll(s => s[0] == letter);
                wordDictionary.SaveWordsForLetterStarting(letter, words);

                beginWith      = words.Count;
                wordsBeginWith = words;
            }

            try
            {
                words   = wordDictionary.GetDictionaryWordsEndingWith(letter);
                endWith = words.Count;
            }
            catch (WordEndingNotFoundException)
            {
                words = wordDictionary.GetDictionaryWords();
                words = words.FindAll(s => s.Last() == letter);
                wordDictionary.SaveWordsForLettersEnding(letter, words);

                endWith = words.Count;
            }

            if (wordsBeginWith.Count > 0)
            {
                // Get the average character length of all the words that start with `letter`.
                avgCount = wordsBeginWith.Aggregate(0, (acc, val) => acc + val.Length, avg => avg / wordsBeginWith.Count);
            }
            else
            {
                avgCount = 0;
            }

            return(new DictionaryLetter(letter, beginWith, endWith, avgCount, wordsBeginWith));
        }
예제 #20
0
        private ParseResult ParseNameByAll(Token token, IWordDictionary collection)
        {
            string      varName = token.GetText();
            ParseResult result  = null;
            WordInfo    word    = collection.SearchWord(varName);

            if (word != null)
            {
                var zType = word.WDataList[0].Data as ZType;
                result = new ParseResult()
                {
                    VarName = varName, ZType = zType
                };
                return(result);
            }
            return(null);
        }
예제 #21
0
        public void AddMethodTests()
        {
            _dictionary = _kernel.Get <IWordDictionary>();

            _dictionary.Add(Key, new[] { "v1" });
            CollectionAssert.Contains(_dictionary.Get(Key).ToList(), "v1");

            _dictionary.Add(Key, new[] { "v2" });
            CollectionAssert.Contains(_dictionary.Get(Key).ToList(), "v2");

            _dictionary.Add(Key, new[] { "v2" });
            Assert.AreEqual(_dictionary.Get(Key).ToList().Count, 2);

            CollectionAssert.DoesNotContain(_dictionary.Get(Key).ToList(), "v3");

            _dictionary.Add(Key, new[] { string.Empty });
            Assert.AreEqual(3, _dictionary.Get(Key).ToList().Count);
        }
        public IList <WordResult> Execute(IWordDictionary dictionary)
        {
            var length = 2;

            if (!(_settings.Length is null) && _settings.Length >= 2)
            {
                length = _settings.Length.Value;
            }

            var result        = new WordResult("Concat Character");
            var nospaceResult = new WordResult("Concat Character (without word including space)");
            var list          = new List <WordResult>();

            if (_settings.IncludeSpace != "no")
            {
                list.Add(result);
            }

            if (_settings.IncludeSpace != "yes")
            {
                list.Add(nospaceResult);
            }

            foreach (var word in dictionary.Words)
            {
                var nospace = !word.Any(x => char.IsWhiteSpace(x));

                for (int i = 0; i < (word.Length - length); i++)
                {
                    var substr = word.Substring(i, length);
                    if (_settings.IncludeSpace != "no")
                    {
                        result.CountUp(substr);
                    }

                    if (_settings.IncludeSpace != "yes" && nospace)
                    {
                        nospaceResult.CountUp(substr);
                    }
                }
            }

            return(list);
        }
예제 #23
0
        private ParseResult ParseNameBySegmenter(Token token, IWordDictionary collection)
        {
            //WordCollection nameManager = this.procContext.ClassContext.FileContext.GetNameDimWordManger();
            WordSegmenter segmenter = new WordSegmenter(collection);

            Token[] newTokens = segmenter.Split(token);
            if (newTokens.Length == 2)
            {
                string argTypeName = newTokens[0].GetText();
                var    ArgType     = ZTypeManager.GetByMarkName(argTypeName)[0] as ZType;
                var    result      = new ParseResult()
                {
                    TypeName = argTypeName, ZType = ArgType, VarName = newTokens[1].GetText()
                };
                return(result);
            }
            else
            {
                return(null);
            }
        }
예제 #24
0
        /// <summary>
        /// Loads a Slob dictionary.
        /// </summary>
        /// <param name="fileName">Name of the dictionary file. The dictionary must be in SLOB format.</param>
        /// <param name="collectKeys">If set to <c>true</c>, the keys of all dictionaries will be collected. When loading multiple dictionaries subsequently, you should set this parameter to true only for the last dictionary loaded.</param>
        public void LoadDictionary(string fileName, bool collectKeys = true)
        {
            var extension = System.IO.Path.GetExtension(fileName).ToLowerInvariant();

            IWordDictionary dictionary = null;

            switch (extension)
            {
            case ".ifo":
            {
                var starDict = new StarDict.StarDictionaryInMemory();
                starDict.Open(fileName);
                dictionary = starDict;
            }
            break;

            case ".slob":
            {
                var slobReader = new SlobReaderWriter(fileName);
                dictionary          = slobReader.Read();
                dictionary.FileName = fileName;
            }
            break;
            }


            if (null != dictionary)
            {
                _dictionaries.Add(dictionary);

                if (collectKeys)
                {
                    CollectAndSortKeys();
                }
            }
        }
예제 #25
0
파일: BoardSolver.cs 프로젝트: mekmak/MWBS
 public BoardSolver(IBoardCop boardCop, IWordDictionary wordDictionary)
 {
     _boardCop       = boardCop;
     _wordDictionary = wordDictionary;
 }
예제 #26
0
        /// <summary>
        /// Tries to find the key <paramref name="searchText"/> in the dictionary.
        /// </summary>
        /// <param name="searchText">The text to search. If this original text was not found, on return, the parameter contains the key for which the content is returned.</param>
        /// <param name="dictionary">The dictionary.</param>
        /// <returns>A tuple consisting of the content, the content identifer, and a boolean. The boolean is true if the original search text was found in the dictionary.
        /// If the original search text was not found, the boolean is false, and <paramref name="searchText"/>contains the search text that was found.</returns>
        private (string Content, string ContentId, bool foundOriginal) GetResult(ref string searchText, IWordDictionary dictionary)
        {
            var searchKey = _compareInfo.GetSortKey(searchText);
            var index     = Array.BinarySearch(_sortKeys, searchKey, new UnicodeStringSorter());


            (string Content, string ContentId)result = (null, null);
            bool found = false;

            if (index >= 0)
            {
                result = dictionary[searchText];
                found  = true;
            }
            else
            {
                index = ~index;

                if (index < _keys.Length)
                {
                    searchText = _keys[index];
                    result     = dictionary[searchText];
                }
            }

            return(result.Content, result.ContentId, found);
        }
예제 #27
0
 /// <summary>
 /// The execute this command.
 /// Idle by default.
 /// </summary>
 /// <param name="wordDictionary">
 /// The word dictionary.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public virtual string Execute(IWordDictionary wordDictionary)
 {
     return(string.Empty);
 }
예제 #28
0
 public WordSegmenter(IWordDictionary tree)
 {
     Tree = tree;
 }
예제 #29
0
 public WordPartsFilter(IWordDictionary dictionary)
 {
     boringWords = new HashSet <string>(FilteredSpeechParts.SelectMany(dictionary.GetWords));
 }
예제 #30
0
 public MyDictionary(IDataPrepare dataPrepare, IWordDictionary wordDictionary)
 {
     _dataPrepare    = dataPrepare;
     _wordDictionary = wordDictionary;
 }