public static Trigger TryToGetTrigger(ITerm t) { if (t.GetType() == typeof(Trigger)) { return((Trigger)t); } if (t.IsPlanBody()) { IPlanBody p = (IPlanBody)t; if (p.GetPlanSize() == 1) { TEOperator op = null; if (p.GetBodyType() == BodyType.Body_Type.addBel) { op = TEOperator.add; } else if (p.GetBodyType() == BodyType.Body_Type.delBel) { op = TEOperator.del; } if (op != null) { Literal l = ((Literal)p.GetBodyTerm().Clone()).ForceFullLiteralImpl(); l.DelAnnot(BeliefBase.TSelf); return(new Trigger(op, TEType.belief, l)); } } } if (t.IsString()) { return(AsSyntax.ParseTrigger(((IStringTerm)t).GetString())); } return(null); }
// Same as previous Add. If "before" is true, add at the beginning of the library. public Plan Add(IStringTerm stPlan, ITerm tSource, bool before) { string sPlan = stPlan.GetString(); // Remove quotes StringBuilder sTemp = new StringBuilder(); for (int c = 0; c < sPlan.Length; c++) { if (sPlan[c] != '\\') { sTemp.Append(sPlan[c]); } } sPlan = sTemp.ToString(); Plan p = AsSyntax.ParsePlan(sPlan); // ??? return(Add(p, tSource, before)); }
/** creates a literal from a list with four elements: [namespace, functor, list of terms, list of annots] * (namespace is optional) */ public static Literal NewFromListOfTerms(IListTerm lt) { try { System.Collections.Generic.IEnumerator <ITerm> i = lt.GetEnumerator(); Atom ns = DefaultNS; if (lt.Count == 4) { ns = i.Current as Atom; } ITerm tFunctor = i.Current; bool pos = Literal.LPos; if (tFunctor.IsLiteral() && (tFunctor as Literal).Negated()) { pos = Literal.LNeg; } if (tFunctor.IsString()) { tFunctor = AsSyntax.ParseTerm((tFunctor as IStringTerm).GetString()); } Literal l = new LiteralImpl(ns, pos, (tFunctor as Atom).GetFunctor()); if (i.Current != null) { //l.SetTerms((i.Current as IListTerm).CloneLT()); return(null); } if (i.Current != null) { l.SetAnnots((i.Current as IListTerm).CloneLT()); } return(l); } catch (Exception) { throw new JasonityException("Error creating literal from" + lt); } }