Class SimpleReasoner
- java.lang.Object
-
- org.apache.jena.rdf.listeners.StatementListener
-
- edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner
-
- All Implemented Interfaces:
ChangeListener,org.apache.jena.rdf.model.ModelChangedListener
public class SimpleReasoner extends org.apache.jena.rdf.listeners.StatementListener implements org.apache.jena.rdf.model.ModelChangedListener, ChangeListener
Allows for real-time incremental materialization or retraction of RDFS- style class and property subsumption based ABox inferences as statements are added to or removed from the (ABox or TBox) knowledge base.- Author:
- sjm222
-
-
Constructor Summary
Constructors Constructor Description SimpleReasoner(org.apache.jena.ontology.OntModel tboxModel, RDFService rdfService, org.apache.jena.rdf.model.Model inferenceModel, org.apache.jena.rdf.model.Model inferenceRebuildModel, org.apache.jena.rdf.model.Model scratchpadModel, SearchIndexer searchIndexer)SimpleReasoner(org.apache.jena.ontology.OntModel tboxModel, org.apache.jena.ontology.OntModel aboxModel, org.apache.jena.rdf.model.Model inferenceModel)This constructor is used for the unit tests only
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddedInverseProperty(org.apache.jena.ontology.OntProperty prop1, org.apache.jena.ontology.OntProperty prop2, org.apache.jena.rdf.model.Model inferenceModel)If it is added that P is an inverse of Q, then: 1.voidaddedStatement(org.apache.jena.rdf.model.Statement stmt)protected voidaddedSubClass(org.apache.jena.ontology.OntClass subClass, org.apache.jena.ontology.OntClass superClass, org.apache.jena.rdf.model.Model inferenceModel)If it is added that B is a subClass of A, then for each individual that is typed as B, either in the ABox or in the inferred model, infer that it is of type A.voidaddedTBoxStatement(org.apache.jena.rdf.model.Statement stmt)Performs incremental ABox reasoning based on changes to the class hierarchy.voidaddInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel)Add an inference from the inference model Adds the inference to the inference model if it is not already in the inference model and not in the abox model.protected voidaddInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel, boolean handleSameAs)protected voidaddInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel, boolean handleSameAs, boolean checkRedundancy)protected voidchangedTBoxStatement(org.apache.jena.rdf.model.Statement stmt, boolean add)Performs incremental ABox reasoning based on changes to the class hierarchy.protected voiddoPlugins(ModelUpdate.Operation op, org.apache.jena.rdf.model.Statement stmt)protected booleanentailedStatement(org.apache.jena.rdf.model.Statement stmt)Returns true if the triple is entailed by inverse property reasoning or sameAs reasoning; otherwise returns false.protected booleanentailedType(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Resource cls)Returns true if it is entailed by class subsumption that subject is of type cls; otherwise returns false.protected booleanentailedType(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Resource cls, List<String> remainingTypeURIs)Returns true if it is entailed by class subsumption that subject is of type cls; otherwise returns false.protected org.apache.jena.rdf.model.ModelgenerateInverseInferences(org.apache.jena.ontology.OntProperty prop, org.apache.jena.ontology.OntProperty inverseProp)protected List<org.apache.jena.ontology.OntProperty>getInverseProperties(org.apache.jena.rdf.model.Statement stmt)Returns a list of properties that are inverses of the property in the given statement.protected List<org.apache.jena.rdf.model.Resource>getParents(org.apache.jena.rdf.model.Resource cls, org.apache.jena.ontology.OntModel tboxModel)List<ReasonerPlugin>getPluginList()protected List<String>getRemainingAssertedTypeURIs(org.apache.jena.rdf.model.Resource resource)booleangetSameAsEnabled()protected List<org.apache.jena.rdf.model.Resource>getSameIndividuals(org.apache.jena.rdf.model.Resource ind, org.apache.jena.rdf.model.Model inferenceModel)Get a list of individuals the same as the given individualprotected List<org.apache.jena.rdf.model.Resource>getSubClasses(org.apache.jena.rdf.model.Resource cls)protected List<org.apache.jena.rdf.model.Resource>getSuperClasses(org.apache.jena.rdf.model.Resource cls)booleanisABoxReasoningAsynchronous()Asynchronous reasoning mode (DeltaComputer) no longer used in the case of batch removals.protected booleanisInterestedInRemovedStatement(org.apache.jena.rdf.model.Statement stmt)booleanisRecomputing()Returns true if the reasoner is in the process of recomputing all inferences.voidnotifyEvent(String string, Object event)Override this to listen to events pertaining to the given graphURI.voidnotifyEvent(org.apache.jena.rdf.model.Model model, Object event)voidnotifyModelChange(ModelChange modelChange)Override this to listen to each model changevoidrecompute()protected voidremovedInverseProperty(org.apache.jena.ontology.OntProperty prop1, org.apache.jena.ontology.OntProperty prop2, org.apache.jena.rdf.model.Model inferenceModel)If it is removed that P is an inverse of Q, then: 1.voidremovedStatement(org.apache.jena.rdf.model.Statement stmt)protected voidremovedSubClass(org.apache.jena.ontology.OntClass subClass, org.apache.jena.ontology.OntClass superClass, org.apache.jena.rdf.model.Model inferenceModel)If removed that B is a subclass of A, then for each individual that is of type B, either inferred or in the ABox, remove the assertion that it is of type A from the inferred model, UNLESS the individual is of some type C that is a subClass of A (including A itself)voidremovedTBoxStatement(org.apache.jena.rdf.model.Statement stmt)Performs incremental ABox reasoning based on changes to the class hierarchy.voidremoveInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel)Remove an inference from the inference model Removes the inference if it is not entailed by the abox model and if the inference model contains it.protected voidremoveInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel, boolean handleSameAs, boolean checkEntailment)protected voidsetMostSpecificTypes(org.apache.jena.rdf.model.Resource individual, HashSet<String> typeURIs, org.apache.jena.rdf.model.Model inferenceModel)protected voidsetMostSpecificTypes(org.apache.jena.rdf.model.Resource individual, org.apache.jena.rdf.model.Model inferenceModel, HashSet<String> unknownTypes)Find the most specific types (classes) of an individual and infer them for the individual with the mostSpecificType annotation.voidsetPluginList(List<ReasonerPlugin> pluginList)voidsetSameAsEnabled(boolean tf)voidsetStopRequested()This is called when the application shuts down.static StringstmtString(org.apache.jena.rdf.model.Statement statement)Utility method for logging-
Methods inherited from class org.apache.jena.rdf.listeners.StatementListener
addedStatements, addedStatements, addedStatements, addedStatements, removedStatements, removedStatements, removedStatements, removedStatements
-
-
-
-
Constructor Detail
-
SimpleReasoner
public SimpleReasoner(org.apache.jena.ontology.OntModel tboxModel, RDFService rdfService, org.apache.jena.rdf.model.Model inferenceModel, org.apache.jena.rdf.model.Model inferenceRebuildModel, org.apache.jena.rdf.model.Model scratchpadModel, SearchIndexer searchIndexer)- Parameters:
tboxModel- - input. This model contains both asserted and inferred TBox axiomsrdfService- - input. An RDF ServiceinferenceModel- - output. This is the model in which inferred (materialized) ABox statements are maintained (added or retracted).inferenceRebuildModel- - output. This the model is temporarily used when the whole ABox inference model is rebuiltscratchpadModel- - output. This the model is temporarily used when the whole ABox inference model is rebuiltsearchIndexer- - output. If not null, the indexer will be paused before the ABox inference model is rebuilt and unpaused when the rebuild is complete.
-
SimpleReasoner
public SimpleReasoner(org.apache.jena.ontology.OntModel tboxModel, org.apache.jena.ontology.OntModel aboxModel, org.apache.jena.rdf.model.Model inferenceModel)This constructor is used for the unit tests only- Parameters:
tboxModel- - input. This model contains both asserted and inferred TBox axiomsaboxModel- - input. This model contains asserted ABox statementsinferenceModel- - output. This is the model in which inferred (materialized) ABox statements are maintained (added or retracted).
-
-
Method Detail
-
setPluginList
public void setPluginList(List<ReasonerPlugin> pluginList)
-
getPluginList
public List<ReasonerPlugin> getPluginList()
-
setSameAsEnabled
public void setSameAsEnabled(boolean tf)
-
getSameAsEnabled
public boolean getSameAsEnabled()
-
notifyModelChange
public void notifyModelChange(ModelChange modelChange)
Description copied from interface:ChangeListenerOverride this to listen to each model change- Specified by:
notifyModelChangein interfaceChangeListener- Parameters:
modelChange- - the object representing the model change
-
addedStatement
public void addedStatement(org.apache.jena.rdf.model.Statement stmt)
- Specified by:
addedStatementin interfaceorg.apache.jena.rdf.model.ModelChangedListener- Overrides:
addedStatementin classorg.apache.jena.rdf.listeners.StatementListener
-
removedStatement
public void removedStatement(org.apache.jena.rdf.model.Statement stmt)
- Specified by:
removedStatementin interfaceorg.apache.jena.rdf.model.ModelChangedListener- Overrides:
removedStatementin classorg.apache.jena.rdf.listeners.StatementListener
-
changedTBoxStatement
protected void changedTBoxStatement(org.apache.jena.rdf.model.Statement stmt, boolean add)Performs incremental ABox reasoning based on changes to the class hierarchy. addedTBoxStatement and removedTBoxStatement use the same tests so the are merged into this method. Handles rdfs:subclassOf, owl:equivalentClass, and owl:inverseOf
-
addedTBoxStatement
public void addedTBoxStatement(org.apache.jena.rdf.model.Statement stmt)
Performs incremental ABox reasoning based on changes to the class hierarchy. Handles rdfs:subclassOf, owl:equivalentClass, and owl:inverseOf
-
removedTBoxStatement
public void removedTBoxStatement(org.apache.jena.rdf.model.Statement stmt)
Performs incremental ABox reasoning based on changes to the class hierarchy. Handles rdfs:subclassOf, owl:equivalentClass, and owl:inverseOf
-
addedSubClass
protected void addedSubClass(org.apache.jena.ontology.OntClass subClass, org.apache.jena.ontology.OntClass superClass, org.apache.jena.rdf.model.Model inferenceModel)If it is added that B is a subClass of A, then for each individual that is typed as B, either in the ABox or in the inferred model, infer that it is of type A.
-
removedSubClass
protected void removedSubClass(org.apache.jena.ontology.OntClass subClass, org.apache.jena.ontology.OntClass superClass, org.apache.jena.rdf.model.Model inferenceModel)If removed that B is a subclass of A, then for each individual that is of type B, either inferred or in the ABox, remove the assertion that it is of type A from the inferred model, UNLESS the individual is of some type C that is a subClass of A (including A itself)
-
addedInverseProperty
protected void addedInverseProperty(org.apache.jena.ontology.OntProperty prop1, org.apache.jena.ontology.OntProperty prop2, org.apache.jena.rdf.model.Model inferenceModel)If it is added that P is an inverse of Q, then: 1. For each statement involving predicate P in the assertions model add the inverse statement to the inference model if that inverse is in the assertions model. 2. Repeat the same for predicate Q.
-
removedInverseProperty
protected void removedInverseProperty(org.apache.jena.ontology.OntProperty prop1, org.apache.jena.ontology.OntProperty prop2, org.apache.jena.rdf.model.Model inferenceModel)If it is removed that P is an inverse of Q, then: 1. For each statement involving predicate P in the abox assertions model remove the inverse statement from the inference model unless that statement is otherwise entailed. 2. Repeat the same for predicate Q.
-
getSameIndividuals
protected List<org.apache.jena.rdf.model.Resource> getSameIndividuals(org.apache.jena.rdf.model.Resource ind, org.apache.jena.rdf.model.Model inferenceModel)
Get a list of individuals the same as the given individual
-
entailedType
protected boolean entailedType(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Resource cls)Returns true if it is entailed by class subsumption that subject is of type cls; otherwise returns false.
-
entailedType
protected boolean entailedType(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Resource cls, List<String> remainingTypeURIs)Returns true if it is entailed by class subsumption that subject is of type cls; otherwise returns false. remainingTypeURIs is an optional list of asserted type URIs for the subject resource, and may be null. Supplying a precompiled list can yield performance improvement when this method is called repeatedly for the same subject.
-
getRemainingAssertedTypeURIs
protected List<String> getRemainingAssertedTypeURIs(org.apache.jena.rdf.model.Resource resource)
-
getSubClasses
protected List<org.apache.jena.rdf.model.Resource> getSubClasses(org.apache.jena.rdf.model.Resource cls)
-
getSuperClasses
protected List<org.apache.jena.rdf.model.Resource> getSuperClasses(org.apache.jena.rdf.model.Resource cls)
-
entailedStatement
protected boolean entailedStatement(org.apache.jena.rdf.model.Statement stmt)
Returns true if the triple is entailed by inverse property reasoning or sameAs reasoning; otherwise returns false.
-
getInverseProperties
protected List<org.apache.jena.ontology.OntProperty> getInverseProperties(org.apache.jena.rdf.model.Statement stmt)
Returns a list of properties that are inverses of the property in the given statement.
-
generateInverseInferences
protected org.apache.jena.rdf.model.Model generateInverseInferences(org.apache.jena.ontology.OntProperty prop, org.apache.jena.ontology.OntProperty inverseProp)
-
addInference
public void addInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel)Add an inference from the inference model Adds the inference to the inference model if it is not already in the inference model and not in the abox model.
-
addInference
protected void addInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel, boolean handleSameAs)
-
addInference
protected void addInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel, boolean handleSameAs, boolean checkRedundancy)
-
removeInference
public void removeInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel)Remove an inference from the inference model Removes the inference if it is not entailed by the abox model and if the inference model contains it. Removes the corresponding inference for each same individual if that inference is not entailed by the abox model.
-
removeInference
protected void removeInference(org.apache.jena.rdf.model.Statement infStmt, org.apache.jena.rdf.model.Model inferenceModel, boolean handleSameAs, boolean checkEntailment)
-
setMostSpecificTypes
protected void setMostSpecificTypes(org.apache.jena.rdf.model.Resource individual, org.apache.jena.rdf.model.Model inferenceModel, HashSet<String> unknownTypes)Find the most specific types (classes) of an individual and infer them for the individual with the mostSpecificType annotation.
-
setMostSpecificTypes
protected void setMostSpecificTypes(org.apache.jena.rdf.model.Resource individual, HashSet<String> typeURIs, org.apache.jena.rdf.model.Model inferenceModel)
-
getParents
protected List<org.apache.jena.rdf.model.Resource> getParents(org.apache.jena.rdf.model.Resource cls, org.apache.jena.ontology.OntModel tboxModel)
-
isInterestedInRemovedStatement
protected boolean isInterestedInRemovedStatement(org.apache.jena.rdf.model.Statement stmt)
-
doPlugins
protected void doPlugins(ModelUpdate.Operation op, org.apache.jena.rdf.model.Statement stmt)
-
isRecomputing
public boolean isRecomputing()
Returns true if the reasoner is in the process of recomputing all inferences.
-
recompute
public void recompute()
-
setStopRequested
public void setStopRequested()
This is called when the application shuts down.
-
isABoxReasoningAsynchronous
public boolean isABoxReasoningAsynchronous()
Asynchronous reasoning mode (DeltaComputer) no longer used in the case of batch removals.
-
notifyEvent
public void notifyEvent(String string, Object event)
Description copied from interface:ChangeListenerOverride this to listen to events pertaining to the given graphURI.- Specified by:
notifyEventin interfaceChangeListener- Parameters:
string- - the graph to which the event pertainsevent- - the event that occurred.
-
notifyEvent
public void notifyEvent(org.apache.jena.rdf.model.Model model, Object event)- Specified by:
notifyEventin interfaceorg.apache.jena.rdf.model.ModelChangedListener- Overrides:
notifyEventin classorg.apache.jena.rdf.listeners.StatementListener
-
stmtString
public static String stmtString(org.apache.jena.rdf.model.Statement statement)
Utility method for logging
-
-