示例#1
0
        /// <summary>
        /// Does this lexica match the rule
        /// </summary>
        /// <param name="word">The lex</param>
        /// <returns>if it matches</returns>
        public bool Matches(ILexica lex)
        {
            string[] fromBegins = FromBeginsWith.Split('|', StringSplitOptions.RemoveEmptyEntries);
            string[] fromEnds   = FromEndsWith.Split('|', StringSplitOptions.RemoveEmptyEntries);

            return((fromBegins.Count() == 0 || fromBegins.Any(bw => lex.Phrase.StartsWith(bw))) &&
                   (fromEnds.Count() == 0 || fromEnds.Any(bw => lex.Phrase.EndsWith(bw))) &&
                   (Tense == LexicalTense.None || lex.Context.Tense == Tense) &&
                   (Perspective == NarrativePerspective.None || lex.Context.Perspective == Perspective) &&
                   (!WhenPlural || lex.Context.Plural) &&
                   (!WhenPossessive || lex.Context.Possessive) &&
                   (SpecificWord == null || SpecificWord.Equals(lex.GetDictata())) &&
                   (SpecificWord != null || ((FromRole == GrammaticalType.None || FromRole == lex.Role) && (FromType == LexicalType.None || FromType == lex.Type))));
        }
示例#2
0
 /// <summary>
 /// Rate this rule on how specific it is so we can run the more specific rules first
 /// </summary>
 /// <returns>Specificity rating, higher = more specific</returns>
 public int RuleSpecificity()
 {
     return((string.IsNullOrWhiteSpace(FromSemantics) ? 0 : FromSemantics.Count(ch => ch == '|') * 3 + 1) +
            (string.IsNullOrWhiteSpace(FromEndsWith) ? 0 : FromEndsWith.Count(ch => ch == '|') + 3) +
            (string.IsNullOrWhiteSpace(FromBeginsWith) ? 0 : FromBeginsWith.Count(ch => ch == '|') + 3) +
            (SpecificWord == null ? 0 : 99) +
            (Tense == LexicalTense.None ? 0 : 2) +
            (Perspective == NarrativePerspective.None ? 0 : 2) +
            (FromType == LexicalType.None ? 0 : 3) +
            (FromRole == GrammaticalType.None ? 0 : 3) +
            (WhenPlural ? 2 : 0) +
            (WhenPositional ? 6 : 0) +
            (WhenPossessive ? 2 : 0));
 }