Class IntensionalDB

java.lang.Object
com.semedy.reasoner.api.idb.IntensionalDB
All Implemented Interfaces:
Iterable<Rule>

public class IntensionalDB extends Object implements Iterable<Rule>
Container for rules. It also maintains a rule graph.
  • Constructor Details

    • IntensionalDB

      public IntensionalDB(Collection<Rule> rules)
    • 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

      public Iterator<Rule> iterator()
      iterator for all rules
      Specified by:
      iterator in interface Iterable<Rule>
    • getRules

      public List<Rule> getRules()
      returns a list of all rules
      Returns:
      list of all rules
    • getQueries

      public List<Rule> getQueries()
      return all queries
      Returns:
      all queries
    • clear

      public void clear()
      remove all rules
    • containsRule

      public boolean containsRule(String identifier)
      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

      public boolean addRule(Rule rule) throws IOException, SemReasonerException
      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

      public boolean addRules(List<Rule> rules) throws IOException, SemReasonerException
      Add rules
      Parameters:
      rules - to be added
      Returns:
      true if all rules have been added
      Throws:
      SemReasonerException
      IOException
    • addAllRules

      public boolean addAllRules(Collection<Rule> rules) throws IOException, SemReasonerException
      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

      public boolean removeAllRules(Collection<Rule> rules) throws IDBException
      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

      public boolean removeRuleById(String rid)
      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

      public List<Rule> removerulebyid(String rid)
    • 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

      public boolean removeRule(Rule rule)
      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

      public boolean addQuery(Rule query) throws IOException, SemReasonerException
      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

      public boolean removeQuery(Rule query)
      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

      public List<Rule> getRuleById(String rid)
      retrieve a rule by its unique id
      Parameters:
      rid - of rule to be retrieved
      Returns:
      rule to given id
    • createRuleGraph

      public void createRuleGraph(SymbolTable symboltable) throws IOException, SemReasonerException
      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

      public Integer getRuleNumber(String ruleIdentifier)
      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

      public Integer getLiteralNumber(int uniqueIdentifier)
      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

      public List<Rule> feedingRules(Literal body)
      delivers a list of all rules feeding into body
      Parameters:
      body - body into which result feeds
      Returns:
      rules which feed into body
    • bottomUpConnectedRule

      public int bottomUpConnectedRule(Rule rule)
      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 rules
      builtins - 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

      public int getStrongComponentsIdentifier(Literal L)
      return the identifier of the strong component of L
      Parameters:
      L - literal L
      Returns:
      identifier for the strong component of L
    • isRecursive

      public boolean isRecursive(Literal L)
      is the (body) literal involved in a recursion?
      Parameters:
      L - literal L
      Returns:
      is literal L involved in a recursion
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(SymbolTable symbols) throws IOException, SemReasonerException
      Throws:
      IOException
      SemReasonerException
    • ruleToString

      public String ruleToString(Rule r, SymbolTable symbols) throws IOException, SemReasonerException
      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 file
      symbolTable -
      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 loaded
      symbolTable - symboltable
      datatypes - datatypes
      Throws:
      IOException
      SimpleParseException
      SemReasonerException
    • getMaxStratum

      public int getMaxStratum()
      get the maximum stratum of the rule set
      Returns:
      the max stratum
    • stratifyRules

      public boolean stratifyRules(BuiltinProvider builtins)
      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