Esempio n. 1
0
        /// <summary>
        /// Load assertions into the KB
        /// </summary>
        public void Consult(string path)
        {
            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;
                }
            }
        }
Esempio n. 2
0
 public CSVParser(Symbol functor, char delimiter, PositionTrackingTextReader reader)
 {
     this.functor = functor;
     this.delimiter = delimiter;
     this.reader = reader;
 }
Esempio n. 3
0
        /// <summary>
        /// Load assertions into the KB
        /// </summary>
        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;
                    }
                }
            }
        }
Esempio n. 4
0
 public CSVParser(Symbol functor, char delimiter, PositionTrackingTextReader reader)
 {
     this.functor   = functor;
     this.delimiter = delimiter;
     this.reader    = reader;
 }