Prolog.KnowledgeBase.Consult C# (CSharp) Method

Consult() public method

Load assertions into the KB
public Consult ( string path ) : void
path string
return void
        public void Consult(string path)
        {
            var directoryPath = Prolog.LoadDirectoryPath(path);
            if (Path.GetExtension(directoryPath) == string.Empty && Directory.Exists(directoryPath))
            {
                foreach (var file in Directory.GetFiles(directoryPath))
                    if (IsSourceFile(file))
                        Consult(file);
            }
            else
            {
                path = DefaultExtension(Prolog.LoadFilePath(path), ".prolog");

                using (var stream = File.OpenText(path))
                {
                    string savedFileName = Prolog.CurrentSourceFile;
                    int savedLineNumber = Prolog.CurrentSourceLineNumber;
                    try
                    {
                        Prolog.CurrentSourceFile = path;
                        Prolog.CurrentSourceLineNumber = 0;
                        var textReader = new PositionTrackingTextReader(stream, path);
                        if (Path.GetExtension(path) == ".csv")
                        {
                            var functor = Symbol.Intern(Path.GetFileNameWithoutExtension(path));
                            this.IsTrue(new Structure("begin_csv_loading", functor)); // Ignore return value
                            new CSVParser(functor, ',', textReader).Read(this.LoadCSVRow);
                            this.IsTrue(new Structure("end_csv_loading", functor)); // Ignore return value
                        }
                        else
                            Consult(textReader);
                    }
                    finally
                    {
                        Prolog.CurrentSourceFile = savedFileName;
                        Prolog.CurrentSourceLineNumber = savedLineNumber;
                    }
                }
            }
        }

Same methods

KnowledgeBase::Consult ( Stream stream ) : void
KnowledgeBase::Consult ( TextReader inStream ) : 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