public Morpher(ITraceManager traceManager, Language lang) { _lang = lang; _traceManager = traceManager; _allomorphTries = new Dictionary <Stratum, RootAllomorphTrie>(); var morphemes = new ObservableList <Morpheme>(); foreach (Stratum stratum in _lang.Strata) { var allomorphs = new HashSet <RootAllomorph>(stratum.Entries.SelectMany(entry => entry.Allomorphs)); var trie = new RootAllomorphTrie(ann => ann.Type() == HCFeatureSystem.Segment); foreach (RootAllomorph allomorph in allomorphs) { trie.Add(allomorph); } _allomorphTries[stratum] = trie; morphemes.AddRange(stratum.Entries); morphemes.AddRange(stratum.MorphologicalRules.OfType <AffixProcessRule>()); morphemes.AddRange(stratum.AffixTemplates.SelectMany(t => t.Slots).SelectMany(s => s.Rules).Distinct()); } _analysisRule = lang.CompileAnalysisRule(this); _synthesisRule = lang.CompileSynthesisRule(this); MaxStemCount = 2; LexEntrySelector = entry => true; RuleSelector = rule => true; _morphemes = new ReadOnlyObservableCollection <Morpheme>(morphemes); }
internal IEnumerable <RootAllomorph> SearchRootAllomorphs(Stratum stratum, Shape shape) { RootAllomorphTrie alloSearcher = _allomorphTries[stratum]; return(alloSearcher.Search(shape).Distinct()); }