コード例 #1
0
            private WordList ToImmutable(bool destructive)
            {
                var affix = Affix ?? new AffixConfig.Builder().MoveToImmutable();

                var nGramRestrictedFlags = Dedup(FlagSet.Create(
                                                     new[]
                {
                    affix.ForbiddenWord,
                    affix.NoSuggest,
                    affix.NoNgramSuggest,
                    affix.OnlyInCompound,
                    SpecialFlags.OnlyUpcaseFlag
                }
                                                     .Where(f => f.HasValue)));

                var result = new WordList(affix)
                {
                    NGramRestrictedFlags = nGramRestrictedFlags,
                };

                if (destructive)
                {
                    result.EntriesByRoot = EntriesByRoot ?? new Dictionary <string, WordEntrySet>();
                    EntriesByRoot        = null;
                }
                else
                {
                    result.EntriesByRoot = EntriesByRoot == null
                        ? new Dictionary <string, WordEntrySet>()
                        : new Dictionary <string, WordEntrySet>(EntriesByRoot);
                }

                var nGramRestrictedEntries = new HashSet <WordEntry>();

                foreach (var rootSet in result.EntriesByRoot)
                {
                    foreach (var entry in rootSet.Value)
                    {
                        if (nGramRestrictedFlags.ContainsAny(entry.Flags))
                        {
                            nGramRestrictedEntries.Add(entry);
                        }
                    }
                }

                result.NGramRestrictedEntries = nGramRestrictedEntries;

                return(result);
            }
コード例 #2
0
 public QueryCheck(string word, WordList wordList)
     : base(word, wordList)
 {
 }
コード例 #3
0
            private WordList ToImmutable(bool destructive)
            {
                var affix = Affix ?? new AffixConfig.Builder().MoveToImmutable();

                var nGramRestrictedFlags = Dedup(FlagSet.Create(
                                                     new[]
                {
                    affix.ForbiddenWord,
                    affix.NoSuggest,
                    affix.NoNgramSuggest,
                    affix.OnlyInCompound,
                    SpecialFlags.OnlyUpcaseFlag
                }
                                                     .Where(f => f.HasValue)));

                var result = new WordList(affix)
                {
                    NGramRestrictedFlags = nGramRestrictedFlags,
                };

                if (EntryDetailsByRoot == null)
                {
                    result.EntriesByRoot = new Dictionary <string, WordEntryDetail[]>();
                }
                else
                {
                    result.EntriesByRoot = new Dictionary <string, WordEntryDetail[]>(EntryDetailsByRoot.Count);
                    foreach (var pair in EntryDetailsByRoot)
                    {
                        result.EntriesByRoot.Add(pair.Key, pair.Value.ToArray());
                    }

                    if (destructive)
                    {
                        EntryDetailsByRoot = null;
                    }
                }

                result.AllReplacements = affix.Replacements;
                if (PhoneticReplacements != null && PhoneticReplacements.Count != 0)
                {
                    // store ph: field of a morphological description in reptable
                    if (result.AllReplacements.IsEmpty)
                    {
                        result.AllReplacements = SingleReplacementSet.Create(PhoneticReplacements);
                    }
                    else
                    {
                        result.AllReplacements = SingleReplacementSet.Create(result.AllReplacements.Concat(PhoneticReplacements));
                    }
                }

                result.NGramRestrictedDetails = new Dictionary <string, WordEntryDetail[]>();

                var details = new List <WordEntryDetail>();

                foreach (var rootSet in result.EntriesByRoot)
                {
                    details.Clear();
                    foreach (var entry in rootSet.Value)
                    {
                        if (nGramRestrictedFlags.ContainsAny(entry.Flags))
                        {
                            details.Add(entry);
                        }
                    }

                    if (details.Count != 0)
                    {
                        result.NGramRestrictedDetails.Add(rootSet.Key, details.ToArray());
                    }
                }

                return(result);
            }
コード例 #4
0
            private WordList ToImmutable(bool destructive)
            {
                var affix = Affix ?? new AffixConfig.Builder().MoveToImmutable();

                var nGramRestrictedFlags = Dedup(FlagSet.Create(
                                                     new[]
                {
                    affix.ForbiddenWord,
                    affix.NoSuggest,
                    affix.NoNgramSuggest,
                    affix.OnlyInCompound,
                    SpecialFlags.OnlyUpcaseFlag
                }
                                                     .Where(f => f.HasValue)));

                var result = new WordList(affix)
                {
                    NGramRestrictedFlags = nGramRestrictedFlags,
                };

                if (EntryDetailsByRoot == null)
                {
                    result.EntriesByRoot = new Dictionary <string, WordEntryDetail[]>(0);
                }
                else
                {
                    result.EntriesByRoot = new Dictionary <string, WordEntryDetail[]>(EntryDetailsByRoot.Count);
                    foreach (var pair in EntryDetailsByRoot)
                    {
                        result.EntriesByRoot.Add(pair.Key, pair.Value.ToArray());
                    }

                    if (destructive)
                    {
                        EntryDetailsByRoot = null;
                    }
                }

                result.NGramRestrictedDetails = new Dictionary <string, WordEntryDetail[]>();

                foreach (var rootSet in result.EntriesByRoot)
                {
                    List <WordEntryDetail> details = null;
                    foreach (var entry in rootSet.Value)
                    {
                        if (nGramRestrictedFlags.ContainsAny(entry.Flags))
                        {
                            if (details == null)
                            {
                                details = new List <WordEntryDetail>();
                            }

                            details.Add(entry);
                        }
                    }

                    if (details != null)
                    {
                        result.NGramRestrictedDetails.Add(rootSet.Key, details.ToArray());
                    }
                }

                return(result);
            }
コード例 #5
0
 public QueryCheck(WordList wordList)
     : base(wordList)
 {
 }
コード例 #6
0
 public NGramAllowedEntries(WordList wordList, Func <string, bool> rootKeyFilter)
 {
     this.wordList      = wordList;
     this.rootKeyFilter = rootKeyFilter;
 }