public EntryIteratorWrapper(BelEntry e, HashSet <Literal> percepts, int size) { entry = e; il = entry.list.GetEnumerator(); this.percepts = percepts; this.size = size; }
protected object Clone() { BelEntry be = new BelEntry(); foreach (Literal l in list) { be.Add(l.Copy(), false); } return(be); }
public IEnumerator <Literal> GetCandidateBeliefs(PredicateIndicator pi) { Dictionary <PredicateIndicator, BelEntry> pi2entry; nameSpaces.TryGetValue(pi.GetNS(), out pi2entry); if (pi2entry == null) { return(null); } BelEntry entry = pi2entry[pi]; if (entry != null) { return(new EntryIteratorWrapper(entry, percepts, size)); } else { return(null); } }
// Checks if the belief base contains a specific literal public Literal Contains(Literal l) { Dictionary <PredicateIndicator, BelEntry> aux; nameSpaces.TryGetValue(l.GetNS(), out aux); Dictionary <PredicateIndicator, BelEntry> belsMap = l.GetNS() == Literal.DefaultNS ? belsMapDefaultNS : aux; if (belsMap == null) { return(null); } BelEntry entry = belsMap[l.GetPredicateIndicator()]; if (entry == null) { return(null); } else { return(entry.Contains(l)); } }
private bool RemoveFromEntry(Literal l) { if (l.HasSource()) { return(false); } else { Dictionary <PredicateIndicator, BelEntry> aux; nameSpaces.TryGetValue(l.GetNS(), out aux); Dictionary <PredicateIndicator, BelEntry> belsMap = l.GetNS() == Literal.DefaultNS ? belsMapDefaultNS : aux; PredicateIndicator key = l.GetPredicateIndicator(); BelEntry entry = belsMap[key]; entry.Remove(l); if (entry.IsEmpty()) { belsMap.Remove(key); } size--; return(true); } }
private BelEntry ProvideBelEntry(Literal l) { Dictionary <PredicateIndicator, BelEntry> belsMap = belsMapDefaultNS; if (l.GetNS() != Literal.DefaultNS) { nameSpaces.TryGetValue(l.GetNS(), out belsMap); if (belsMap == null) { belsMap = new Dictionary <PredicateIndicator, BelEntry>(); nameSpaces.Add(l.GetNS(), belsMap); } } BelEntry entry = belsMap[l.GetPredicateIndicator()]; if (entry == null) { entry = new BelEntry(); belsMap.Add(l.GetPredicateIndicator(), entry); } return(entry); }
// Adds a new literal at the end of the belief base protected bool Add(Literal l, bool addInEnd) { if (!l.CanBeAddedInBB()) { return(false); } Literal bl = Contains(l); if (bl != null && !bl.IsRule()) { if (bl.ImportAnnots(l)) { if (l.HasAnnot(TPercept)) { percepts.Add(bl); } return(true); } } else { // new belief l = l.Copy(); BelEntry entry = ProvideBelEntry(l); entry.Add(l, addInEnd); // Add it to percepts list if (l.HasAnnot(TPercept)) { percepts.Add(l); } size++; return(true); } return(false); }
public IEnumerator <Literal> GetCandidateBeliefs(Literal l, Unifier u) { if (l.IsVar()) { return(GetEnumerator()); } else { Dictionary <PredicateIndicator, BelEntry> belsMap = belsMapDefaultNS; if (l.GetNS() != Literal.DefaultNS) { Atom ns = l.GetNS(); if (ns.IsVar()) { l = (Literal)l.CApply(u); ns = l.GetNS(); } if (ns.IsVar()) { return(GetEnumerator()); } nameSpaces.TryGetValue(ns, out belsMap); } if (belsMap == null) { return(null); } BelEntry entry = belsMap[l.GetPredicateIndicator()]; if (entry != null) { return(new EntryIteratorWrapper(entry, percepts, size)); } else { return(null); } } }