コード例 #1
0
 /// <summary>
 /// Add clause to Problem stating that consequent(i) follow from antecedent(i)
 /// </summary>
 /// <param name="i">Individual for which this implication holds</param>
 /// <param name="antecedents">A set of conditions on i</param>
 /// <param name="consequent">A concept that must be true of i when the antecedents are true.</param>
 void AddImplication(Individual i, IEnumerable <MonadicConceptLiteral> antecedents, MonadicConceptLiteral consequent)
 {
     AddClause(antecedents.Select(a => Not(Satisfies(i, a))).Append(Satisfies(i, consequent)));
 }
コード例 #2
0
    /// <summary>
    /// The literal representing that concept k or its negation applies to individual i
    /// </summary>
    private Literal Satisfies(Individual i, MonadicConceptLiteral l)
    {
        var prop = IsA(i, l.Concept);

        return(l.IsPositive ? prop : Not(prop));
    }
コード例 #3
0
    /// <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>
    private bool ScanComplexNP()
    {
        UnityEngine.Debug.Assert(CachedConcept == null);
        var                   old = State;
        MonadicConcept        nextConcept;
        MonadicConceptLiteral last = null;

        Modifiers.Clear();
        do
        {
            var isPositive = true;
            if (EndOfInput)
            {
                break;
            }
            if (CurrentToken == "not" || CurrentToken == "non")
            {
                isPositive = false;
                SkipToken();
                if (EndOfInput)
                {
                    return(false);
                }
                if (CurrentToken == "-")
                {
                    SkipToken();
                }
            }
            nextConcept = MatchTrie(MonadicConcept.Trie);
            if (nextConcept != null)
            {
                var next = new MonadicConceptLiteral(nextConcept, isPositive);

                if (last != null)
                {
                    Modifiers.Add(last);
                }
                last = next;
                if (!EndOfInput && CurrentToken == ",")
                {
                    SkipToken();
                }
            }
        } while (nextConcept != null);

        if (last != null && 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 = MonadicConcept.LastMatchPlural ? Syntax.Number.Plural : Syntax.Number.Singular;
            }

            return(true);
        }

        ResetTo(old);
        return(false);
    }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 private void SetLiteral(Individual i, MonadicConceptLiteral l, bool truth) => SetIsA(i, l.Concept, l.IsPositive ? truth : !truth);
コード例 #6
0
 public ConditionalModifier(MonadicConceptLiteral[] conditions, MonadicConceptLiteral modifier)
 {
     Conditions = conditions ?? EmptyCondition;
     Modifier   = modifier;
 }