public static AnnotatedSentence ParseAnnotatedPreservingQuotes( this IRussianGrammarParser @this, string annotatedText, IRussianLexicon russianLexicon) { var quotedSequences = LocateQuotedSequences(annotatedText); var quotationSubstitutions = MakeSubstitutionsOfQuotedSequencesWithSingleWords(quotedSequences); var textWithSubstitutedQuotes = ApplySubstitutions(quotationSubstitutions, annotatedText); var markedupWords = @this.ParseMarkup(textWithSubstitutedQuotes).ToArray(); var sentenceWithoutMarkup = string.Join(" ", markedupWords.Select(w => w.Content)); var parsedText = WorkaroundForSituationsWhenParserRetunsFlatChainOfElements(@this, sentenceWithoutMarkup); var sentenceStructure = RestoreQuotations(quotationSubstitutions, parsedText).Single( _ => true, _ => new InvalidOperationException( $"Text '{textWithSubstitutedQuotes}' could not be tokenized unambiguously. Please reformulate it.")); ProgramLogic.Check( ( markedupWords.Select(w => w.Content).AsImmutable(), IterateDepthFirst(parsedText) .OrderBy(it => it.PositionInSentence) .Select(it => it.Content) .AsImmutable() ) switch { var(markups, grammars) when !markups.SequenceEqual(grammars, Impl.RussianIgnoreCase) => Some( "Parsing marked-up sentence gave the result that is incompatible with " + "the structure returned by russian grammmar parser." + Environment.NewLine + "Markup parsing result: " + string.Join(";", markups) + Environment.NewLine + "Russian grammar parsing result: " + string.Join(";", grammars)), _ => None });
public static SentenceUnderstander LoadFromPatterns( IEnumerable <GenerativePattern> generativePatterns, IRussianGrammarParser grammarParser, IRussianLexicon russianLexicon, MeaningBuilder meaningBuilder) { var concreteUnderstanders = new List <ConcretePatternOfUnderstanding>(); var result = new SentenceUnderstander(concreteUnderstanders); foreach (var generativePattern in generativePatterns) { var concretePatterns = generativePattern .GenerateConcretePatterns(grammarParser, russianLexicon) .AsImmutable(); var ambiguouslyUnderstoodPatterns = ( from it in concretePatterns let pattern = it.PatternWithMeaning.Pattern let understanding = Understand( pattern.AsParsedSentence(), concreteUnderstanders, meaningBuilder) where understanding.IsRight select new { Pattern = pattern, NewPatternId = generativePattern.PatternId, ExistingPatternId = understanding.Right !.PatternId }
public Patterns( ScenarioContext scenarioContext, IRussianGrammarParser grammarParser, IRussianLexicon russianLexicon) { _scenarioContext = scenarioContext; _grammarParser = grammarParser; _russianLexicon = russianLexicon; }
public Sut( ScenarioContext scenarioContext, IRussianGrammarParser grammarParser, Patterns patterns) { _scenarioContext = scenarioContext; _grammarParser = grammarParser; _patterns = patterns; }
public static SentenceUnderstander LoadFromEmbeddedResources( IRussianGrammarParser grammarParser, IRussianLexicon russianLexicon, MeaningBuilder meaningBuilder) => LoadFromPatterns( ParsePatterns(ReadEmbeddedResource("Ginger.Runner.SentenceUnderstandingRules.txt")), grammarParser, russianLexicon, meaningBuilder);
public static IReadOnlyCollection <MarkedupWord> ParseMarkup( this IRussianGrammarParser @this, string markedupText) { var parsedText = ExtractTildasToSeparateTokens(@this.Tokenize(markedupText)).ToArray(); return(MarkupParser(new Tokens(parsedText)) .Fold( error => throw new InvalidOperationException( $"Error parsing markup text: {error.Text} at {error.Location}"), result => result.Value)); }
public static ParsedSentence ParsePreservingQuotes( this IRussianGrammarParser @this, string sentence) { var quotedSequences = LocateQuotedSequences(sentence); var quotationSubstitutions = MakeSubstitutionsOfQuotedSequencesWithSingleWords(quotedSequences); var textWithSubstitutedQuotes = ApplySubstitutions(quotationSubstitutions, sentence); var parsedText = WorkaroundForSituationsWhenParserRetunsFlatChainOfElements(@this, textWithSubstitutedQuotes); var sentenceStructure = RestoreQuotations(quotationSubstitutions, parsedText).Single( _ => true, _ => new InvalidOperationException( $"Text '{textWithSubstitutedQuotes}' could not be tokenized unambiguously. Please reformulate it.")); return(new (sentence, sentenceStructure)); }
public SutSpecificationBuilder(IRussianGrammarParser grammarParser, SentenceUnderstander sentenceUnderstander) { _grammarParser = grammarParser; _sentenceUnderstander = sentenceUnderstander; }
public SolarixParserMemoizer(IRussianGrammarParser wrappedParser) { _wrappedParser = wrappedParser; EnsureDataFileExists(); _knownSentences = LoadKnownSentences(); }
public InternalFunctionalityTestSteps( IRussianGrammarParser grammarParser, IRussianLexicon russianLexicon) => (_grammarParser, _russianLexicon) = (grammarParser, russianLexicon);