GeoPubby  Version 0.1.0.0
Dataset Class Reference

A dataset block in the server's configuration. More...

Inheritance diagram for Dataset:
Collaboration diagram for Dataset:

Public Member Functions

 Dataset (Resource dataset, Configuration configuration)
 
DataSource getDataSource ()
 
MetadataConfiguration getMetadataConfiguration ()
 
boolean supportsIRIs ()
 
boolean addSameAsStatements ()
 
boolean supportsSPARQL11 ()
 
Set< String > getBrowsableNamespaces ()
 Gets all values of conf:browsableNamespace declared on the dataset resource. More...
 
Resource getSelf ()
 
Model getModel ()
 
boolean hasType (Resource class_)
 
boolean hasProperty (Property p)
 
Resource getResource (Property p)
 
Set< Resource > getResources (Property p)
 
Set< Property > getProperties (Property p)
 
String getIRI (Property p)
 
String getIRI (Property p, String defaultValue)
 
String getRequiredIRI (Property p)
 
Set< String > getIRIs (Property p)
 
String getString (Property p)
 
String getString (Property p, String defaultValue)
 
Set< String > getStrings (Property p)
 
boolean getBoolean (Property p, boolean defaultValue)
 
void requireExactlyOneOf (Property... properties)
 

Public Attributes

String datasetBase
 
String sparqlEndpoint
 

Private Member Functions

DataSource buildDataSource (Configuration configuration)
 
void assertHasOneValue (Property p)
 
void assertResourceValue (Property p)
 
void assertResourceValue (Statement stmt)
 
void assertIRIValue (Property p)
 
void assertIRIValue (Statement stmt)
 
void assertLiteralValue (Property p)
 
void assertLiteralValue (Statement stmt)
 
void assertString (Statement stmt)
 
String pretty (RDFNode node)
 
String pretty (Statement stmt)
 
void raiseMissingProperty (Property p)
 
void raiseUnexpectedDatatype (String expectedDatatype, Statement stmt)
 

Private Attributes

final DataSource dataSource
 
final MetadataConfiguration metadata
 
RemoteSPARQLDataSource sparqlDataSource = null
 
final Resource resource
 

Detailed Description

A dataset block in the server's configuration.

Constructor & Destructor Documentation

◆ Dataset()

Dataset ( Resource  dataset,
Configuration  configuration 
)
34  {
35  super(dataset);
36  dataSource = buildDataSource(configuration);
37  metadata = new MetadataConfiguration(dataset, sparqlDataSource);
38  }
final DataSource dataSource
Definition: Dataset.java:24
final MetadataConfiguration metadata
Definition: Dataset.java:25
RemoteSPARQLDataSource sparqlDataSource
Definition: Dataset.java:32
DataSource buildDataSource(Configuration configuration)
Definition: Dataset.java:72

References Dataset.buildDataSource(), Dataset.dataSource, Dataset.metadata, and Dataset.sparqlDataSource.

Member Function Documentation

◆ addSameAsStatements()

boolean addSameAsStatements ( )
52  {
53  return getBoolean(CONF.addSameAsStatements, false);
54  }
boolean getBoolean(Property p, boolean defaultValue)
Definition: ResourceReader.java:124

References CONF.addSameAsStatements, and ResourceReader.getBoolean().

Referenced by Dataset.buildDataSource().

◆ assertHasOneValue()

void assertHasOneValue ( Property  p)
privateinherited
170  {
171  StmtIterator it = resource.listProperties(p);
172  if (!it.hasNext()) {
173  throw new ConfigurationException("Missing property " + pretty(p) +
174  " on resource " + pretty(resource));
175  }
176  it.next();
177  if (it.hasNext()) {
178  throw new ConfigurationException("Too many values for property " +
179  pretty(p) + " on resource " + pretty(resource));
180  }
181  }
String pretty(RDFNode node)
Definition: ResourceReader.java:235
final Resource resource
Definition: ResourceReader.java:23

References ResourceReader.pretty(), and ResourceReader.resource.

Referenced by ResourceReader.getBoolean(), ResourceReader.getIRI(), ResourceReader.getResource(), and ResourceReader.getString().

◆ assertIRIValue() [1/2]

void assertIRIValue ( Property  p)
privateinherited
194  {
195  assertIRIValue(resource.getProperty(p));
196  }
void assertIRIValue(Property p)
Definition: ResourceReader.java:194

