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 AlternativeIncrGAnalyzer.AnalyzeAgain(IncrGAnalysisListener listener) { var nextInput = previousResult[previousResult.Count - 1].nextInput; var newResultStack = new List <EasyIncrGAnalysListener>(previousResult); #region try past alternatives while (newResultStack.Count != 0) { var lastResult = newResultStack[newResultStack.Count - 1]; if (lastResult.alternative != null) { var altLis = new EasyIncrGAnalysListener(); lastResult.alternative.AnalyzeAgain(altLis); if (altLis.didMatch) { newResultStack.RemoveAt(newResultStack.Count - 1); newResultStack.Add(lastResult); listener.OnMatch(altLis.nextInput, new ClusterAMListener { listeners = newResultStack }, new PrvtAltIGAnlys { parent = parent, previousResult = newResultStack }); return; } } } #endregion #region try repeat var conjLis = new EasyIncrGAnalysListener(); parent.conjectionAnalyzer.Analyze(nextInput, conjLis); if (conjLis.didMatch) { nextInput = conjLis.nextInput; } if (conjLis.didMatch || parent.isConjectionOptional) { var mainLis = new EasyIncrGAnalysListener(); parent.baseAnalyzer.Analyze(nextInput, mainLis); if (mainLis.didMatch) { newResultStack.Add(mainLis); listener.OnMatch(mainLis.nextInput, new ClusterAMListener { listeners = newResultStack }, new PrvtAltIGAnlys { parent = parent, previousResult = newResultStack }); return; } } #endregion }
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) { 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) { if (IsMatching(input)) { listener.OnMatch(input.GetAdvanced(words.Count), this); } }
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 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 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) { 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); } } } }
void IncrGAnalysisListener.OnMatch(GAnlysInput result, AfterMatchListener listener, AlternativeIncrGAnalyzer alternative) { didMatch = true; baseListener.OnMatch(result, listener, alternative); }
void AlternativeIncrGAnalyzer.AnalyzeAgain(IncrGAnalysisListener listener) { Stack <EasyIncrGAnalysListener> resultArchives = new Stack <EasyIncrGAnalysListener>(givenResultArchive); EasyIncrGAnalysListener lastLis = null; while (true) { if (resultArchives.Count <= 0) { return; } var analyzer = resultArchives.Pop(); if (analyzer.alternative == null) { continue; } var easyLis = new EasyIncrGAnalysListener(); analyzer.alternative.AnalyzeAgain(easyLis); if (easyLis.didMatch) { resultArchives.Push(easyLis); lastLis = easyLis; break; } } while (true) { if (parent.conjectionAnalyzer != null) { var conjLis = new EasyIncrGAnalysListener { }; parent.conjectionAnalyzer.Analyze(lastLis.nextInput, conjLis); if (conjLis.didMatch) { lastLis = conjLis; } else if (!parent.isConjectionOptional) { return; } } var easyLis = new EasyIncrGAnalysListener(); parent.baseAnalyzer.Analyze(lastLis.nextInput, 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 altAnlys = null; if (hasAlt) { altAnlys = new PrvtAltIGAnlys { givenResultArchive = resultArchives, parent = parent }; } listener.OnMatch(resultArchives.Peek().nextInput, new PrvtLis { listeners = afLiss }, altAnlys); }
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 AlternativeIncrGAnalyzer.AnalyzeAgain(IncrGAnalysisListener listener) { #region try past alternatives if (previousAlt != null) { var altLis = new EasyIncrGAnalysListener(); previousAlt.AnalyzeAgain(altLis); if (altLis.didMatch) { var alt = new PrvtAltIGAnlys { parent = parent, previousAlt = altLis.alternative, analyzers = analyzers, input = input }; listener.OnMatch(altLis.nextInput, altLis.listener, alt); return; } } #endregion #region try repeat /*if (parent.conjectionAnalyzer != null && !parent.isConjectionOptional) { * var easyConjLis = new EasyIncrGAnalysListener(); * parent.conjectionAnalyzer.Analyze(input, easyConjLis); * if (!easyConjLis.didMatch) { * return; * } * }*/ var newAnalyzers = new List <IncrementalGAnalyzer>(analyzers); if (parent.conjectionAnalyzer != null) { if (parent.isConjectionOptional) { newAnalyzers.Add(new IGAnlys_IgnoreBlock { baseAnalyzer = new IGAnlys_Optional { baseAnalyzer = parent.conjectionAnalyzer } }); } else { newAnalyzers.Add(new IGAnlys_IgnoreBlock { baseAnalyzer = parent.conjectionAnalyzer }); } } newAnalyzers.Add(parent.baseAnalyzer); var repeatLis = new EasyIncrGAnalysListener(); newAnalyzers[0].Analyze( input, new ChainListener { index = 0, results = new List <IndexAndResult>(), analyzers = newAnalyzers, finalListener = repeatLis, afterListenerFactory = DefaultAfterListener } ); if (repeatLis.didMatch) { listener.OnMatch(repeatLis.nextInput, repeatLis.listener, new PrvtAltIGAnlys { analyzers = newAnalyzers, input = input, parent = parent, previousAlt = repeatLis.alternative } ); } #endregion }