示例#1
0
 public Clause(AtomType type, Atom subj, AtomType pred, object val)
 {
     AtomType  = type;
     Subject   = subj;
     Predicate = pred;
     Object    = val;
 }
示例#2
0
 public Clause(Atom subj, AtomType pred, object val)
 {
     AtomType  = Expert.Ent_Belief;
     Subject   = subj;
     Predicate = pred;
     Object    = val;
 }
示例#3
0
 public IEnumerable <Atom> QueryType(AtomType type)
 {
     foreach (var clause in Clauses)
     {
         if (clause.TypeCheck(type))
         {
             yield return(clause);
         }
     }
 }
示例#4
0
 public AtomType(string name, AtomType baseType = null)
     : base(name)
 {
     BaseType = baseType;
     if (baseType != null)
     {
         MemberFlags = baseType.MemberFlags;
     }
     IsIntegral = false;
 }
示例#5
0
 public ClausePattern(AtomType type, Atom subj, Atom pred, object val, MatchFlag matchFlags)
 {
     Type  = type;
     Flags = type.MemberFlags;
     //
     Subject   = subj;
     Predicate = pred;
     Object    = val;
     //
     MatchFlags = matchFlags;
 }
示例#6
0
 //
 //TODO:probably not wise.
 public ClausePattern(Atom subj, Atom pred, object val)
 {
     Type  = Expert.Ent_Belief;
     Flags = Type.MemberFlags;
     //
     Subject   = subj;
     Predicate = pred;
     Object    = val;
     //
     MatchFlags = MatchFlag.None;
 }
示例#7
0
 public bool MatchPredObj(AtomType pred, object obj, out Atom subj)
 {
     if (Predicate == pred && Object.Equals(obj))
     {
         subj = Subject;
         return(true);
     }
     //else
     subj = null;
     return(false);
 }
示例#8
0
 //
 public bool MatchSubjPred <T>(Atom subj, AtomType pred, out T obj)
 {
     if (Predicate == pred && Subject == subj)
     {
         obj = (T)Object;
         return(true);
     }
     //else
     obj = default(T);
     return(false);
 }
示例#9
0
 //
 public bool TypeCheck(AtomType type)
 {
     if (type.IsIntegral && (AtomType.MemberFlags & type.MemberFlags) == type.MemberFlags)
     {
         return(true);
     }
     if (AtomType == type)
     {
         return(true);
     }
     //else
     return(false);
 }
示例#10
0
        public bool Exists <T>(Atom subj, AtomType pred, T obj)
        {
            ClausePattern target = new ClausePattern(subj, pred, obj);

            foreach (var clause in Clauses)
            {
                if (clause.Predicate != pred)
                {
                    continue;
                }
                if (target.Match(clause))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#11
0
        public IEnumerable <T> QuerySubjPred <T>(Atom subj, AtomType pred)
        {
            T obj;

            foreach (var clause in Clauses)
            {
                if (clause.Predicate != pred)
                {
                    continue;
                }
                if (!clause.MatchSubjPred(subj, pred, out obj))
                {
                    continue;
                }
                //else
                yield return(obj);
            }
        }
示例#12
0
        public IEnumerable <Atom> QueryPredObj <T>(AtomType pred, T obj)
        {
            Atom subj;

            foreach (var clause in Clauses)
            {
                if (clause.Predicate != pred)
                {
                    continue;
                }
                if (!clause.MatchPredObj(pred, obj, out subj))
                {
                    continue;
                }
                //else
                yield return(subj);
            }
        }
示例#13
0
 public Entity(string name, AtomType type)
 {
     Name     = name;
     AtomType = type;
 }
示例#14
0
 //
 public AtomType(string name, AtomType baseType, AtomFlag atomTypeFlags)
     : this(name, baseType)
 {
     MemberFlags = atomTypeFlags;
     IsIntegral  = true;
 }