Skip to content
This repository has been archived by the owner on Jan 3, 2021. It is now read-only.

Commit

Permalink
void support first part, still missing: dataset description metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes committed May 3, 2012
1 parent 17fe666 commit 61b2b5e
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 407 deletions.
41 changes: 19 additions & 22 deletions doc/example/metadata.ttl
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

@prefix prv: <http://purl.org/net/provenance/ns#> .
@prefix prvTypes: <http://purl.org/net/provenance/types#> .

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix void: <http://rdfs.org/ns/void#> .

@prefix doap: <http://usefulinc.com/ns/doap#> .

@prefix xhtml: <http://www.w3.org/1999/xhtml/vocab/#> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .


# This template provides provenance information about RDF graphs served by D2R.
# The provenance information is described using the Provenance Vocabulary v0.6.

<about:metadata:root:root> a prv:DataItem ;
foaf:primaryTopic <about:metadata:runtime:resource> ;
foaf:topic <about:metadata:runtime:graph> ;

<about:metadata:runtime:resource>
rdfs:isDefinedBy <about:metadata:runtime:graph> ;
foaf:page <about:metadata:runtime:page> .

<about:metadata:runtime:graph> a prv:DataItem, foaf:Document ;
dc:publisher <about:metadata:runtime:resource> ;
void:inDataset <about:metadata:runtime:dataset> ;
dc:date <about:metadata:runtime:time> ;
xhtml:alternate <about:metadata:runtime:page> ;

prv:createdBy [
a prv:DataCreation ;
prv:completedAt <about:metadata:runtime:time> ;
prv:performedBy _:d2r ;

prv:usedData [
a prv:DataItem ;
d2rq:jdbcDSN <about:metadata:database:jdbcDSN>;
] ;
prv:performedBy _:d2rinstallation ;
prv:usedData <about:metadata:runtime:dataset> ;
] .

_:d2r a prv:NonHumanAgent ,
_:d2rinstallation a prv:NonHumanAgent ,
prvTypes:DataCreatingService ,
prv:DataProvidingService ;

rdfs:comment "This service runs D2R Server." ;
prv:operatedBy <about:metadata:metadata:d2rUser> ;
prv:deployedSoftware <http://www4.wiwiss.fu-berlin.de/is-group/resource/projects/Project3> ;
prv:deployedSoftware _:d2rrelease ;
rdfs:seeAlso <about:metadata:config:baseURI> .

<http://www4.wiwiss.fu-berlin.de/is-group/resource/projects/Project3> a doap:Project ;
_:d2rrelease a doap:Project ;
doap:release [
a doap:Version ;
doap:revision "0.9";
];
doap:name "D2R Server";
doap:homepage <http://www4.wiwiss.fu-berlin.de/bizer/d2r-server/> .
doap:homepage <http://d2rq.org/d2r-server> .

<about:metadata:metadata:dataset> rdf:type void:Dataset ;
void:exampleResource <about:metadata:runtime:resource> ;
rdfs:seeAlso <about:metadata:config:baseURI> .

<about:metadata:metadata:d2rUser>
foaf:name <about:metadata:metadata:operatorName> ;
Expand Down
138 changes: 88 additions & 50 deletions src/de/fuberlin/wiwiss/d2rq/server/D2RServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,50 @@
import de.fuberlin.wiwiss.d2rq.map.Mapping;

