Ejemplo n.º 1
0
 public IncrementalGAnalyzer FormsToAnlys(List <string> forms, bool setting_isPolymorphicWord)
 {
     if (forms.Count == 0)
     {
         return(fReader.PickBestElement(forms[0]));
     }
     if (setting_isPolymorphicWord)
     {
         IGAnlys_PolymorphicWord poly = new IGAnlys_PolymorphicWord();
         foreach (var form in forms)
         {
             poly.wordAnalyzers.Add(fReader.ForceWordANlys(form, contentMorphemes));
         }
         return(poly);
     }
     if (forms.Count > 1)
     {
         IGAnlys_Candidates candidates = new IGAnlys_Candidates {
         };
         foreach (var form in forms)
         {
             candidates.candidates.Add(fReader.PickBestElement(form));
         }
         return(candidates);
     }
     return(fReader.PickBestElement(forms[0]));
 }
Ejemplo n.º 2
0
        public void AddWordCandidate(string word, IncrementalGAnalyzer condidateAnalyzer, IGAnlys_Candidates candidateHolder)
        {
            wordCandidateInfoDict.TryGetValue(word, out var wordCandInfos);
            if (wordCandInfos == null)
            {
                wordCandInfos = wordCandidateInfoDict[word] = new List <AnalyzerInfo>();
            }
            var info = wordCandInfos.Find((elem) => elem.condidateAnalyzer == condidateAnalyzer);

            if (info == null)
            {
                info = new AnalyzerInfo {
                    condidateAnalyzer = condidateAnalyzer
                };
                wordCandInfos.Add(info);
            }
            info.candidateHolders.Add(candidateHolder);
        }
Ejemplo n.º 3
0
 public void AddCandidate(string name, IGAnlys_Candidates candidate)
 {
     dict[name] = categories[name] = new IGAnlys_Candidates();
 }
Ejemplo n.º 4
0
 public ExampleNLangProcessor(string dictionaryFilePath)
 {
     #region MAnlys
     var mAnlys = new StdMAnalyzer {
     };
     {
         var ignoreReader = new IgnoreBlockReader {
             markers = new List <string> {
                 " ", "\r", "\n", "\t"
             }
         };
         var markerReader = new MarkerBlockReader {
             markers = new List <MarkerAndFormatID> {
                 new MarkerAndFormatID {
                     marker = ".", formatID = 2
                 },
                 new MarkerAndFormatID {
                     marker = ",", formatID = 3
                 },
                 new MarkerAndFormatID {
                     marker = "###", formatID = 4
                 },
                 new MarkerAndFormatID {
                     marker = ":", formatID = 5
                 },
             }
         };
         var quoteBlockMarker = new QuoteBlockReader {
             formatID = 1, leftMarker = "\"", rightMarker = "\""
         };
         mAnlys.blockReaderes.Add(ignoreReader);
         mAnlys.blockReaderes.Add(markerReader);
         mAnlys.blockReaderes.Add(quoteBlockMarker);
         mAnlys.generalReaders.Add(new NumberReader {
         });
         mAnlys.generalReaders.Add(new WordReader {
         });
     }
     #endregion
     #region MAnlys for dictionary creation
     var mAnlysForDict = new StdMAnalyzer {
     };
     {
         var ignoreReader = new IgnoreBlockReader {
             markers = new List <string> {
                 " "
             }
         };
         var markerReader = new MarkerBlockReader {
             markers = new List <MarkerAndFormatID> {
                 new MarkerAndFormatID {
                     marker = "(IGNORE)", formatID = 2
                 },
                 new MarkerAndFormatID {
                     marker = "(UNREADABLE)", formatID = 3
                 }
             }
         };
         var quoteBlockMarker = new QuoteBlockReader {
             formatID = 1, leftMarker = "#", rightMarker = "#"
         };
         mAnlysForDict.blockReaderes.Add(ignoreReader);
         mAnlysForDict.blockReaderes.Add(markerReader);
         mAnlysForDict.blockReaderes.Add(quoteBlockMarker);
         mAnlysForDict.generalReaders.Add(new WordReader {
         });
     }
     #endregion
     #region dictionary creation
     var gDict        = new IncrGAnlysDictionary();
     var formatReader = new FormatReader();
     FormatReader.fReader = new FormToGAnlys {
         analyzer = mAnlysForDict, dict = gDict
     };
     FormatReader.gAnlysDict = gDict;
     FormatReader.metaInfos  = new Dictionary <string, GrammarBlock>();
     FormatReader.metaInfos[StdMetaInfos.sentenceCluster.word] = StdMetaInfos.sentenceCluster;
     FormatReader.metaInfos[StdMetaInfos.nominalBlock.word]    = StdMetaInfos.nominalBlock;
     FormatReader.metaInfos[StdMetaInfos.verbalBlock.word]     = StdMetaInfos.verbalBlock;
     FormatReader.metaInfos[StdMetaInfos.quoteBlock.word]      = StdMetaInfos.quoteBlock;
     FormatReader.metaInfos[StdMetaInfos.sv.word]                 = StdMetaInfos.sv;
     FormatReader.metaInfos[StdMetaInfos.conditionSV.word]        = StdMetaInfos.conditionSV;
     FormatReader.metaInfos[StdMetaInfos.negated.word]            = StdMetaInfos.negated;
     FormatReader.metaInfos[StdMetaInfos.title.word]              = StdMetaInfos.title;
     FormatReader.metaInfos[StdMetaInfos.clusterExtractable.word] = StdMetaInfos.clusterExtractable;
     FormatReader.metaInfos[StdMetaInfos.metaCluster.word]        = StdMetaInfos.metaCluster;
     FormatReader.metaInfos[StdMetaInfos.anonymousCommand.word]   = StdMetaInfos.anonymousCommand;
     FormatReader.metaInfos[StdMetaInfos.modifierCluster.word]    = StdMetaInfos.modifierCluster;
     FormatReader.metaInfos[StdMetaInfos.quoteSV.word]            = StdMetaInfos.quoteSV;
     FormatReader.metaInfos[StdMetaInfos.pronoun.word]            = StdMetaInfos.pronoun;
     FormatReader.metaInfos[StdMetaInfos.plural.word]             = StdMetaInfos.plural;
     FormatReader.metaInfos[StdMetaInfos.unreadable.word]         = StdMetaInfos.unreadable;
     {
         var conjCand = new IGAnlys_Candidates {
         };
         var and      = new IGAnlys_Word {
         };
         and.AddMorphemeText("and");
         var or = new IGAnlys_Word {
         };
         or.AddMorphemeText("or");
         var quote = new IGAnlys_Quote {
             morphemeID = 3
         };
         conjCand.candidates.Add(and);
         conjCand.candidates.Add(or);
         conjCand.candidates.Add(quote);
         var conjGAnlys = new IGAnlys_RepeatableBlock {
             baseAnalyzer = conjCand
         };
         FormatReader.cojunctionIGAnlys = conjGAnlys;
         FormatReader.preparer          = new AnalyzePreparer();
     }
     #endregion
     var dictionaryJsonText = File.ReadAllText(dictionaryFilePath);
     var reader             = new RootReader {
     };
     reader.subReader.Push(new GrammarDictRoot {
         gAnlysDict = gDict
     });
     reader.Read(dictionaryJsonText);
     var rootGAnlys = gDict.dict["RootUnit"];
     nlProcessor = new MGSyntacticProcessor {
         gAnalyzer = new StdGrammarAnalyzer {
             incrGAnalyzer = rootGAnlys, analyzePreparer = FormatReader.preparer
         },
         mAnalyzer = mAnlys
     };
 }