References ResourceReader.resource.

Referenced by ResourceReader.getIRI(), and ResourceReader.getIRIs().

◆ assertIRIValue() [2/2]

void assertIRIValue ( Statement  stmt)
privateinherited
198  {
199  if (stmt.getObject().isLiteral()) {
200  throw new ConfigurationException(
201  "Expected IRI object, found literal: " + pretty(stmt));
202  }
203  if (stmt.getObject().isAnon()) {
204  throw new ConfigurationException(
205  "Expected IRI object, found blank node: " + pretty(stmt));
206  }
207  }

References ResourceReader.pretty().

◆ assertLiteralValue() [1/2]

void assertLiteralValue ( Property  p)
privateinherited
209  {
210  assertLiteralValue(resource.getProperty(p));
211  }
void assertLiteralValue(Property p)
Definition: ResourceReader.java:209

References ResourceReader.resource.

Referenced by ResourceReader.assertString(), and ResourceReader.getBoolean().

◆ assertLiteralValue() [2/2]

void assertLiteralValue ( Statement  stmt)
privateinherited
213  {
214  if (stmt.getObject().isURIResource()) {
215  throw new ConfigurationException(
216  "Expected literal object, found IRI: " + pretty(stmt));
217  }
218  if (stmt.getObject().isAnon()) {
219  throw new ConfigurationException(
220  "Expected literal object, found blank node: " + pretty(stmt));
221  }
222  }

References ResourceReader.pretty().

◆ assertResourceValue() [1/2]

void assertResourceValue ( Property  p)
privateinherited
183  {
184  assertResourceValue(resource.getProperty(p));
185  }
void assertResourceValue(Property p)
Definition: ResourceReader.java:183

References ResourceReader.resource.

Referenced by ResourceReader.getResource(), and ResourceReader.getResources().

◆ assertResourceValue() [2/2]

void assertResourceValue ( Statement  stmt)
privateinherited
187  {
188  if (stmt.getObject().isLiteral()) {
189  throw new ConfigurationException(
190  "Expected resource object, found literal: " + pretty(stmt));
191  }
192  }

References ResourceReader.pretty().

◆ assertString()

void assertString ( Statement  stmt)
privateinherited
224  {
225  assertLiteralValue(stmt);
226  Literal value = stmt.getLiteral();
227  if (value.getDatatypeURI() == null ||
228  XSD.xstring.getURI().equals(value.getDatatypeURI()) ||
229  (RDF.getURI() + "langString").equals(value.getDatatypeURI())) {
230  return;
231  }
232  raiseUnexpectedDatatype("string", stmt);
233  }
void raiseUnexpectedDatatype(String expectedDatatype, Statement stmt)
Definition: ResourceReader.java:257

References ResourceReader.assertLiteralValue(), and ResourceReader.raiseUnexpectedDatatype().

Referenced by ResourceReader.getString(), and ResourceReader.getStrings().

◆ buildDataSource()

