private Event CreateEventFromTerm(PlTerm term) { if (term.Name != "event" || term.Arity != 2) { return(null); } var queryEventArgs = new PlTerm[] { term[1], PlTerm.PlVar(), PlTerm.PlVar(), PlTerm.PlVar(), PlTerm.PlVar(), PlTerm.PlVar(), PlTerm.PlVar() }; bool eventExists = PlQuery.PlCall("eventType", new PlTermV(queryEventArgs)); if (!eventExists) { return(null); } var argsLst = PlTermExtension.ArgsLst(term[1]); var stateTermsArgs = instanceStateTermArgs(argsLst); if (stateTermsArgs == null) { return(null); } return(new Event(term[1].Name, term[1].Arity, stateTermsArgs, float.Parse(term[2].ToString(), CultureInfo.InvariantCulture))); }
private State CreateStateFromTerm(PlTerm stateTerm) { var argsLst = PlTermExtension.ArgsLst(stateTerm); var type = new StateType(stateTerm.Name, stateTerm.Arity); if (!_StateTypeSpecs.ContainsKey(type)) { return(null); } var specsSet = _StateTypeSpecs[type]; IEnumerable <StateTerm> stateTermsArgs = null; foreach (var specsLst in specsSet) { if (argsSatisfySpecs(specsLst, argsLst, out var stateTerms)) { stateTermsArgs = stateTerms; break; } } return(stateTermsArgs != null ? new State(type.Name, type.Arity, stateTermsArgs) : null); }