protected void ExpectToken(string token) { if (CurrentToken.ToLower() != token.ToLower()) { throw new ExpectedTokenNotFoundException(token, CurrentToken, Tokenizer.Position); } ReadNextToken(); }
/// <inheritdoc /> public override void ParseModifiers() { var tok = CurrentToken.ToLower(); if (tok == "not" || tok == "non" || tok == "never") { IsNegated = true; SkipToken(); if (!EndOfInput && CurrentToken == "-") { SkipToken(); } } }
protected void ExpectToken(string token) { var current = Tokenizer.Current; if (current == Token.Null || CurrentToken.ToLower() != token.ToLower()) { throw new ExpectedTokenNotFoundException( token, current != Token.Null ? current.ToString() : "EOF", Tokenizer.Position ); } ReadNextToken(); }
/// <summary> /// Attempt to match tokens to a complex NP, including modifiers. /// If successful, this sets Modifiers and CommonNoun directly. /// Will fail phrase includes an unknown noun or adjective. /// </summary> /// <returns>True on success</returns> // ReSharper disable once InconsistentNaming private bool ScanComplexNP() { Debug.Assert(CachedConcept == null); var beginning = State; MonadicConcept nextConcept; MonadicConceptLiteral last = null; Modifiers.Clear(); do { var isPositive = true; if (EndOfInput) { break; } var tok = CurrentToken.ToLower(); if (tok == "not" || tok == "non") { isPositive = false; SkipToken(); if (EndOfInput) { return(false); } if (CurrentToken == "-") { SkipToken(); } } nextConcept = Parser.MatchTrie(Ontology.MonadicConceptTrie); if (nextConcept != null) { var next = new MonadicConceptLiteral(nextConcept, isPositive); if (last != null) { Modifiers.Add(last); } last = next; if (!EndOfInput && !ElementOfList && CurrentToken == ",") { SkipToken(); } } } while (nextConcept != null); if (last?.Concept is Noun n) { CachedConcept = n; if (!Number.HasValue) { // Only update if Number wasn't already set by a determiner. // This is to get around nouns that are their own plurals. Number = Ontology.LastMatchPlural ? Parser.Number.Plural : Parser.Number.Singular; } RelativeFrequency = Parser.ParseRelativeFrequency(); SetText(beginning); return(true); } ResetTo(beginning); return(false); }