DataSource buildDataSource ( Configuration  configuration)
private
72  {
73  requireExactlyOneOf(CONF.sparqlEndpoint, CONF.loadRDF);
74 
75  DataSource result;
76  if (hasProperty(CONF.sparqlEndpoint)) {
77 
78  // SPARQL data source
79  String endpointURL = getIRI(CONF.sparqlEndpoint);
80  this.sparqlEndpoint=endpointURL;
81  String defaultGraphURI = getIRI(CONF.sparqlDefaultGraph);
82  sparqlDataSource = new RemoteSPARQLDataSource(
83  endpointURL,
84  defaultGraphURI,
86  getStrings(CONF.resourceDescriptionQuery),
87  getStrings(CONF.propertyListQuery),
88  getStrings(CONF.inversePropertyListQuery),
89  getStrings(CONF.anonymousPropertyDescriptionQuery),
90  getStrings(CONF.anonymousInversePropertyDescriptionQuery),
91  configuration.getVocabularyStore().getHighIndegreeProperties(),
92  configuration.getVocabularyStore().getHighOutdegreeProperties());
93  if (hasProperty(CONF.contentType)) {
95  }
96  for (String param: getStrings(CONF.queryParamSelect)) {
98  }
99  for (String param: getStrings(CONF.queryParamGraph)) {
101  }
102  result = sparqlDataSource;
103 
104  } else {
105 
106  // File data source
107  Model data = ModelFactory.createDefaultModel();
108  for (String fileName: getIRIs(CONF.loadRDF)) {
109  // If the location is a local file, then use webBase as base URI
110  // to resolve relative URIs in the file. Having file:/// URIs in
111  // there would likely not be useful to anyone.
112  //IRIResolver res=new IRIResolver();
113  //res.iriFactory().
114  //fileName = IRIResolver..resolveFileURL(fileName);
115  String base = (fileName.startsWith("file:/") ?
116  configuration.getWebApplicationBaseURI() : fileName);
117 
118  try {
119  Model m = RDFDataMgr.loadModel(fileName);
120  data.add(m);
121 
122  // We'd like to do simply data.setNsPrefix(m), but that leaves relative
123  // namespace URIs like <#> unresolved, so we do a big dance to make them
124  // absolute.
125  for (String prefix: m.getNsPrefixMap().keySet()) {
126  String uri=m.getNsPrefixMap().get("prefix");
127  if(uri.contains("file:/")) {
128  data.setNsPrefix(prefix, uri.toString().replace("file:/", base));
129  }
130  }
131  } catch (JenaException ex) {
132  throw new ConfigurationException("Error reading <" + fileName + ">: " + ex.getMessage());
133  }
134  }
135  result = new ModelDataSource(data);
136  }
137 
138  // If conf:datasetURIPattern is set, then filter the dataset accordingly.
139  if (hasProperty(CONF.datasetURIPattern)) {
140  final Pattern pattern = Pattern.compile(getString(CONF.datasetURIPattern));
141  final DataSource fresult=result;
142  result = new FilteredDataSource(fresult) {
143  @Override
144  public boolean canDescribe(String absoluteIRI) {
145  return pattern.matcher(absoluteIRI).find();
146  }
147 
148  @Override
149  public Model describeResource(String absoluteIRI, String language) {
150  // TODO Auto-generated method stub
151  return null;
152  }
153  };
154  }
155 
156  IRIRewriter rewriter = IRIRewriter.identity;
157 
158  // If conf:datasetBase is set (and different from conf:webBase),
159  // rewrite the IRIs accordingly
160  // Base IRI for IRIs considered to be "in" the data source
161  String fullWebBase = configuration.getWebApplicationBaseURI() +
162  configuration.getWebResourcePrefix();
163  datasetBase = getIRI(CONF.datasetBase,
164  fullWebBase);
165  if (!datasetBase.equals(fullWebBase)) {
166  rewriter = IRIRewriter.createNamespaceBased(datasetBase, fullWebBase);
167  }
168 
169  // Escape special characters in IRIs
170  rewriter = IRIRewriter.chain(rewriter, new PubbyIRIEscaper(
171  fullWebBase, !supportsIRIs()));
172 
173  result = new RewrittenDataSource(
174  result, rewriter, addSameAsStatements());
175 
176  // Determine all browsable namespaces for this dataset
177  final Set<String> browsableNamespaces = new HashSet<String>();
178  browsableNamespaces.add(fullWebBase);
179  for (String iri: getBrowsableNamespaces()) {
180  browsableNamespaces.add(iri);
181  }
182  browsableNamespaces.addAll(configuration.getBrowsableNamespaces());
183 
184  // Filter the dataset to keep only those resources in the datasetBase
185  // and in browsable namespaces, unless it's an annotation provider
186  if (!hasType(CONF.AnnotationProvider)) {
187  final DataSource fresult=result;
188  result = new FilteredDataSource(fresult) {
189  @Override
190  public boolean canDescribe(String absoluteIRI) {
191  for (String namespace: browsableNamespaces) {
192  if (absoluteIRI.startsWith(namespace)) return true;
193  }
194  return false;
195  }
196 
197  @Override
198  public Model describeResource(String absoluteIRI, String language) {
199  // TODO Auto-generated method stub
200  return null;
201  }
202  };
203  }
204 
205  return result;
206  }
String sparqlEndpoint
Definition: Dataset.java:29
boolean supportsSPARQL11()
Definition: Dataset.java:56
boolean supportsIRIs()
Definition: Dataset.java:48
Set< String > getBrowsableNamespaces()
Gets all values of conf:browsableNamespace declared on the dataset resource.
Definition: Dataset.java:67
String datasetBase
Definition: Dataset.java:27
boolean addSameAsStatements()
Definition: Dataset.java:52
String getIRI(Property p)
Definition: ResourceReader.java:71
String getString(Property p)
Definition: ResourceReader.java:100
Set< String > getIRIs(Property p)
Definition: ResourceReader.java:89
boolean hasType(Resource class_)
Definition: ResourceReader.java:37
Set< String > getStrings(Property p)
Definition: ResourceReader.java:113
boolean hasProperty(Property p)
Definition: ResourceReader.java:41
void requireExactlyOneOf(Property... properties)
Definition: ResourceReader.java:144
void addGraphQueryParam(String param)
Definition: RemoteSPARQLDataSource.java:124
void addSelectQueryParam(String param)
Definition: RemoteSPARQLDataSource.java:128
void setGraphContentType(String mediaType)
Sets the content type to ask for in graph requests (CONSTRUCT and DESCRIBE) to the remote SPARQL endp...
Definition: RemoteSPARQLDataSource.java:120