/**
* A D2R Server instance. Sets up a service, loads the D2RQ model, and starts Joseki.
* A D2R Server instance. Sets up a service, loads the D2RQ model, and starts
* Joseki.
*
* @author Richard Cyganiak (richard@cyganiak.de)
*/
public class D2RServer {
private final static String SPARQL_SERVICE_NAME = "sparql";

/* These service names should match the mappings in web.xml */
private final static String RESOURCE_SERVICE_NAME = "resource";
private final static String DATASET_SERVICE_NAME = "dataset";
private final static String DATA_SERVICE_NAME = "data";
private final static String PAGE_SERVICE_NAME = "page";
private final static String VOCABULARY_STEM = "vocab/";

private final static String DEFAULT_SERVER_NAME = "D2R Server";
private final static String SYSTEM_LOADER = "D2RServer.SYSTEM_LOADER";

private static final Log log = LogFactory.getLog(D2RServer.class);

/** System loader for access to the GraphD2RQ and configuration */
private final SystemLoader loader;

/** config file parser and Java representation */
private final ConfigLoader config;

/** base URI from command line */
private String overrideBaseURI = null;

/** the dataset, auto-reloadable in case of local mapping files */
private AutoReloadableDataset dataset;

/** Cached single instance */
private MetadataCreator metadataCreator;

public D2RServer(SystemLoader loader) {
this.loader = loader;
this.config = loader.getServerConfig();
}

public static D2RServer fromServletContext(ServletContext context) {
return retrieveSystemLoader(context).getD2RServer();
}

public void overrideBaseURI(String baseURI) {
// This is a hack to allow hash URIs to be used at least in the
// SPARQL endpoint. It will not work in the Web interface.
Expand All @@ -78,58 +80,69 @@ public void overrideBaseURI(String baseURI) {
}
this.overrideBaseURI = baseURI;
}

public String baseURI() {
if (this.overrideBaseURI != null) {
return this.overrideBaseURI;
}
return this.config.baseURI();
}

public String serverName() {
if (this.config.serverName() != null) {
return this.config.serverName();
}
return D2RServer.DEFAULT_SERVER_NAME;
}

public boolean hasTruncatedResults() {
return dataset.hasTruncatedResults();
}

public String resourceBaseURI(String serviceStem) {
// This is a hack to allow hash URIs to be used at least in the
// SPARQL endpoint. It will not work in the Web interface.
if (this.baseURI().endsWith("#")) {
return this.baseURI();
}
return this.baseURI() + serviceStem + D2RServer.RESOURCE_SERVICE_NAME + "/";
return this.baseURI() + serviceStem + D2RServer.RESOURCE_SERVICE_NAME
+ "/";
}

public String resourceBaseURI() {
return resourceBaseURI("");
}

public static String getResourceServiceName() {
return RESOURCE_SERVICE_NAME;
}

public static String getDataServiceName() {
return DATA_SERVICE_NAME;
}

public static String getPageServiceName() {
return PAGE_SERVICE_NAME;
}


public static String getDatasetServiceName() {
return DATASET_SERVICE_NAME;
}

public static String getSparqlServiceName() {
return SPARQL_SERVICE_NAME;
}

public String dataURL(String serviceStem, String relativeResourceURI) {
return this.baseURI() + serviceStem + DATA_SERVICE_NAME + "/" + relativeResourceURI;
return this.baseURI() + serviceStem + DATA_SERVICE_NAME + "/"
+ relativeResourceURI;
}

public String pageURL(String serviceStem, String relativeResourceURI) {
return this.baseURI() + serviceStem + PAGE_SERVICE_NAME + "/" + relativeResourceURI;
return this.baseURI() + serviceStem + PAGE_SERVICE_NAME + "/"
+ relativeResourceURI;
}

public boolean isVocabularyResource(Resource r) {
return r.getURI().startsWith(resourceBaseURI(VOCABULARY_STEM));
}
Expand All @@ -139,7 +152,8 @@ public void addDocumentMetadata(Model document, Resource documentResource) {
}

/**
* @return the auto-reloadable dataset which contains a GraphD2RQ as its default graph, no named graphs
* @return the auto-reloadable dataset which contains a GraphD2RQ as its
* default graph, no named graphs
*/
public AutoReloadableDataset dataset() {
return this.dataset;
Expand All @@ -148,70 +162,78 @@ public AutoReloadableDataset dataset() {
public Mapping getMapping() {
return loader.getMapping();
}

/**
* delegate to auto-reloadable dataset, will reload if necessary
*/
public void checkMappingFileChanged() {
dataset.checkMappingFileChanged();
}

/**
* delegate to auto-reloadable dataset *

/**
* delegate to auto-reloadable dataset *
*
* @return prefix mappings for the d2rq base graph
*/
public PrefixMapping getPrefixes() {
return dataset.getPrefixMapping();
}

public void start() {
if (config.isLocalMappingFile()) {
this.dataset = new AutoReloadableDataset(loader, config.getLocalMappingFilename(), config.getAutoReloadMapping());
this.dataset = new AutoReloadableDataset(loader,
config.getLocalMappingFilename(),
config.getAutoReloadMapping());
} else {
this.dataset = new AutoReloadableDataset(loader, null, false);
}

if (loader.getMapping().configuration().getUseAllOptimizations()) {
log.info("Fast mode (all optimizations)");
} else {
log.info("Safe mode (launch using --fast to use all optimizations)");
}

this.metadataCreator = new MetadataCreator(this);

// Set up a custom DescribeHandler that calls out to
// {@link ResourceDescriber}
DescribeHandlerRegistry.get().clear();
DescribeHandlerRegistry.get().add(new DescribeHandlerFactory() {
public DescribeHandler create() {
return new DescribeHandler() {
private BulkUpdateHandler adder;
public void start(Model accumulateResultModel, Context qContext) {
adder = accumulateResultModel.getGraph().getBulkUpdateHandler();

public void start(Model accumulateResultModel,
Context qContext) {
adder = accumulateResultModel.getGraph()
.getBulkUpdateHandler();
}

public void describe(Resource resource) {
log.info("DESCRIBE <" + resource + ">");
boolean outgoingTriplesOnly =
isVocabularyResource(resource) && !getConfig().getVocabularyIncludeInstances();
adder.add(new ResourceDescriber(
getMapping(), resource.asNode(),
outgoingTriplesOnly,
boolean outgoingTriplesOnly = isVocabularyResource(resource)
&& !getConfig().getVocabularyIncludeInstances();
adder.add(new ResourceDescriber(getMapping(), resource
.asNode(), outgoingTriplesOnly,
Relation.NO_LIMIT).description());
}
public void finish() {}

public void finish() {
}
};
}
});

Registry.add(RDFServer.ServiceRegistryName, createJosekiServiceRegistry());
Registry.add(RDFServer.ServiceRegistryName,
createJosekiServiceRegistry());
}

public void shutdown()
{

public void shutdown() {
log.info("shutting down");
loader.getMapping().close();
}

protected ServiceRegistry createJosekiServiceRegistry() {
ServiceRegistry services = new ServiceRegistry();
Service service = new Service(new SPARQL(),
Expand All @@ -220,20 +242,36 @@ protected ServiceRegistry createJosekiServiceRegistry() {
services.add(D2RServer.SPARQL_SERVICE_NAME, service);
return services;
}

public ConfigLoader getConfig() {
return config;
}

public static void storeSystemLoader(SystemLoader loader, ServletContext context) {

public static void storeSystemLoader(SystemLoader loader,
ServletContext context) {
context.setAttribute(SYSTEM_LOADER, loader);
}

public static SystemLoader retrieveSystemLoader(ServletContext context) {
return (SystemLoader) context.getAttribute(SYSTEM_LOADER);
}

public MetadataCreator getMetadataCreator() {
return metadataCreator;
}

private static String getUri(String base, String service) {
return base.endsWith("/") ? base + service : base + "/" + service;
}

public String getDatasetIri() {
// construct the dataset IRI from the configured base URI and "/dataset"
// - as in web.xml
return getUri(getConfig().baseURI(), D2RServer.getDatasetServiceName());
}

public String getSparqlUrl() {
return getUri(getConfig().baseURI(),
D2RServer.getSparqlServiceName());
}
}

0 comments on commit 61b2b5e

Please sign in to comment.