Package com.semedy.reasoner.api.idb
Class IntensionalDB
java.lang.Object
com.semedy.reasoner.api.idb.IntensionalDB
Container for rules. It also maintains a rule graph.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAllRules(Collection<Rule> rules) Add a whole collection of rules.booleanAdd a query which is a rule without head.booleanAdd a rule.booleanAdd rulesintbottomUpConnectedRule(Rule rule) returns the number of rules connected bottom up to rulevoidclear()remove all rulesbooleancontainsRule(String identifier) does intensional database contain a rule with that identifier?voidcreateAxioms(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) create the relevant axiomsvoidCreate dense rule graph for topological numbering of rules and literals.voidcreateRuleGraph(SymbolTable symboltable) Creates a rule graph.voidCreate strong components of rule graph.voidexportRules(Writer out, SymbolTable symbolTable) export all rulesvoidexportRules(String filepath, boolean append, SymbolTable symbolTable) store all rules in file given by file pathfeedingRules(Literal body) delivers a list of all rules feeding into bodygetLiteralNumber(int uniqueIdentifier) Returns topographic number of literal with unique identifier.intget the maximum stratum of the rule setreturn all queriesgetRuleById(String rid) retrieve a rule by its unique idgetRuleNumber(String ruleIdentifier) Returns topographic number of rule.getRules()returns a list of all rulesintreturn the identifier of the strong component of Lbooleanget the rule graphbooleanisEmpty()are there any rules or queries?booleanis the (body) literal involved in a recursion?iterator()iterator for all rulesvoidlastModification(long time) set the time of last modificationlongtime of last modificationvoidloadRuleFiles(List<String> files, SymbolTable symbolTable, ExternalDataTypeProvider datatypes, BuiltinProvider builtins) load rules from filebooleanremoveAllRules(Collection<Rule> rules) Remove a whole collection of rules.voidremoveAxioms(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) remove the relevant axiomsbooleanremoveQuery(Rule query) remove a query either by its unique id or by the query textbooleanremoveRule(Rule rule) remove a rule either by the same id or by the same rule textremoverulebyid(String rid) booleanremoveRuleById(String rid) remove a rule given by its unique idruleToString(Rule r, SymbolTable symbols) return an OO-Logic representation of the ruleselectRules(List<Rule> rules, BuiltinProvider builtins) select all rules transitively feeding into rulesintsize()returns the number of rules and queriesbooleanstratifyRules(BuiltinProvider builtins) stratify the rule set, i.e. assign to each rule a stratumtoString()toString(SymbolTable symbols) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
IntensionalDB
-
IntensionalDB
public IntensionalDB()
-
-
Method Details
-
lastModificationTime
public long lastModificationTime()time of last modification- Returns:
- time
-
hasRuleGraph
public boolean hasRuleGraph()get the rule graph- Returns:
-
lastModification
public void lastModification(long time) set the time of last modification- Parameters:
time- , time of last modification of idb
-
isEmpty
public boolean isEmpty()are there any rules or queries?- Returns:
- true if there are rules
-
iterator
iterator for all rules -
getRules
returns a list of all rules- Returns:
- list of all rules
-
getQueries
return all queries- Returns:
- all queries
-
clear
public void clear()remove all rules -
containsRule
does intensional database contain a rule with that identifier?- Parameters:
identifier-- Returns:
-
size
public int size()returns the number of rules and queries- Returns:
- the number of rules plus the number of queries
-
addRule
Add a rule. A rule must have a unique identifier.- Parameters:
rule- to be added- Returns:
- true if rule has been added
- Throws:
SemReasonerExceptionIOException
-
addRules
Add rules- Parameters:
rules- to be added- Returns:
- true if all rules have been added
- Throws:
SemReasonerExceptionIOException
-
addAllRules
Add a whole collection of rules.
Returns true if all have been added- Parameters:
rules- to be added- Returns:
- true if all rules have been added
- Throws:
SemReasonerExceptionIOException
-
removeAllRules
Remove a whole collection of rules.
Returns true if all have been removed- Parameters:
rules- to be removed- Returns:
- true if all rules have been removed
- Throws:
IDBException
-
removeRuleById
remove a rule given by its unique id- Parameters:
rid- , rule id of rule to be removed- Returns:
- true if rule has been removed
-
removerulebyid
-
createAxioms
public void createAxioms(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) throws IOException, SemReasonerException create the relevant axioms- Parameters:
symbols-datatypes-config-- Throws:
IOExceptionSemReasonerException
-
removeAxioms
public void removeAxioms(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) throws IOException, SemReasonerException remove the relevant axioms- Parameters:
symbols-datatypes-config-- Throws:
IOExceptionSemReasonerException
-
removeRule
remove a rule either by the same id or by the same rule text- Parameters:
rule- to be removed- Returns:
- true if rule has been removed
-
addQuery
Add a query which is a rule without head.
In addition it is also added to the set of rules.
A query must have a unique identifier with respect to all rules and queries- Parameters:
query- to be added- Returns:
- true if query has been added
- Throws:
SemReasonerExceptionIOException
-
removeQuery
remove a query either by its unique id or by the query text- Parameters:
query- to be removed- Returns:
- true if query has been removed
-
getRuleById
retrieve a rule by its unique id- Parameters:
rid- of rule to be retrieved- Returns:
- rule to given id
-
createRuleGraph
Creates a rule graph. This is the precondition for the methods nextRules,
nextBodies, feedingRules, literalToRule, selectRules- Parameters:
symboltable- for which rule graph is created- Throws:
IOExceptionSemReasonerException
-
createDenseRuleGraph
public void createDenseRuleGraph()Create dense rule graph for topological numbering of rules and literals.
CreateRuleGraph must be called first -
getRuleNumber
Returns topographic number of rule.
CreateDenseRuleGraph must be called before.
Returns null if rule cannot be found.
Numbering is not dense.- Parameters:
ruleIdentifier-- Returns:
-
getLiteralNumber
Returns topographic number of literal with unique identifier.
CreateDenseRuleGraph must be called before.
Returns null if literal cannot be found.
Numbering is not dense.- Parameters:
uniqueIdentifier- , every literal has a unique identifier- Returns:
-
feedingRules
delivers a list of all rules feeding into body- Parameters:
body- body into which result feeds- Returns:
- rules which feed into body
-
bottomUpConnectedRule
returns the number of rules connected bottom up to rule- Parameters:
rule- rule- Returns:
- number of rules connected bottom up to input rule
-
selectRules
public IntensionalDB selectRules(List<Rule> rules, BuiltinProvider builtins) throws IOException, SemReasonerException select all rules transitively feeding into rules- Parameters:
rules- input rulesbuiltins- the built-ins- Returns:
- selected idb containing all rules which feed (finally) into input rules
- Throws:
SemReasonerExceptionIOException
-
createStrongComponents
public void createStrongComponents()Create strong components of rule graph.
Rule graph must be generated first -
getStrongComponentsIdentifier
return the identifier of the strong component of L- Parameters:
L- literal L- Returns:
- identifier for the strong component of L
-
isRecursive
is the (body) literal involved in a recursion?- Parameters:
L- literal L- Returns:
- is literal L involved in a recursion
-
toString
-
toString
- Throws:
IOExceptionSemReasonerException
-
ruleToString
return an OO-Logic representation of the rule- Parameters:
r-symbols-- Returns:
- Throws:
IOExceptionSemReasonerException
-
exportRules
public void exportRules(String filepath, boolean append, SymbolTable symbolTable) throws IOException, SemReasonerException store all rules in file given by file path- Parameters:
filepath-append- , rules are appended to the filesymbolTable-- Throws:
IOExceptionSemReasonerException
-
exportRules
public void exportRules(Writer out, SymbolTable symbolTable) throws IOException, SemReasonerException export all rules- Parameters:
out-symbolTable-- Throws:
IOExceptionSemReasonerException
-
loadRuleFiles
public void loadRuleFiles(List<String> files, SymbolTable symbolTable, ExternalDataTypeProvider datatypes, BuiltinProvider builtins) throws IOException, SemReasonerException load rules from file- Parameters:
files- files to be loadedsymbolTable- symboltabledatatypes- datatypes- Throws:
IOExceptionSimpleParseExceptionSemReasonerException
-
getMaxStratum
public int getMaxStratum()get the maximum stratum of the rule set- Returns:
- the max stratum
-
stratifyRules
stratify the rule set, i.e. assign to each rule a stratum- Parameters:
builtins- , the built-ins- Returns:
- true if rule set has been stratified successfully
-