Prolog.KnowledgeBase.Consult C# (CSharp) Method

Consult() private method

private Consult ( TextReader inStream ) : void
inStream System.IO.TextReader
return void
        public void Consult(TextReader inStream)
        {
            sourceFiles.NoteFile(Prolog.CurrentSourceFile);
            var reader = new ISOPrologReader(inStream);
            reader.SkipLayout();
            int lastLine = reader.LineNumber;
            using (var context = PrologContext.Allocate(this, this))
            {
                try
                {
                    object unexpanded;
                    Prolog.CurrentSourceLineNumber = lastLine;
                    while ((unexpanded = reader.ReadTerm()) != Symbol.EndOfFile)
                    {
                        // Perform user-level macroexpansion.
                        object assertion = TermExpansion(unexpanded);
                        if (ELProlog.IsELTerm(assertion))
                            // It's an EL term.
                            ELProlog.Update(assertion, this);
                        else
                        {
                            // It's a normal Prolog term
                            var t = Term.Structurify(
                                assertion,
                                "Assertions in prolog files must be valid propositions or predicates.");

                            // Perform built-in macroexpansion.
                            t = t.Expand();

                            if (t.IsFunctor(Symbol.Implication, 1))
                            {
                                context.Reset();
                                var goal = Term.Structurify(
                                    t.Argument(0),
                                    "Argument to a :- directive must be an atom or structure.");
                                // Run t once, but don't backtrack for a second solution (since it's presumably an imperative anyway).
                                Prove(goal.Functor, goal.Arguments, context, 0).GetEnumerator().MoveNext();
                            }
                            else
                                Assert(t, true, true);
                        }
                        reader.SkipLayout();
                        lastLine = reader.LineNumber;
                        Prolog.CurrentSourceLineNumber = lastLine;
                    }
                }
                catch (InferenceStepsExceededException e)
                {
                    Repl.RecordExceptionSourceLocation(e, lastLine);
                    throw;
                }
                catch (Exception e)
                {
            #if !DisableUnity
                    Debug.LogException(e);
                    Repl.RecordExceptionSourceLocation(e, lastLine);
            #endif
                    throw new PrologError(
                        e,
                        context.StackTrace(Prolog.CurrentSourceFile, Prolog.CurrentSourceLineNumber, "consult/1", false));
                }
            }
        }

Same methods

KnowledgeBase::Consult ( Stream stream ) : void
KnowledgeBase::Consult ( string path ) : void

Usage Example

Ejemplo n.º 1
0
        private void MakeKB()
        {
            var parent   = transform.parent;
            KB  parentKB = null;

            if (parent != null)
            {
                parentKB = parent.GetComponent <KB>();
            }

            kb = IsGlobal?
                 KnowledgeBase.Global
                : new KnowledgeBase(
                gameObject.name,
                gameObject,
                parentKB == null ? GameObject.Find(GlobalKBGameObjectName).KnowledgeBase() : parentKB.KnowledgeBase);

            // Add UID counter.
            ELNode.Store(kb.ELRoot / Symbol.Intern("next_uid") % 0);

            try
            {
                foreach (var file in SourceFiles)
                {
                    kb.Consult(file);
                }
            }
            catch (Exception)
            {
                Debug.Break(); // Pause the game
                throw;
            }
        }
All Usage Examples Of Prolog.KnowledgeBase::Consult