References RemoteSPARQLDataSource.addGraphQueryParam(), Dataset.addSameAsStatements(), RemoteSPARQLDataSource.addSelectQueryParam(), CONF.AnnotationProvider, CONF.anonymousInversePropertyDescriptionQuery, CONF.anonymousPropertyDescriptionQuery, IRIRewriter.chain(), CONF.contentType, IRIRewriter.createNamespaceBased(), Dataset.datasetBase, CONF.datasetBase, CONF.datasetURIPattern, Configuration.getBrowsableNamespaces(), Dataset.getBrowsableNamespaces(), VocabularyStore.getHighIndegreeProperties(), VocabularyStore.getHighOutdegreeProperties(), ResourceReader.getIRI(), ResourceReader.getIRIs(), ResourceReader.getString(), ResourceReader.getStrings(), Configuration.getVocabularyStore(), Configuration.getWebApplicationBaseURI(), Configuration.getWebResourcePrefix(), ResourceReader.hasProperty(), ResourceReader.hasType(), IRIRewriter.identity, CONF.inversePropertyListQuery, CONF.loadRDF, CONF.propertyListQuery, CONF.queryParamGraph, CONF.queryParamSelect, ResourceReader.requireExactlyOneOf(), CONF.resourceDescriptionQuery, RemoteSPARQLDataSource.setGraphContentType(), Dataset.sparqlDataSource, CONF.sparqlDefaultGraph, CONF.sparqlEndpoint, Dataset.supportsIRIs(), and Dataset.supportsSPARQL11().

Referenced by Dataset.Dataset().

◆ getBoolean()

boolean getBoolean ( Property  p,
boolean  defaultValue 
)
inherited
124  {
125  if (!resource.hasProperty(p)) {
126  return defaultValue;
127  }
130  Literal value = resource.getProperty(p).getLiteral();
131  if (XSD.xboolean.getURI().equals(value.getDatatypeURI())) {
132  return value.getBoolean();
133  }
134  if (value.getDatatypeURI() == null || XSD.xstring.getURI().equals(value.getDatatypeURI())) {
135  if ("true".equals(value.getString().toLowerCase())
136  || "false".equals(value.getString().toLowerCase())) {
137  return "true".equals(value.getString().toLowerCase());
138  }
139  }
140  raiseUnexpectedDatatype("xsd:boolean", resource.getProperty(p));
141  return false;
142  }
void assertHasOneValue(Property p)
Definition: ResourceReader.java:170

References ResourceReader.assertHasOneValue(), ResourceReader.assertLiteralValue(), ResourceReader.raiseUnexpectedDatatype(), and ResourceReader.resource.

Referenced by Dataset.addSameAsStatements(), Configuration.showLabels(), Dataset.supportsIRIs(), and Dataset.supportsSPARQL11().

◆ getBrowsableNamespaces()

Set<String> getBrowsableNamespaces ( )

Gets all values of conf:browsableNamespace declared on the dataset resource.

Does not include values inherited from the configuration resource.

Returns
Namespace IRIs of browsable namespaces
67  {
68  return getIRIs(CONF.browsableNamespace);
69  }

References CONF.browsableNamespace, and ResourceReader.getIRIs().

