sameAs support in plugins
This commit is contained in:
parent
7ed15e82b4
commit
121acbc17b
2 changed files with 34 additions and 19 deletions
|
@ -19,6 +19,7 @@ import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handles rules of the form
|
* handles rules of the form
|
||||||
|
@ -34,6 +35,7 @@ public abstract class SimpleBridgingRule implements ReasonerPlugin {
|
||||||
private Property assertedProp1;
|
private Property assertedProp1;
|
||||||
private Property assertedProp2;
|
private Property assertedProp2;
|
||||||
private String queryStr;
|
private String queryStr;
|
||||||
|
private SimpleReasoner simpleReasoner;
|
||||||
|
|
||||||
protected SimpleBridgingRule(String assertedProp1, String assertedProp2, String inferredProp) {
|
protected SimpleBridgingRule(String assertedProp1, String assertedProp2, String inferredProp) {
|
||||||
this.assertedProp1 = ResourceFactory.createProperty(assertedProp1);
|
this.assertedProp1 = ResourceFactory.createProperty(assertedProp1);
|
||||||
|
@ -66,7 +68,7 @@ public abstract class SimpleBridgingRule implements ReasonerPlugin {
|
||||||
StmtIterator sit = inf.listStatements();
|
StmtIterator sit = inf.listStatements();
|
||||||
while(sit.hasNext()) {
|
while(sit.hasNext()) {
|
||||||
Statement s = sit.nextStatement();
|
Statement s = sit.nextStatement();
|
||||||
tryToInfer(s, aboxAssertionsModel, aboxInferencesModel);
|
if (simpleReasoner != null) simpleReasoner.addInference(s,aboxInferencesModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,16 +108,6 @@ public abstract class SimpleBridgingRule implements ReasonerPlugin {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToInfer(Statement s,
|
|
||||||
Model aboxAssertionsModel,
|
|
||||||
Model aboxInferencesModel) {
|
|
||||||
// this should be part of a superclass or some class that provides
|
|
||||||
// reasoning framework functions
|
|
||||||
if (!aboxAssertionsModel.contains(s) && !aboxInferencesModel.contains(s)) {
|
|
||||||
aboxInferencesModel.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removedABoxStatement(Statement stmt,
|
public void removedABoxStatement(Statement stmt,
|
||||||
Model aboxAssertionsModel,
|
Model aboxAssertionsModel,
|
||||||
Model aboxInferencesModel,
|
Model aboxInferencesModel,
|
||||||
|
@ -131,6 +123,13 @@ public abstract class SimpleBridgingRule implements ReasonerPlugin {
|
||||||
Model m = ModelFactory.createDefaultModel();
|
Model m = ModelFactory.createDefaultModel();
|
||||||
m.add(stmt);
|
m.add(stmt);
|
||||||
Model union = ModelFactory.createUnion(m, aboxAssertionsModel);
|
Model union = ModelFactory.createUnion(m, aboxAssertionsModel);
|
||||||
|
Model inf = constructInferences(stmt, union);
|
||||||
|
StmtIterator sit = inf.listStatements();
|
||||||
|
while(sit.hasNext()) {
|
||||||
|
Statement s = sit.nextStatement();
|
||||||
|
if (simpleReasoner != null) simpleReasoner.removeInference(s,aboxInferencesModel);
|
||||||
|
}
|
||||||
|
|
||||||
aboxInferencesModel.remove(constructInferences(stmt, union));
|
aboxInferencesModel.remove(constructInferences(stmt, union));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +137,13 @@ public abstract class SimpleBridgingRule implements ReasonerPlugin {
|
||||||
return (assertedProp1.equals(stmt.getPredicate())
|
return (assertedProp1.equals(stmt.getPredicate())
|
||||||
|| assertedProp2.equals(stmt.getPredicate()));
|
|| assertedProp2.equals(stmt.getPredicate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSimpleReasoner(SimpleReasoner simpleReasoner) {
|
||||||
|
this.simpleReasoner = simpleReasoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleReasoner getSimpleReasoner() {
|
||||||
|
return this.simpleReasoner;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handles rules of the form
|
* handles rules of the form
|
||||||
|
@ -27,6 +28,7 @@ public abstract class SimplePropertyAndTypeRule implements ReasonerPlugin {
|
||||||
private Property ASSERTED_PROP;
|
private Property ASSERTED_PROP;
|
||||||
private Resource TYPE;
|
private Resource TYPE;
|
||||||
private Property INFERRED_PROP;
|
private Property INFERRED_PROP;
|
||||||
|
private SimpleReasoner simpleReasoner;
|
||||||
|
|
||||||
protected SimplePropertyAndTypeRule(String assertedProp, String type, String inferredProp) {
|
protected SimplePropertyAndTypeRule(String assertedProp, String type, String inferredProp) {
|
||||||
TYPE = ResourceFactory.createResource(type);
|
TYPE = ResourceFactory.createResource(type);
|
||||||
|
@ -82,8 +84,8 @@ public abstract class SimplePropertyAndTypeRule implements ReasonerPlugin {
|
||||||
// this should be part of a superclass or some class that provides
|
// this should be part of a superclass or some class that provides
|
||||||
// reasoning framework functions
|
// reasoning framework functions
|
||||||
Statement s = ResourceFactory.createStatement(subject, predicate, object);
|
Statement s = ResourceFactory.createStatement(subject, predicate, object);
|
||||||
if (!aboxAssertionsModel.contains(s) && !aboxInferencesModel.contains(s)) {
|
if (simpleReasoner != null) {
|
||||||
aboxInferencesModel.add(s);
|
simpleReasoner.addInference(s,aboxInferencesModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +99,9 @@ public abstract class SimplePropertyAndTypeRule implements ReasonerPlugin {
|
||||||
// stmt.getSubject(), RDF.type, BIBO_DOCUMENT)
|
// stmt.getSubject(), RDF.type, BIBO_DOCUMENT)
|
||||||
// || aboxInferencesModel.contains(
|
// || aboxInferencesModel.contains(
|
||||||
// stmt.getSubject(), RDF.type, BIBO_DOCUMENT)) {
|
// stmt.getSubject(), RDF.type, BIBO_DOCUMENT)) {
|
||||||
aboxInferencesModel.remove(
|
if (simpleReasoner != null) {
|
||||||
stmt.getSubject(), INFERRED_PROP, stmt.getObject());
|
simpleReasoner.removeInference(ResourceFactory.createStatement(stmt.getSubject(), INFERRED_PROP, stmt.getObject()), aboxInferencesModel);
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
} else if (isRelevantType(stmt, TBoxInferencesModel)) {
|
} else if (isRelevantType(stmt, TBoxInferencesModel)) {
|
||||||
if(!aboxInferencesModel.contains(
|
if(!aboxInferencesModel.contains(
|
||||||
|
@ -107,8 +110,7 @@ public abstract class SimplePropertyAndTypeRule implements ReasonerPlugin {
|
||||||
stmt.getSubject(), ASSERTED_PROP, (RDFNode) null);
|
stmt.getSubject(), ASSERTED_PROP, (RDFNode) null);
|
||||||
while (groundIt.hasNext()) {
|
while (groundIt.hasNext()) {
|
||||||
Statement groundStmt = groundIt.nextStatement();
|
Statement groundStmt = groundIt.nextStatement();
|
||||||
aboxInferencesModel.remove(
|
simpleReasoner.removeInference(ResourceFactory.createStatement(groundStmt.getSubject(), INFERRED_PROP, groundStmt.getObject()), aboxInferencesModel);
|
||||||
groundStmt.getSubject(), INFERRED_PROP, groundStmt.getObject());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,5 +126,12 @@ public abstract class SimplePropertyAndTypeRule implements ReasonerPlugin {
|
||||||
private boolean isRelevantPredicate(Statement stmt) {
|
private boolean isRelevantPredicate(Statement stmt) {
|
||||||
return (ASSERTED_PROP.equals(stmt.getPredicate()));
|
return (ASSERTED_PROP.equals(stmt.getPredicate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSimpleReasoner(SimpleReasoner simpleReasoner) {
|
||||||
|
this.simpleReasoner = simpleReasoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleReasoner getSimpleReasoner() {
|
||||||
|
return this.simpleReasoner;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue