Package com.semedy.reasoner.api.core
Class DeductiveDatabase
java.lang.Object
com.semedy.reasoner.api.core.DeductiveDatabase
- Direct Known Subclasses:
QueryRunner
,StreamReasoningDB
High level interface for a whole deductive database.
Encapsulates symbol handler, edb, idb, builtins, rewriters.
Provides adding/removing facts, adding/removing rules,
querying and transaction handling of fact and rule modifications.
DDB is thread local, so every thread has its own instance of DDB.
Core which is a member of DDB is shared for different DDBs.
Encapsulates symbol handler, edb, idb, builtins, rewriters.
Provides adding/removing facts, adding/removing rules,
querying and transaction handling of fact and rule modifications.
DDB is thread local, so every thread has its own instance of DDB.
Core which is a member of DDB is shared for different DDBs.
- Author:
- angele
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a fact to the deductive database.boolean
addFacts
(Collection<Literal> facts) Add facts to the deductive database.boolean
add a rule to the deductive database.boolean
add a rule to the deductive database.boolean
addRules
(Collection<Rule> rules, boolean parsed) Add rules to the deductive database.void
addRulesAndFacts
(String rulesAndFacts) add rules and facts from textvoid
applyChangeSet
(List<String> paths) Applies changes to the extensional database.
During this operation the to be modified predicates
are read locked.void
create a backup for the databasevoid
export
(InterruptFlag interrupt, List<String> predicates, String resultdirectory) bulk export of facts for predicates to raw files in result directoryvoid
exportNQuads
(Writer writer, String iri) export of facts as N-Quads.void
exportNQuads
(String resultpath, String iri) export of facts as N-Quadsvoid
exportOOLogic
(InterruptFlag interrupt, Writer writer, String module) export of facts and rules for predicates to file in OO-logic into a module.void
exportOOLogic
(InterruptFlag interrupt, String resultpath, String module) export of facts and rules for predicates to file in OO-logic into a module.void
exportOOLogic
(InterruptFlag interrupt, List<Filter> filters, Writer writer, String module) export of facts and rules for predicates to file in OO-logic into a module.void
exportOOLogic
(InterruptFlag interrupt, List<Filter> filter, String resultpath, String module) export of facts and rules for predicates to file in OO-logic into a module.void
exportRules
(Writer writer) store all rules in file given by file pathvoid
exportRules
(String filepath, boolean append) store all rules in file given by file pathgetCore()
Return the reasoner coregetRuleById
(String ruleIdentifier) get a rule by its rule identifiergetRules()
get all rulesget the extensional database for snapshotsget reasoning symbol tablevoid
load files from file path
path can be a directory or a single file
files are distinguished by their endings:
.raw, .raw.zip, .rls, .fctvoid
load files from file paths
files are distinguished by their endings:
.raw, .raw.zip, .rls, .fctvoid
loadByStream
(InputStream in, InputStream companionstream, String format) load facts by stream. format is either the file format like raw,json,nq etc.void
loadPredicates
(InputStream input) Load facts and/or rules in predicate format from an input stream.boolean
start a long transaction
If a long transaction is already running false is returnedboolean
commit a long transactionvoid
discard all changesvoid
materializeQueries
(InterruptFlag interruptFlag, String squeries, ReasoningMonitor monitor) Materialize queries.void
materializeQueries
(InterruptFlag interruptFlag, String squeries, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) Materialize queries.void
materializeQueries
(InterruptFlag interruptFlag, List<Rule> queries, ReasoningMonitor monitor) Materialize queries.void
materializeQueries
(InterruptFlag interruptFlag, List<Rule> queries, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) Materialize queries.query
(InterruptFlag interruptFlag, Rule query, int maxNumberOfResults, ReasoningMonitor monitor) Pose a query.query
(InterruptFlag interruptFlag, Rule query, int maxNumberOfResults, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) Pose a query.query
(InterruptFlag interruptFlag, String query, int maxNumberOfResults, Configuration config, Properties builtinConfig) Pose a query.query
(InterruptFlag interruptFlag, String query, int maxNumberOfResults, ReasoningMonitor monitor) Pose a query.query
(InterruptFlag interruptFlag, String query, int maxNumberOfResults, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) Pose a query.query
(InterruptFlag interruptFlag, String query, Properties builtinConfig) Pose a query.query
(InterruptFlag interruptFlag, List<Rule> queries, int maxNumberOfResults, ReasoningMonitor monitor) Pose a query and several rulesquery
(InterruptFlag interruptFlag, List<Rule> queries, int maxNumberOfResults, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) Pose a query and several rulesquery
(InterruptFlag interruptFlag, List<Rule> queries, int maxNumberOfResults, ReasoningMonitor monitor, ExtensionalDB[] additionalEDBs, IntensionalDB[] additionalIDBs, boolean skipAnswers, Configuration config, Properties builtinConfig) Pose a query and several rules.boolean
Remove a fact from the deductive database.boolean
Remove a fact from the deductive database.boolean
removeFacts
(Collection<Literal> facts) Remove facts from the deductive database.boolean
removeFactsEncoded
(Collection<Literal> facts) Remove facts from the deductive database.boolean
removeRuleById
(String id) remove a rule identified by the unique id.boolean
removeRules
(Collection<Rule> rules) Remove rules from the deductive database.void
removeRulesAndFacts
(String rulesAndFacts) remove rules and facts from textvoid
start a transactionvoid
commit all modificationsvoid
discard all changes
-
Constructor Details
-
DeductiveDatabase
- Throws:
IOException
SemReasonerException
-
-
Method Details
-
getRules
get all rules- Returns:
- Throws:
SemReasonerException
-
getRuleById
get a rule by its rule identifier- Parameters:
ruleIdentifier
-- Returns:
- Throws:
SemReasonerException
-
getSymbolTable
get reasoning symbol table- Returns:
-
getSnapshotEDB
get the extensional database for snapshots- Returns:
-
getCore
Return the reasoner core -
addFact
Add a fact to the deductive database.
This facts becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
L
- , literal to be added- Returns:
- Throws:
IOException
EDBException
InterruptedException
-
addRulesAndFacts
public void addRulesAndFacts(String rulesAndFacts) throws SemReasonerException, InterruptedException add rules and facts from text- Parameters:
rulesAndFacts
- , rules and facts as text- Throws:
SemReasonerException
InterruptedException
-
removeRulesAndFacts
public void removeRulesAndFacts(String rulesAndFacts) throws IOException, SemReasonerException, InterruptedException remove rules and facts from text- Parameters:
rulesAndFacts
-- Throws:
IOException
SemReasonerException
InterruptedException
-
addRule
public boolean addRule(Rule R, boolean parsed) throws IOException, SemReasonerException, InterruptedException add a rule to the deductive database.- Parameters:
R
- , rule to be added @return, true if rule has been addedparsed
- , rule has been parse before- Throws:
IOException
SemReasonerException
InterruptedException
-
addRule
add a rule to the deductive database.- Parameters:
R
- , rule to be added @return, true if rule has been added- Throws:
SemReasonerException
InterruptedException
-
removeRuleById
public boolean removeRuleById(String id) throws IOException, SemReasonerException, InterruptedException remove a rule identified by the unique id.- Parameters:
id
-- Returns:
- true if rule has been removed
- Throws:
SemReasonerException
IOException
InterruptedException
-
removeFact
Remove a fact from the deductive database.
This change becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
L
- , literal to be removed- Returns:
- true, if fact has been removed
- Throws:
IOException
EDBException
InterruptedException
-
removeFactEncoded
public boolean removeFactEncoded(Literal L) throws IOException, SemReasonerException, InterruptedException Remove a fact from the deductive database.
Fact is already encoded.
This change becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
L
- , literal to be removed- Returns:
- true, if fact has been removed
- Throws:
IOException
SemReasonerException
InterruptedException
-
addFacts
public boolean addFacts(Collection<Literal> facts) throws EDBException, IOException, InterruptedException Add facts to the deductive database.
These facts becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
facts
-- Returns:
- true, if all facts have been added
- Throws:
IOException
EDBException
InterruptedException
-
removeFacts
public boolean removeFacts(Collection<Literal> facts) throws EDBException, IOException, InterruptedException Remove facts from the deductive database.
This change becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
facts
- to be added- Returns:
- true, if all facts have been added
- Throws:
IOException
EDBException
InterruptedException
-
removeFactsEncoded
public boolean removeFactsEncoded(Collection<Literal> facts) throws IOException, SemReasonerException, InterruptedException Remove facts from the deductive database.
Facts are already encoded.
This change becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
facts
- to be added- Returns:
- true, if all facts have been added
- Throws:
IOException
SemReasonerException
InterruptedException
-
addRules
public boolean addRules(Collection<Rule> rules, boolean parsed) throws IOException, SemReasonerException, InterruptedException Add rules to the deductive database.
This change becomes visible to the current thread only.
These rules must not be parsed by rule parser before.
After commit it becomes visible to others as well.- Parameters:
rules
- to be addedparsed
- rules have been parsed before- Returns:
- true, if all rules have been added
- Throws:
IOException
SemReasonerException
InterruptedException
-
removeRules
public boolean removeRules(Collection<Rule> rules) throws IOException, SemReasonerException, InterruptedException Remove rules from the deductive database.
This change becomes visible to the current thread only.
After commit it becomes visible to others as well.- Parameters:
rules
- to be removed.- Returns:
- true if all rules have been removed
- Throws:
SemReasonerException
IOException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, String query, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Pose a query. Get the results as an enumerator for tuples of objects- Parameters:
interruptFlag
- for interrupting the evaluationquery
- , the querybuiltinConfig
- , configurations for built-ins e.g. access tokens- Returns:
- an enumerator for results
- Throws:
ReasoningException
SimpleParseException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, String query, int maxNumberOfResults, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Pose a query. Get the results as an enumerator for tuples of objects- Parameters:
interruptFlag
- for interrupting the evaluationquery
- , the querymaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsbuiltinConfig
- , configurations for built-ins e.g. access tokens- Returns:
- an enumerator for results
- Throws:
ReasoningException
SimpleParseException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, String query, int maxNumberOfResults, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Pose a query. Get the results as an enumerator for tuples of objects- Parameters:
interruptFlag
- for interrupting the evaluationquery
- , the querymaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , monitoring reasoning, may be nullbuiltinConfig
- , configurations for built-ins e.g. access tokens- Returns:
- an enumerator for results
- Throws:
ReasoningException
SimpleParseException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, String query, int maxNumberOfResults, ReasoningMonitor monitor) throws SemReasonerException, InterruptedException, IOException Pose a query. Get the results as an enumerator for tuples of objects- Parameters:
interruptFlag
- for interrupting the evaluationquery
- , the querymaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , monitoring reasoning, may be null- Returns:
- an enumerator for results
- Throws:
ReasoningException
SimpleParseException
IOException
SemReasonerException
InterruptedException
-
transactionBegin
start a transaction- Throws:
SemReasonerException
IOException
-
longTransactionBegin
start a long transaction
If a long transaction is already running false is returned- Throws:
SemReasonerException
IOException
-
longTransactionCommit
public boolean longTransactionCommit() throws SemReasonerException, EDBException, IOException, InterruptedExceptioncommit a long transaction -
longTransactionRollback
discard all changes -
transactionRollback
discard all changes -
transactionCommit
commit all modifications -
load
public void load(String path) throws EDBException, IOException, SimpleParseException, SemReasonerException, InterruptedException, SymboltableException load files from file path
path can be a directory or a single file
files are distinguished by their endings:
.raw, .raw.zip, .rls, .fct- Parameters:
path
-- Throws:
EDBException
IOException
SimpleParseException
SemReasonerException
InterruptedException
SymboltableException
-
loadByStream
public void loadByStream(InputStream in, InputStream companionstream, String format) throws EDBException, IOException, SimpleParseException, SemReasonerException, SymboltableException, InterruptedException load facts by stream. format is either the file format like raw,json,nq etc. In case of raw it is the predicate like value|3 A companionstream contains additional information, e.g. schema information for csv- Parameters:
in
- , stream for the csv datacompanionstream
- , additional stream describing the data types and new header namesformat
-- Throws:
UnsupportedEncodingException
IOException
SemReasonerException
InterruptedException
EDBException
SimpleParseException
SymboltableException
-
load
public void load(List<String> paths) throws EDBException, IOException, SimpleParseException, SemReasonerException, InterruptedException, SymboltableException load files from file paths
files are distinguished by their endings:
.raw, .raw.zip, .rls, .fct- Parameters:
paths
-- Throws:
EDBException
IOException
SimpleParseException
SemReasonerException
InterruptedException
SymboltableException
-
loadPredicates
public void loadPredicates(InputStream input) throws SemReasonerException, IOException, SimpleParseException, InterruptedException, EDBException Load facts and/or rules in predicate format from an input stream. Loading facts in this way is much slower than raw files or fct files.- Parameters:
input
- , the input stream- Throws:
IOException
SimpleParseException
SemReasonerException
InterruptedException
EDBException
-
backup
create a backup for the database- Parameters:
backupfile
-- Throws:
IOException
EDBException
SemReasonerException
-
export
public void export(InterruptFlag interrupt, List<String> predicates, String resultdirectory) throws EDBException, SemReasonerException, IOException, InterruptedException bulk export of facts for predicates to raw files in result directory- Parameters:
interrupt
- , flag to interrupt exportpredicates
-resultdirectory
-- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, String resultpath, String module) throws EDBException, SemReasonerException, IOException, InterruptedException export of facts and rules for predicates to file in OO-logic into a module.
If there is already a module, this one is used.
If module is null, it is exported but not filled into a module.- Parameters:
interrupt
- , flag to interrupt exportresultpath
-module
- , module name- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, List<Filter> filter, String resultpath, String module) throws EDBException, SemReasonerException, IOException, InterruptedException export of facts and rules for predicates to file in OO-logic into a module.
If there is already a module, this one is used.
If module is null, it is exported but not filled into a module.- Parameters:
interrupt
- , flag to interrupt exportfilter
- , a list of filters for predicates to be exportedresultpath
-module
- , module name- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, Writer writer, String module) throws EDBException, SemReasonerException, IOException, InterruptedException export of facts and rules for predicates to file in OO-logic into a module.
If there is already a module, this one is used.
If module is null, it is exported but not filled into a module.- Parameters:
interrupt
- , flag to interrupt exportwriter
-- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, List<Filter> filters, Writer writer, String module) throws EDBException, SemReasonerException, IOException, InterruptedException export of facts and rules for predicates to file in OO-logic into a module.
If there is already a module, this one is used.
If module is null, it is exported but not filled into a module.- Parameters:
interrupt
- , flag to interrupt exportfilters
- , predicates together with filters to export.writer
-- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportNQuads
public void exportNQuads(Writer writer, String iri) throws EDBException, SemReasonerException, IOException, InterruptedException export of facts as N-Quads.- Parameters:
writer
-iri
-- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportNQuads
public void exportNQuads(String resultpath, String iri) throws EDBException, SemReasonerException, IOException, InterruptedException export of facts as N-Quads- Parameters:
resultpath
- , path of fileiri
- , iri used for the n-quads- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
exportRules
store all rules in file given by file path- Parameters:
filepath
-append
- , rules are appended to the file- Throws:
SemReasonerException
IOException
-
exportRules
store all rules in file given by file path- Parameters:
writer
- , writer to write rules to- Throws:
SemReasonerException
IOException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, Rule query, int maxNumberOfResults, ReasoningMonitor monitor) throws SemReasonerException, InterruptedException, IOException Pose a query. Get the results as an enumerator for tuples of objects- Parameters:
interruptFlag
- for interrupting the evaluationquery
- , the querymonitor
- , monitoring reasoning, may be nullmaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , reasoning monitor- Returns:
- an enumerator for results
- Throws:
ReasoningException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, Rule query, int maxNumberOfResults, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Pose a query. Get the results as an enumerator for tuples of objects- Parameters:
interruptFlag
- for interrupting the evaluationquery
- , the querymonitor
- , monitoring reasoning, may be nullmaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , reasoning monitorconfig
- , configurationbuiltinConfig
- , configurations for built-ins e.g. access tokens- Returns:
- an enumerator for results
- Throws:
ReasoningException
IOException
SemReasonerException
InterruptedException
-
applyChangeSet
public void applyChangeSet(List<String> paths) throws EDBException, SemReasonerException, IOException, InterruptedException Applies changes to the extensional database.
During this operation the to be modified predicates
are read locked. A write lock is used for a short time only at the end of the operation
The input files are raw files
For every predicate p two files may be given:
_add_p contains tuples to be added
_delete_p contains tuples to be deleted
if T(p) is the set of tuples for predicate p,
add(p) is the set of tuples to be added,
del(p) the set of tuples to be deleted
(T(p)-del(p)) + add(p) is computed- Parameters:
paths
- , paths of the input files- Throws:
EDBException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, List<Rule> queries, int maxNumberOfResults, ReasoningMonitor monitor) throws SemReasonerException, InterruptedException, IOException Pose a query and several rules- Parameters:
interruptFlag
- for interrupting the evaluationqueries
- , a query and rulesmaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , monitoring reasoning, may be null- Returns:
- an enumerator for results
- Throws:
ReasoningException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, List<Rule> queries, int maxNumberOfResults, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Pose a query and several rules- Parameters:
interruptFlag
- for interrupting the evaluationqueries
- , a query and rulesmaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , monitoring reasoning, may be nullconfig
- , configurationbuiltinConfig
- , built-in configuration like access tokens etc.- Returns:
- an enumerator for results
- Throws:
ReasoningException
IOException
SemReasonerException
InterruptedException
-
query
public ResultEnumerator query(InterruptFlag interruptFlag, List<Rule> queries, int maxNumberOfResults, ReasoningMonitor monitor, ExtensionalDB[] additionalEDBs, IntensionalDB[] additionalIDBs, boolean skipAnswers, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Pose a query and several rules.- Parameters:
interruptFlag
- for interrupting the evaluationqueries
- , list of queriesmaxNumberOfResults
- , the maximum number of result tuples, -1 for all resultsmonitor
- , monitoring reasoning, may be nulladditionalEDBs
- , additional edbs to be used during queryingadditionalIDBs
- , additional idbs to be used during queryingmonitor
- , reasoning monitorbuiltinConfig
- , configurations for built-ins e.g. access tokens- Returns:
- an enumerator for results
- Throws:
ReasoningException
IOException
SemReasonerException
InterruptedException
-
materializeQueries
public void materializeQueries(InterruptFlag interruptFlag, List<Rule> queries, ReasoningMonitor monitor) throws SemReasonerException, InterruptedException, IOException Materialize queries.
This means that the queries are evaluated and the results are stored in the database.- Parameters:
interruptFlag
-queries
- , the queries to be materializedmonitor
- , reasoning monitor- Throws:
ReasoningException
InterruptedException
IOException
SemReasonerException
-
materializeQueries
public void materializeQueries(InterruptFlag interruptFlag, List<Rule> queries, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Materialize queries.
This means that the queries are evaluated and the results are stored in the database.- Parameters:
interruptFlag
-queries
- , the queries to be materializedmonitor
- , reasoning monitorconfig
- , configurationbuiltinConfig
- , configurations for built-ins e.g. access tokens- Throws:
ReasoningException
InterruptedException
IOException
SemReasonerException
-
materializeQueries
public void materializeQueries(InterruptFlag interruptFlag, String squeries, ReasoningMonitor monitor) throws ReasoningException, InterruptedException, IOException, SemReasonerException Materialize queries.
This means that the queries are evaluated and the results are stored in the database.- Parameters:
interruptFlag
-squeries
- , the queries to be materializedmonitor
- , reasoning monitor- Throws:
ReasoningException
InterruptedException
IOException
SemReasonerException
-
materializeQueries
public void materializeQueries(InterruptFlag interruptFlag, String squeries, ReasoningMonitor monitor, Configuration config, Properties builtinConfig) throws SemReasonerException, InterruptedException, IOException Materialize queries.
This means that the queries are evaluated and the results are stored in the database.- Parameters:
interruptFlag
-squeries
- , the queries to be materializedmonitor
- , reasoning monitorconfig
- , configurationbuiltinConfig
- , built-in configuration like access tokens etc.- Throws:
ReasoningException
InterruptedException
SemReasonerException
IOException
-