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 TypeMethodDescriptionboolean
addAllRules
(Collection<Rule> rules) Add a whole collection of rules.boolean
Add a query which is a rule without head.boolean
Add a rule.boolean
Add rulesint
bottomUpConnectedRule
(Rule rule) returns the number of rules connected bottom up to rulevoid
clear()
remove all rulesboolean
containsRule
(String identifier) does intensional database contain a rule with that identifier?void
createAxioms
(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) create the relevant axiomsvoid
Create dense rule graph for topological numbering of rules and literals.void
createRuleGraph
(SymbolTable symboltable) Creates a rule graph.void
Create strong components of rule graph.void
exportRules
(Writer out, SymbolTable symbolTable) export all rulesvoid
exportRules
(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.int
get 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 rulesint
return the identifier of the strong component of Lboolean
get the rule graphboolean
isEmpty()
are there any rules or queries?boolean
is the (body) literal involved in a recursion?iterator()
iterator for all rulesvoid
lastModification
(long time) set the time of last modificationlong
time of last modificationvoid
loadRuleFiles
(List<String> files, SymbolTable symbolTable, ExternalDataTypeProvider datatypes, BuiltinProvider builtins) load rules from fileboolean
removeAllRules
(Collection<Rule> rules) Remove a whole collection of rules.void
removeAxioms
(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) remove the relevant axiomsboolean
removeQuery
(Rule query) remove a query either by its unique id or by the query textboolean
removeRule
(Rule rule) remove a rule either by the same id or by the same rule textremoverulebyid
(String rid) boolean
removeRuleById
(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 rulesint
size()
returns the number of rules and queriesboolean
stratifyRules
(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, wait
Methods 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:
SemReasonerException
IOException
-
addRules
Add rules- Parameters:
rules
- to be added- Returns:
- true if all rules have been added
- Throws:
SemReasonerException
IOException
-
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:
SemReasonerException
IOException
-
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:
IOException
SemReasonerException
-
removeAxioms
public void removeAxioms(SymbolTable symbols, ExternalDataTypeProvider datatypes, Configuration config) throws IOException, SemReasonerException remove the relevant axioms- Parameters:
symbols
-datatypes
-config
-- Throws:
IOException
SemReasonerException
-
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:
SemReasonerException
IOException
-
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:
IOException
SemReasonerException
-
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:
SemReasonerException
IOException
-
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:
IOException
SemReasonerException
-
ruleToString
return an OO-Logic representation of the rule- Parameters:
r
-symbols
-- Returns:
- Throws:
IOException
SemReasonerException
-
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:
IOException
SemReasonerException
-
exportRules
public void exportRules(Writer out, SymbolTable symbolTable) throws IOException, SemReasonerException export all rules- Parameters:
out
-symbolTable
-- Throws:
IOException
SemReasonerException
-
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:
IOException
SimpleParseException
SemReasonerException
-
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
-