Referenced by Dataset.buildDataSource(), and Configuration.Configuration().

◆ getDataSource()

DataSource getDataSource ( )
40  {
41  return dataSource;
42  }

References Dataset.dataSource.

◆ getIRI() [1/2]

◆ getIRI() [2/2]

String getIRI ( Property  p,
String  defaultValue 
)
inherited
75  {
76  if (!resource.hasProperty(p)) return defaultValue;
78  assertIRIValue(p);
79  return resource.getProperty(p).getResource().getURI();
80  }

References ResourceReader.assertHasOneValue(), ResourceReader.assertIRIValue(), and ResourceReader.resource.

◆ getIRIs()

Set<String> getIRIs ( Property  p)
inherited
89  {
90  Set<String> result = new HashSet<String>();
91  StmtIterator it = resource.listProperties(p);
92  while (it.hasNext()) {
93  Statement stmt = it.next();
94  assertIRIValue(stmt);
95  result.add(stmt.getResource().getURI());
96  }
97  return result;
98  }

References ResourceReader.assertIRIValue(), and ResourceReader.resource.

Referenced by Dataset.buildDataSource(), Configuration.Configuration(), Configuration.getBrowsableNamespaces(), and Dataset.getBrowsableNamespaces().

◆ getMetadataConfiguration()

MetadataConfiguration getMetadataConfiguration ( )
44  {
45  return metadata;
46  }

References Dataset.metadata.

◆ getModel()

◆ getProperties()

Set<Property> getProperties ( Property  p)
inherited
63  {
64  Set<Property> result = new HashSet<Property>();
65  for (Resource r: getResources(p)) {
66  result.add(r.as(Property.class));
67  }
68  return result;
69  }
Set< Resource > getResources(Property p)
Definition: ResourceReader.java:52

References ResourceReader.getResources().

Referenced by Configuration.Configuration().

◆ getRequiredIRI()

String getRequiredIRI ( Property  p)
inherited
82  {
83  if (!resource.hasProperty(p)) {
85  }
86  return getIRI(p);
87  }
void raiseMissingProperty(Property p)
Definition: ResourceReader.java:252

References ResourceReader.getIRI(), ResourceReader.raiseMissingProperty(), and ResourceReader.resource.

Referenced by Configuration.Configuration().

◆ getResource()

Resource getResource ( Property  p)
inherited
45  {
46  if (!resource.hasProperty(p)) return null;
49  return resource.getProperty(p).getResource();
50  }

References ResourceReader.assertHasOneValue(), ResourceReader.assertResourceValue(), and ResourceReader.resource.

Referenced by MetadataConfiguration.MetadataConfiguration().

◆ getResources()

Set<Resource> getResources ( Property  p)
inherited
52  {
53  Set<Resource> result = new HashSet<Resource>();
54  StmtIterator it = resource.listProperties(p);
55  while (it.hasNext()) {
56  Statement stmt = it.next();
57  assertResourceValue(stmt);
58  result.add(stmt.getResource());
59  }
60  return result;
61  }

References ResourceReader.assertResourceValue(), and ResourceReader.resource.

Referenced by Configuration.Configuration(), and ResourceReader.getProperties().

◆ getSelf()

Resource getSelf ( )
inherited
29  {
30  return resource;
31  }

References ResourceReader.resource.

Referenced by MetadataConfiguration.parsePlaceholder().

◆ getString() [1/2]

String getString ( Property  p)
inherited

◆ getString() [2/2]

String getString ( Property  p,
String  defaultValue 
)
inherited
104  {
105  if (!resource.hasProperty(p)) {
106  return defaultValue;
107  }
109  assertString(resource.getProperty(p));
110  return resource.getProperty(p).getString();
111  }
void assertString(Statement stmt)
Definition: ResourceReader.java:224

References ResourceReader.assertHasOneValue(), ResourceReader.assertString(), and ResourceReader.resource.

◆ getStrings()

Set<String> getStrings ( Property  p)
inherited
113  {
114  Set<String> result = new HashSet<String>();
115  StmtIterator it = resource.listProperties(p);
116  while (it.hasNext()) {
117  Statement stmt = it.next();
118  assertString(stmt);
119  result.add(stmt.getString());
120  }
121  return result;
122  }

References ResourceReader.assertString(), and ResourceReader.resource.

