public Clause(AtomType type, Atom subj, AtomType pred, object val) { AtomType = type; Subject = subj; Predicate = pred; Object = val; }
public Clause(Atom subj, AtomType pred, object val) { AtomType = Expert.Ent_Belief; Subject = subj; Predicate = pred; Object = val; }
public IEnumerable <Atom> QueryType(AtomType type) { foreach (var clause in Clauses) { if (clause.TypeCheck(type)) { yield return(clause); } } }
public AtomType(string name, AtomType baseType = null) : base(name) { BaseType = baseType; if (baseType != null) { MemberFlags = baseType.MemberFlags; } IsIntegral = false; }
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; }
// //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; }
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); }
// 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); }
// public bool TypeCheck(AtomType type) { if (type.IsIntegral && (AtomType.MemberFlags & type.MemberFlags) == type.MemberFlags) { return(true); } if (AtomType == type) { return(true); } //else return(false); }
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); }
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); } }
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); } }
public Entity(string name, AtomType type) { Name = name; AtomType = type; }
// public AtomType(string name, AtomType baseType, AtomFlag atomTypeFlags) : this(name, baseType) { MemberFlags = atomTypeFlags; IsIntegral = true; }