Permalink
Browse files

stop including rdfs:seeAlso links to DESCRIBE results; they are most …

…likely not useful to anyone
  • Loading branch information...
cygri committed Mar 30, 2012
1 parent 79aa85e commit e23d80bec0fe87bba33e657c5d3a4e88a14f2a9b
@@ -1,8 +1,5 @@
package de.fuberlin.wiwiss.d2rq.server;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
@@ -105,18 +102,6 @@ public String resourceBaseURI() {
return resourceBaseURI("");
}
- public String graphURLDescribingResource(String resourceURI) {
- if (resourceURI.indexOf(":") == -1) {
- resourceURI = resourceBaseURI() + resourceURI;
- }
- String query = "DESCRIBE <" + resourceURI + ">";
- try {
- return this.baseURI() + D2RServer.SPARQL_SERVICE_NAME + "?query=" + URLEncoder.encode(query, "utf-8");
- } catch (UnsupportedEncodingException ex) {
- throw new RuntimeException(ex);
- }
- }
-
public static String getResourceServiceName() {
return RESOURCE_SERVICE_NAME;
}
@@ -4,63 +4,44 @@
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sparql.core.describe.DescribeHandler;
import com.hp.hpl.jena.sparql.util.Context;
-import com.hp.hpl.jena.vocabulary.RDFS;
/**
* A custom {@link DescribeHandler} that returns the results of a two-way
* find.
*
- * TODO Is this thread-safe? Does ARQ create new instances for each execution?
- *
* @author Richard Cyganiak (richard@cyganiak.de)
*/
public class FindDescribeHandler implements DescribeHandler {
- private Log log = LogFactory.getLog(FindDescribeHandler.class);
+ private static final Log log = LogFactory.getLog(FindDescribeHandler.class);
- private Model resultModel;
private final D2RServer server;
+ private final Model d2rqModel;
+ private Model resultModel;
public FindDescribeHandler(D2RServer server) {
this.server = server;
+ this.d2rqModel = server.dataset().getDefaultModel();
}
public void start(Model accumulateResultModel, Context qContext) {
- this.resultModel = accumulateResultModel;
- this.resultModel.setNsPrefix("rdfs", RDFS.getURI());
+ resultModel = accumulateResultModel;
}
public void describe(Resource resource) {
log.info("DESCRIBE <" + resource + ">");
try {
- Model description = ModelFactory.createDefaultModel();
- Model seeAlsos = ModelFactory.createDefaultModel();
- Model dataModel = server.dataset().getDefaultModel();
- description.add(dataModel.listStatements(resource, null, (RDFNode) null));
-
- if (!server.isVocabularyResource(resource) || server.getConfig().getVocabularyIncludeInstances()) {
- description.add(dataModel.listStatements(null, null, resource));
- description.add(dataModel.listStatements(null, (Property) resource.as(Property.class), (RDFNode) null));
- }
- ResIterator rit = description.listSubjects();
- while (rit.hasNext()) {
- addSeeAlsoStatement(rit.nextResource(), seeAlsos, resource.getURI());
- }
- rit.close();
- NodeIterator nit = description.listObjects();
- while (nit.hasNext()) {
- addSeeAlsoStatement(nit.nextNode(), seeAlsos, resource.getURI());
- }
- nit.close();
- resultModel.add(description);
- resultModel.add(seeAlsos);
+ resultModel.add(d2rqModel.listStatements(resource, null, (RDFNode) null));
+ if (!server.isVocabularyResource(resource)) {
+ resultModel.add(d2rqModel.listStatements(null, null, resource));
+ } else if (server.getConfig().getVocabularyIncludeInstances()) {
+ resultModel.add(d2rqModel.listStatements(null, null, resource));
+ resultModel.add(d2rqModel.listStatements(null, (Property) resource.as(Property.class), (RDFNode) null));
+ }
} catch (RuntimeException ex) {
log.debug("Caught and re-threw RuntimeException", ex);
throw ex;
@@ -70,22 +51,4 @@ public void describe(Resource resource) {
public void finish() {
// do nothing
}
-
- private void addSeeAlsoStatement(RDFNode n, Model m, String currentResourceURI) {
- if (!n.isURIResource()) {
- return;
- }
- String resourceURI = n.asNode().getURI();
- if (currentResourceURI.equals(resourceURI)) {
- // Don't add seeAlso for the current resource pointing to its own description
- return;
- }
- if (resourceURI.startsWith(server.baseURI())) {
- // Don't add seeAlso for dereferenceable URIs
- return;
- }
- String seeAlsoURI = server.graphURLDescribingResource(resourceURI);
- Resource nAsResource = m.getResource(resourceURI);
- nAsResource.addProperty(RDFS.seeAlso, m.createResource(seeAlsoURI));
- }
}

0 comments on commit e23d80b

Please sign in to comment.