Remove last use of graph wrapper from reinferencer
This commit is contained in:
parent
25874449dd
commit
a5084a614c
1 changed files with 52 additions and 24 deletions
|
@ -17,6 +17,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -41,13 +42,11 @@ 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.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer;
|
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
|
||||||
|
|
||||||
public class ABoxRecomputer {
|
public class ABoxRecomputer {
|
||||||
|
|
||||||
|
@ -516,30 +515,59 @@ public class ABoxRecomputer {
|
||||||
return sameAsInds;
|
return sameAsInds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getSameAsIndividuals(String individualURI, Set<String> sameAsInds) {
|
private void getSameAsIndividuals(String individualUri, final Set<String> sameAsInds) {
|
||||||
Model m = RDFServiceGraph.createRDFServiceModel(new RDFServiceGraph(rdfService));
|
try {
|
||||||
Resource individual = ResourceFactory.createResource(individualURI);
|
final List<String> addedURIs = new ArrayList<String>();
|
||||||
StmtIterator sit = m.listStatements(individual, OWL.sameAs, (RDFNode) null);
|
StringBuilder builder = new StringBuilder();
|
||||||
while(sit.hasNext()) {
|
|
||||||
Statement stmt = sit.nextStatement();
|
builder.append("SELECT\n")
|
||||||
if (stmt.getObject().isURIResource()) {
|
.append(" ?object\n")
|
||||||
String sameAsURI = stmt.getObject().asResource().getURI();
|
.append("WHERE\n")
|
||||||
if (!sameAsInds.contains(sameAsURI)) {
|
.append("{\n")
|
||||||
sameAsInds.add(sameAsURI);
|
.append(" <" + individualUri + "> <" + OWL.sameAs + "> ?object .\n")
|
||||||
getSameAsIndividuals(sameAsURI, sameAsInds);
|
.append("}\n");
|
||||||
|
|
||||||
|
rdfService.sparqlSelectQuery(builder.toString(), new ResultSetConsumer() {
|
||||||
|
@Override
|
||||||
|
protected void processQuerySolution(QuerySolution qs) {
|
||||||
|
Resource object = qs.getResource("object");
|
||||||
|
if (object != null && !sameAsInds.contains(object.getURI())) {
|
||||||
|
sameAsInds.add(object.getURI());
|
||||||
|
addedURIs.add(object.getURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (String indUri : addedURIs) {
|
||||||
|
getSameAsIndividuals(indUri, sameAsInds);
|
||||||
}
|
}
|
||||||
sit = m.listStatements(null, OWL.sameAs, individual);
|
|
||||||
while(sit.hasNext()) {
|
addedURIs.clear();
|
||||||
Statement stmt = sit.nextStatement();
|
builder = new StringBuilder();
|
||||||
if (stmt.getSubject().isURIResource()) {
|
|
||||||
String sameAsURI = stmt.getSubject().asResource().getURI();
|
builder.append("SELECT\n")
|
||||||
if (!sameAsInds.contains(sameAsURI)) {
|
.append(" ?subject\n")
|
||||||
sameAsInds.add(sameAsURI);
|
.append("WHERE\n")
|
||||||
getSameAsIndividuals(sameAsURI, sameAsInds);
|
.append("{\n")
|
||||||
|
.append(" ?subject <" + OWL.sameAs + "> <" + individualUri + "> .\n")
|
||||||
|
.append("}\n");
|
||||||
|
|
||||||
|
rdfService.sparqlSelectQuery(builder.toString(), new ResultSetConsumer() {
|
||||||
|
@Override
|
||||||
|
protected void processQuerySolution(QuerySolution qs) {
|
||||||
|
Resource object = qs.getResource("subject");
|
||||||
|
if (object != null && !sameAsInds.contains(object.getURI())) {
|
||||||
|
sameAsInds.add(object.getURI());
|
||||||
|
addedURIs.add(object.getURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (String indUri : addedURIs) {
|
||||||
|
getSameAsIndividuals(indUri, sameAsInds);
|
||||||
|
}
|
||||||
|
} catch (RDFServiceException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue