Sparql query improvments.
This commit is contained in:
parent
297805e5bc
commit
6e7afb976d
1 changed files with 30 additions and 59 deletions
|
@ -26,6 +26,7 @@ import com.hp.hpl.jena.ontology.OntResource;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.query.ResultSetFormatter;
|
import com.hp.hpl.jena.query.ResultSetFormatter;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
@ -652,15 +653,14 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
try {
|
try {
|
||||||
if (webappDaoFactory.getJenaBaseDao().PRIMARY_LINK != null) {
|
if (webappDaoFactory.getJenaBaseDao().PRIMARY_LINK != null) {
|
||||||
String listPropertyValues =
|
String listPropertyValues =
|
||||||
"CONSTRUCT {<" + this.individualURI + "> <" + webappDaoFactory.getJenaBaseDao().PRIMARY_LINK + "> ?values}" +
|
"SELECT ?values" +
|
||||||
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + webappDaoFactory.getJenaBaseDao().PRIMARY_LINK + "> ?values} }";
|
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + webappDaoFactory.getJenaBaseDao().PRIMARY_LINK + "> ?values} }";
|
||||||
tempModel = QueryExecutionFactory.create(QueryFactory.create(listPropertyValues), dataset).execConstruct();
|
ResultSet links = QueryExecutionFactory.create(QueryFactory.create(listPropertyValues), dataset).execSelect();
|
||||||
ontModel.add(tempModel.listStatements());
|
QuerySolution result = null;
|
||||||
OntResource res = ontModel.createOntResource(this.individualURI);
|
|
||||||
Iterator links = res.listPropertyValues(webappDaoFactory.getJenaBaseDao().PRIMARY_LINK);
|
|
||||||
if (links.hasNext()) {
|
if (links.hasNext()) {
|
||||||
|
result = links.next();
|
||||||
try {
|
try {
|
||||||
com.hp.hpl.jena.ontology.Individual linkInd = ((com.hp.hpl.jena.ontology.Individual)((Resource)links.next()).as(com.hp.hpl.jena.ontology.Individual.class));
|
com.hp.hpl.jena.ontology.Individual linkInd = ((com.hp.hpl.jena.ontology.Individual)((Resource)result.get("values")).as(com.hp.hpl.jena.ontology.Individual.class));
|
||||||
if (webappDaoFactory.getJenaBaseDao().LINK_ANCHOR != null) {
|
if (webappDaoFactory.getJenaBaseDao().LINK_ANCHOR != null) {
|
||||||
try {
|
try {
|
||||||
Literal l = (Literal) linkInd.getPropertyValue(webappDaoFactory.getJenaBaseDao().LINK_ANCHOR);
|
Literal l = (Literal) linkInd.getPropertyValue(webappDaoFactory.getJenaBaseDao().LINK_ANCHOR);
|
||||||
|
@ -814,26 +814,21 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
List<Individual> relatedIndividuals = new ArrayList<Individual>();
|
List<Individual> relatedIndividuals = new ArrayList<Individual>();
|
||||||
|
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
Model tempModel = ModelFactory.createDefaultModel();
|
|
||||||
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
try {
|
try {
|
||||||
String valuesOfProperty =
|
String valuesOfProperty =
|
||||||
"CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" +
|
"SELECT ?object" +
|
||||||
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }";
|
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }";
|
||||||
tempModel = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execConstruct();
|
ResultSet values = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execSelect();
|
||||||
ontModel.add(tempModel.listStatements());
|
QuerySolution result = null;
|
||||||
OntResource ontRes = ontModel.createOntResource(this.individualURI);
|
|
||||||
NodeIterator values = ontRes.listPropertyValues(ontRes.getModel().getProperty(propertyURI));
|
|
||||||
while (values.hasNext()) {
|
while (values.hasNext()) {
|
||||||
RDFNode value = values.nextNode();
|
result = values.next();
|
||||||
|
RDFNode value = result.get("object");
|
||||||
if (value.canAs(OntResource.class)) {
|
if (value.canAs(OntResource.class)) {
|
||||||
relatedIndividuals.add(
|
relatedIndividuals.add(
|
||||||
new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dataset, webappDaoFactory) );
|
new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dataset, webappDaoFactory) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tempModel.close();
|
|
||||||
ontModel.close();
|
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
return relatedIndividuals;
|
return relatedIndividuals;
|
||||||
|
@ -846,24 +841,19 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
}
|
}
|
||||||
|
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
Model tempModel = ModelFactory.createDefaultModel();
|
|
||||||
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
try {
|
try {
|
||||||
String valueOfProperty =
|
String valueOfProperty =
|
||||||
"CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" +
|
"SELECT ?object" +
|
||||||
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }";
|
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }";
|
||||||
tempModel = QueryExecutionFactory.create(QueryFactory.create(valueOfProperty), dataset).execConstruct();
|
ResultSet results = QueryExecutionFactory.create(QueryFactory.create(valueOfProperty), dataset).execSelect();
|
||||||
ontModel.add(tempModel.listStatements());
|
QuerySolution result = results.next();
|
||||||
OntResource ontRes = ontModel.createOntResource(this.individualURI);
|
RDFNode value = result.get("object");
|
||||||
RDFNode value = ontRes.getPropertyValue(ontRes.getModel().getProperty(propertyURI));
|
|
||||||
if (value != null && value.canAs(OntResource.class)) {
|
if (value != null && value.canAs(OntResource.class)) {
|
||||||
return new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dataset, webappDaoFactory);
|
return new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dataset, webappDaoFactory);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
tempModel.close();
|
|
||||||
ontModel.close();
|
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1121,39 +1111,20 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs) {
|
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs) {
|
||||||
this.dataset.getLock().enterCriticalSection(Lock.READ);
|
|
||||||
Model tempModel = ModelFactory.createDefaultModel();
|
|
||||||
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
try {
|
|
||||||
String getTypes =
|
|
||||||
"CONSTRUCT{ <" + this.individualURI + "> <" + RDF.type + "> ?types }\n" +
|
|
||||||
"WHERE{ GRAPH ?g { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" +
|
|
||||||
"} } \n";
|
|
||||||
tempModel = QueryExecutionFactory.create(QueryFactory.create(getTypes), dataset).execConstruct();
|
|
||||||
ontModel.add(tempModel.listStatements());
|
|
||||||
OntResource ontRes = ontModel.createOntResource(this.individualURI);
|
|
||||||
StmtIterator stmtIt = ontRes.listProperties(RDF.type);
|
|
||||||
try {
|
|
||||||
while(stmtIt.hasNext()) {
|
|
||||||
Statement stmt = stmtIt.nextStatement();
|
|
||||||
if (stmt.getObject().isURIResource()) {
|
|
||||||
String typeURI = ((Resource)stmt.getObject()).getURI();
|
|
||||||
if (pfs.isClassProhibited(typeURI)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
stmtIt.close();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
tempModel.close();
|
|
||||||
ontModel.close();
|
|
||||||
this.dataset.getLock().leaveCriticalSection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
List<VClass> types = getVClasses(false);
|
||||||
|
Iterator<VClass> itr = types.iterator();
|
||||||
|
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
String typeURI = itr.next().getURI();
|
||||||
|
if (pfs.isClassProhibited(typeURI)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Overriding the base method so that we can do the sorting by arbitrary property here. An
|
* Overriding the base method so that we can do the sorting by arbitrary property here. An
|
||||||
* IndividualSDB has a reference back to the model; everything else is just a dumb bean (for now).
|
* IndividualSDB has a reference back to the model; everything else is just a dumb bean (for now).
|
||||||
|
|
Loading…
Add table
Reference in a new issue