Package org.projog.core.parser
Class ProjogSourceReader
- java.lang.Object
-
- org.projog.core.parser.ProjogSourceReader
-
public final class ProjogSourceReader extends java.lang.ObjectPopulates aKnowledgeBasewith clauses parsed from Prolog syntax.
-
-
Field Summary
Fields Modifier and Type Field Description private KnowledgeBasekbprivate java.util.Map<PredicateKey,UserDefinedPredicateFactory>userDefinedPredicates
-
Constructor Summary
Constructors Modifier Constructor Description privateProjogSourceReader(KnowledgeBase kb)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddUserDefinedPredicatesToKnowledgeBase()private UserDefinedPredicateFactorycreateOrReturnUserDefinedPredicate(Term t)private static java.io.ReadergetReader(KnowledgeBase kb, java.lang.String resourceName)Creates a newReaderfor the specified resource.private static voidnotifyReadingFromClasspath(KnowledgeBase kb, java.lang.String resourceName)private static voidnotifyReadingFromFileSystem(KnowledgeBase kb, java.io.File file)private voidparse(java.io.Reader reader)static voidparseFile(KnowledgeBase kb, java.io.File prologSourceFile)Populates the KnowledgeBase with clauses defined in the file.static voidparseReader(KnowledgeBase kb, java.io.Reader reader)Populates the KnowledgeBase with clauses read from the Reader.static voidparseResource(KnowledgeBase kb, java.lang.String prologSourceResourceName)Populates the KnowledgeBase with clauses defined in the specified resource.private voidparseTerms(java.io.Reader reader)private voidprocessQuestion(Term t)private voidstoreParsedTerm(Term parsedTerm)
-
-
-
Field Detail
-
kb
private final KnowledgeBase kb
-
userDefinedPredicates
private final java.util.Map<PredicateKey,UserDefinedPredicateFactory> userDefinedPredicates
-
-
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 toprologSourceFile- 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
prologSourceResourceNamerefers to an existing file on the file system then that file is used as the source of the prolog syntax elseprologSourceResourceNameis read from the classpath.- Parameters:
kb- the KnowledgeBase to add the clauses toprologSourceResourceName- 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 toreader- 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 newReaderfor the specified resource.If
resourceNamerefers to an existing file on the filesystem then that file is used as the source of theReader. If there is no existing file on the filesystem matchingresourceNamethen 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)
-
createOrReturnUserDefinedPredicate
private UserDefinedPredicateFactory createOrReturnUserDefinedPredicate(Term t)
-
addUserDefinedPredicatesToKnowledgeBase
private void addUserDefinedPredicatesToKnowledgeBase()
-
-