Class ProjogSourceReader


  • public final class ProjogSourceReader
    extends java.lang.Object
    Populates a KnowledgeBase with clauses parsed from Prolog syntax.

    • Constructor Detail

      • ProjogSourceReader

        private ProjogSourceReader​(KnowledgeBase kb)
    • Method Detail

      • parseFile

        public static void parseFile​(KnowledgeBase kb,
                                     java.io.File prologSourceFile)
        Populates the KnowledgeBase with clauses defined in the file.
        Parameters:
        kb - the KnowledgeBase to add the clauses to
        prologSourceFile - source of the prolog syntax defining clauses to add to the KnowledgeBase
        Throws:
        ProjogException - if there is any problem parsing the syntax or adding the new clauses to the KnowledgeBase
      • parseResource

        public static void parseResource​(KnowledgeBase kb,
                                         java.lang.String prologSourceResourceName)
        Populates the KnowledgeBase with clauses defined in the specified resource.

        If prologSourceResourceName refers to an existing file on the file system then that file is used as the source of the prolog syntax else prologSourceResourceName is read from the classpath.

        Parameters:
        kb - the KnowledgeBase to add the clauses to
        prologSourceResourceName - source of the prolog syntax defining clauses to add to the KnowledgeBase
        Throws:
        ProjogException - if there is any problem parsing the syntax or adding the new clauses to the KnowledgeBase
      • parseReader

        public static void parseReader​(KnowledgeBase kb,
                                       java.io.Reader reader)
        Populates the KnowledgeBase with clauses read from the Reader.

        Note that this method will call close() on the specified reader - regardless of whether this method completes successfully or if an exception is thrown.

        Parameters:
        kb - the KnowledgeBase to add the clauses to
        reader - source of the prolog syntax defining clauses to add to the KnowledgeBase
        Throws:
        ProjogException - if there is any problem parsing the syntax or adding the new clauses to the KnowledgeBase
      • getReader

        private static java.io.Reader getReader​(KnowledgeBase kb,
                                                java.lang.String resourceName)
                                         throws java.io.IOException
        Creates a new Reader for the specified resource.

        If resourceName refers to an existing file on the filesystem then that file is used as the source of the Reader. If there is no existing file on the filesystem matching resourceName then an attempt is made to read the resource from the classpath.

        Throws:
        java.io.IOException
      • notifyReadingFromFileSystem

        private static void notifyReadingFromFileSystem​(KnowledgeBase kb,
                                                        java.io.File file)
      • notifyReadingFromClasspath

        private static void notifyReadingFromClasspath​(KnowledgeBase kb,
                                                       java.lang.String resourceName)
      • parse

        private void parse​(java.io.Reader reader)
      • parseTerms

        private void parseTerms​(java.io.Reader reader)
      • processQuestion

        private void processQuestion​(Term t)
        Parameters:
        t - structure with name of ?- and a single argument.
      • storeParsedTerm

        private void storeParsedTerm​(Term parsedTerm)
      • addUserDefinedPredicatesToKnowledgeBase

        private void addUserDefinedPredicatesToKnowledgeBase()