Referenced by Dataset.buildDataSource().

◆ hasProperty()

boolean hasProperty ( Property  p)
inherited
41  {
42  return resource.hasProperty(p);
43  }

References ResourceReader.resource.

Referenced by Configuration.buildDataSource(), Dataset.buildDataSource(), and Configuration.Configuration().

◆ hasType()

boolean hasType ( Resource  class_)
inherited
37  {
38  return resource.hasProperty(RDF.type, class_);
39  }

References ResourceReader.resource.

Referenced by Dataset.buildDataSource().

◆ pretty() [1/2]

String pretty ( RDFNode  node)
privateinherited
235  {
236  if (node.isAnon()) return "[]";
237  if (node.isURIResource()) {
238  Resource r = node.asResource();
239  if (getModel().qnameFor(r.getURI()) == null) {
240  return "<" + r.getURI() + ">";
241  }
242  return getModel().qnameFor(r.getURI());
243  }
244  return PrintUtil.print(node);
245  }
Model getModel()
Definition: ResourceReader.java:33

References ResourceReader.getModel().

Referenced by ResourceReader.assertHasOneValue(), ResourceReader.assertIRIValue(), ResourceReader.assertLiteralValue(), ResourceReader.assertResourceValue(), ResourceReader.pretty(), ResourceReader.raiseMissingProperty(), ResourceReader.raiseUnexpectedDatatype(), and ResourceReader.requireExactlyOneOf().

◆ pretty() [2/2]

String pretty ( Statement  stmt)
privateinherited
247  {
248  return pretty(stmt.getSubject()) + " " + pretty(stmt.getPredicate())
249  + " " + pretty(stmt.getObject()) + ".";
250  }

References ResourceReader.pretty().

◆ raiseMissingProperty()

void raiseMissingProperty ( Property  p)
privateinherited
252  {
253  throw new ConfigurationException("Missing property " +
254  pretty(p) + " on resource " + pretty(resource));
255  }

References ResourceReader.pretty(), and ResourceReader.resource.

Referenced by ResourceReader.getRequiredIRI().

◆ raiseUnexpectedDatatype()

void raiseUnexpectedDatatype ( String  expectedDatatype,
Statement  stmt 
)
privateinherited
257  {
258  throw new ConfigurationException(
259  "Expected " + expectedDatatype +
260  " object, found other datatype: " +
261  pretty(stmt));
262  }

References ResourceReader.pretty().

Referenced by ResourceReader.assertString(), and ResourceReader.getBoolean().

◆ requireExactlyOneOf()

void requireExactlyOneOf ( Property...  properties)
inherited
144  {
145  Property found = null;
146  boolean first = true;
147  StringBuilder s = new StringBuilder();
148  for (Property p: properties) {
149  if (resource.hasProperty(p)) {
150  if (found == null) {
151  found = p;
152  } else {
153  throw new ConfigurationException("Can't have both " +
154  pretty(found) + " and " + pretty(p) +
155  " on resource " + pretty(resource));
156  }
157  }
158  if (!first) {
159  s.append(", ");
160  }
161  s.append(pretty(p));
162  first = false;
163  }
164  if (found == null) {
165  throw new ConfigurationException("One of " + s.toString() +
166  " required on resource " + pretty(resource));
167  }
168  }

References ResourceReader.pretty(), and ResourceReader.resource.

Referenced by Dataset.buildDataSource().

◆ supportsIRIs()

boolean supportsIRIs ( )
48  {
49  return getBoolean(CONF.supportsIRIs, true);
50  }

References ResourceReader.getBoolean(), and CONF.supportsIRIs.

Referenced by Dataset.buildDataSource().

◆ supportsSPARQL11()

boolean supportsSPARQL11 ( )
56  {
57  return getBoolean(CONF.supportsSPARQL11, false);
58  }

References ResourceReader.getBoolean(), and CONF.supportsSPARQL11.

Referenced by Dataset.buildDataSource().

Member Data Documentation

◆ datasetBase

String datasetBase

Referenced by Dataset.buildDataSource().

◆ dataSource

final DataSource dataSource
private

◆ metadata

◆ resource

◆ sparqlDataSource

RemoteSPARQLDataSource sparqlDataSource = null
private

◆ sparqlEndpoint

String sparqlEndpoint