void IncrGAnalysisListener.OnMatch(GAnlysInput _nextInput, AfterMatchListener _listener, AlternativeIncrGAnalyzer _alternative) { didMatch = true; nextInput = _nextInput; listener = _listener; alternative = _alternative; }
void IncrGAnalysisListener.OnMatch(GAnlysInput nextInput, AfterMatchListener afterListener, AlternativeIncrGAnalyzer alternative) { List <IndexedAfterMatchListener> updatedMatches = new List <IndexedAfterMatchListener>(previoudMatches); updatedMatches.Add(new IndexedAfterMatchListener(nextIndex - 1, afterListener)); if (nextIndex < analyzers.Count) { var recordingListener = new RecordingIncrGAnalysListener { baseListener = new ChainListenerOld { analyzers = analyzers, nextIndex = nextIndex + 1, rootListener = rootListener, previoudMatches = updatedMatches, afterListenerFactory = afterListenerFactory } }; analyzers[nextIndex].Analyze(nextInput, recordingListener); if (!recordingListener.didMatch && alternative != null) { updatedMatches.RemoveAt(updatedMatches.Count - 1); AlternativeIncrGAnalyzer currentAlternative = alternative; var altListener = new ChainListenerOld { analyzers = analyzers, nextIndex = nextIndex, rootListener = rootListener, previoudMatches = updatedMatches, afterListenerFactory = afterListenerFactory }; alternative.AnalyzeAgain(altListener); } } else { //rootListener.OnMatch(nextInput, new ClusterAfterListener { afterListeners = updatedMatches }); rootListener.OnMatch(nextInput, afterListenerFactory(updatedMatches), alternative); } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { if (IsMatching(input)) { listener.OnMatch(input.GetAdvanced(words.Count), this); } }
void IncrGAnalysisListener.OnMatch(GAnlysInput nextInput, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative) { didHit = true; if (alternative != null) { clientListner.OnMatch(nextInput, listener, new UnitAltAnlys { parent = parent, nextIndex = nextAnalyzerIndex, subAltAnalyzer = alternative, originalInput = originalInput } ); } else { if (nextAnalyzerIndex < parent.candidates.Count) { clientListner.OnMatch(nextInput, listener, new UnitAltAnlys { parent = parent, nextIndex = nextAnalyzerIndex, originalInput = originalInput }); } else { clientListner.OnMatch(nextInput, listener); } } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { int offset = 0; var afterLis = new PrvtALis { }; foreach (var morpheme in input.followings) { EasyIncrGAnalysListener easyLis = new EasyIncrGAnalysListener(); var nextInput = input.GetAdvanced(offset); lasyAnlys.Analyze(nextInput, easyLis); if (easyLis.didMatch) { listener.OnMatch(nextInput, afterLis); return; } else { afterLis.gBlocks.Add(new StdMutableGUnit { word = morpheme.word }); } offset++; } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { anaylzers[0].Analyze(input, new ChainListener { index = 0, results = new List <IndexAndResult>(), analyzers = anaylzers, finalListener = listener, afterListenerFactory = CreateAfterListener } ); }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { var recLis = new RecordingIncrGAnalysListener { baseListener = listener }; baseAnalyzer.Analyze(input, recLis); if (!recLis.didMatch) { listener.OnMatch(input, StbAfterLis.instance); } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { foreach (var sourceFUnit in input.followings) { if (sourceFUnit.id == morphemeID) { listener.OnMatch(input.GetAdvanced(1), new QuoteAfterMatchListener { unit = sourceFUnit }); } break; } }
void IncrGAnalysisListener.OnMatch(GAnlysInput _nextInput, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative) { if (alternative != null) { baseListener.OnMatch(_nextInput, parent.ChangeAfterListener(listener), new ResultAltIncrGAnalyzer { baseAltAnalyzer = alternative, parent = parent }); } else { baseListener.OnMatch(_nextInput, parent.ChangeAfterListener(listener)); } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { var easyLis = new EasyIncrGAnalysListener(); baseAnalyzer.Analyze(input, easyLis); if (easyLis.didMatch) { var alt = new PrvtAltIGAnlys { parent = this, previousResult = new List <EasyIncrGAnalysListener> { easyLis } }; listener.OnMatch(easyLis.nextInput, easyLis.listener, alt); } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { if (candidates.Count == 0) { return; } var innerListener = new SubListener { clientListner = listener, parent = this, nextAnalyzerIndex = 1, originalInput = input }; while (!innerListener.didHit && innerListener.nextAnalyzerIndex - 1 < candidates.Count) { candidates[innerListener.nextAnalyzerIndex - 1].Analyze(input, innerListener); innerListener.nextAnalyzerIndex++; } }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { var easyLis = new EasyIncrGAnalysListener(); baseAnalyzer.Analyze(input, easyLis); if (easyLis.didMatch) { var alt = new PrvtAltIGAnlys { input = input, parent = this, previousAlt = easyLis.alternative, analyzers = new List <IncrementalGAnalyzer> { baseAnalyzer } }; listener.OnMatch(easyLis.nextInput, easyLis.listener, alt); } }
void IncrGAnalysisListener.OnMatch(GAnlysInput nextInput, AfterMatchListener afterListener, AlternativeIncrGAnalyzer alternative) { results.Add(new IndexAndResult { index = index, result = new EasyIncrGAnalysListener { alternative = alternative, didMatch = true, listener = afterListener, nextInput = nextInput } }); //last analyzer if (index == analyzers.Count - 1) { didFinalMatch = true; finalListener.OnMatch(nextInput, afterListenerFactory(new List <IndexAndResult>(results)), new PrvtAltAnlys { results = new List <IndexAndResult>(results), afterListenerFactory = afterListenerFactory, analyzers = analyzers }); } //go to next analyzer else { var nextLis = new ChainListener { afterListenerFactory = afterListenerFactory, analyzers = analyzers, finalListener = finalListener, index = index + 1, results = results }; analyzers[index + 1].Analyze(nextInput, nextLis); didFinalMatch = nextLis.didFinalMatch; if (!nextLis.didFinalMatch) { bool hasAlternative = false; foreach (var result in results) { if (result.result.alternative != null) { hasAlternative = true; break; } } if (hasAlternative) { AlternativeIncrGAnalyzer alt = new PrvtAltAnlys { afterListenerFactory = afterListenerFactory, analyzers = analyzers, results = new List <IndexAndResult>(results) }; alt.AnalyzeAgain(finalListener); } } } }
public bool IsMatching(GAnlysInput input) { int i = 0; foreach (var sourceWord in input.followings) { if (!words[i].Equals(sourceWord.word, StringComparison.CurrentCultureIgnoreCase)) { return(false); } if (i == words.Count - 1) { return(true); } i++; } //text end before match return(false); }
public void UnitProcess(GAnlysInput input, int fromIndex, IncrGAnalysisListener listener) { for (int index = fromIndex; index < wordAnalyzers.Count; index++) { if (wordAnalyzers[index].IsMatching(input)) { if (index < wordAnalyzers.Count - 1) { listener.OnMatch(input.GetAdvanced(wordAnalyzers[index].words.Count), wordAnalyzers[0], new PrvtAltGAnlys { parent = this, index = index + 1, input = input }); return; } else { listener.OnMatch(input.GetAdvanced(wordAnalyzers[index].words.Count), wordAnalyzers[0], null); return; } } } }
void GrammarAnalyzer.AnalyzeGrammar(GAnlysInput input, Taker <GrammarBlock> listener) { var result = new ExpansiveMutableGBlock { metaForCluster = StdMetaInfos.sentenceCluster }; Action <GrammarBlock> adder = (gBlock) => result.AddBlock(gBlock); var nextInput = input; while (true) { //prepare analyzePreparer.Init(); foreach (var morpheme in nextInput.followings) { analyzePreparer.FeedMorpheme(morpheme); if (morpheme.id == 2) { break; } } var easyLis = new EasyIncrGAnalysListener { }; incrGAnalyzer.Analyze(nextInput, easyLis); if (!easyLis.didMatch) { break; } nextInput = easyLis.nextInput; easyLis.listener.OnResultRequested(adder); } if (result.content != null) { listener.Take(result); } else { listener.None(); } }
void IncrGAnalysisListener.OnMatch(GAnlysInput result, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative) { didMatch = true; baseListener.OnMatch(result, listener, alternative); }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { UnitProcess(input, 0, listener); }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { Stack <EasyIncrGAnalysListener> resultArchives = new Stack <EasyIncrGAnalysListener>(); while (true) { var currentInput = resultArchives.Count == 0 ? input : resultArchives.Peek().nextInput; if (resultArchives.Count > 0 && conjectionAnalyzer != null) { var conjLis = new EasyIncrGAnalysListener(); conjectionAnalyzer.Analyze(currentInput, conjLis); if (conjLis.didMatch) { currentInput = conjLis.nextInput; } if (!conjLis.didMatch && !isConjectionOptional) { break; } } var easyLis = new EasyIncrGAnalysListener(); baseAnalyzer.Analyze(currentInput, easyLis); if (!easyLis.didMatch) { if (resultArchives.Count == 0) { return; } else { break; } } else { resultArchives.Push(easyLis); } } List <AfterMatchListener> afLiss = new List <AfterMatchListener>(); foreach (var result in resultArchives) { afLiss.Add(result.listener); } bool hasAlt = false; foreach (var result in resultArchives) { if (result.alternative != null) { hasAlt = true; } } AlternativeIncrGAnalyzer altLis = null; if (hasAlt) { altLis = new PrvtAltIGAnlys { givenResultArchive = resultArchives, parent = this }; } listener.OnMatch(resultArchives.Peek().nextInput, new PrvtLis { listeners = afLiss }, altLis); }
void IncrementalGAnalyzer.Analyze(GAnlysInput input, IncrGAnalysisListener listener) { baseAnalyzer.Analyze(input, new ResultChangingIGAListener { baseListener = listener, parent = this }); }