GeoPubby  Version 0.1.0.0
ResourceDescription Class Reference

A convenient interface to an RDF description of a resource. More...

Collaboration diagram for ResourceDescription:

Classes

class  PropertyBuilder
 
class  ResourceProperty
 
class  Value
 

Public Member Functions

 ResourceDescription (HypermediaControls controller, Model model, Configuration config)
 Constructor for this class. More...
 
List< Geometry > getGeoms ()
 Gets the list of geometries existing at the current resource. More...
 
String getEPSG ()
 Gets the EPSG code from a statement if it is annotated using an EPSG statement. More...
 
List< StyleObjectgetStyle ()
 Gets the EPSG code from a statement if it is annotated using an EPSG statement. More...
 
 ResourceDescription (HypermediaControls controller, Model model, Map< Property, Integer > highIndegreeProperties, Map< Property, Integer > highOutdegreeProperties, Configuration config)
 
String getURI ()
 
Model getModel ()
 
String getTitle ()
 If getLabel() is non null, return the label. More...
 
Literal getLabel ()
 
String getComment ()
 
String getImageURL ()
 
ResourceProperty getProperty (Property property, boolean isInverse)
 
List< ResourcePropertygetProperties ()
 
String toSentenceCase (String s, String lang)
 Converts a string to Sentence Case. More...
 
String toTitleCase (String s, String lang)
 Converts a string to Title Case. More...
 

Private Member Functions

void addPoint (final Resource r)
 Adds a point described by a longitude and latitude coordinate to the list of geometries. More...
 
void addGeometry2 (final Literal literall)
 Adds a geometry given as a WKT literal and extracts an EPSG code if annotated. More...
 
void addGeometryGeoJSON (final Literal literall)
 Adds a geometry described using a GeoJSON literal. More...
 
void addGeometry (final Resource r)
 Adds a geometry described using a WKT literal. More...
 
void addAllGeoms ()
 Adds geometries to GeoPubby considering a list of geo properties with different literal types. More...
 
 ResourceDescription (HypermediaControls controller, Model model, Map< Property, Integer > highIndegreeProperties, Map< Property, Integer > highOutdegreeProperties, Configuration config, boolean learnHighDegreeProps)
 
 ResourceDescription (Resource resource, Model model, Configuration config)
 
List< ResourcePropertybuildProperties ()
 
boolean isEmptyLiteral (RDFNode node)
 Checks whether a node is an empty literal that should better be skipped. More...
 
PrefixMapping getPrefixes ()
 Returns a prefix mapping containing all prefixes from the input model and from the configuration, with the configuration taking precedence. More...
 
Collection< RDFNode > getValuesFromMultipleProperties (Collection< Property > properties)
 
Literal getBestLanguageMatch (Collection< RDFNode > nodes, String lang)
 
String normalizeWhitespace (String s, boolean squash)
 
void learnHighDegreeProperties (boolean isInverse, int limit)
 

Private Attributes

final HypermediaControls hypermediaResource
 
final Model model
 
final Resource resource
 
final Configuration config
 
final Map< Property, Integer > highIndegreeProperties
 
final Map< Property, Integer > highOutdegreeProperties
 
PrefixMapping prefixes = null
 
List< ResourcePropertyproperties = null
 
List< Geometry > geoms
 List of extracted geometries per resource. More...
 
WKTReader reader =new WKTReader()
 WKTReader to read WKT literals. More...
 
GeometryFactory fac =new GeometryFactory()
 

Static Private Attributes

static final int HIGH_DEGREE_CUTOFF = 10
 
static Pattern wordPattern = Pattern.compile("[^ \t\r\n-]+|")
 
static Pattern camelCaseBoundaryPattern
 
static Pattern english = Pattern.compile("^en(-.*)?$", Pattern.CASE_INSENSITIVE)
 
static Set< String > englishUncapitalizedWords
 

Detailed Description

A convenient interface to an RDF description of a resource.

Provides access to its label, a textual comment, detailed representations of its properties, and so on.

TODO: Sort out who constructs these. Perhaps only the data source and this class itself should?

Constructor & Destructor Documentation

◆ ResourceDescription() [1/4]

ResourceDescription ( HypermediaControls  controller,
Model  model,
Configuration  config 
)

Constructor for this class.

Parameters
controller
model
config
77  {
78  this(controller, model, null, null, config, false);
79  }
final Model model
Definition: ResourceDescription.java:53
final Configuration config
Definition: ResourceDescription.java:55

References ResourceDescription.config, and ResourceDescription.model.

Referenced by ResourceDescription.PropertyBuilder.addValue(), and ResourceDescription.Value.getLabel().

◆ ResourceDescription() [2/4]

ResourceDescription ( HypermediaControls  controller,
Model  model,
Map< Property, Integer >  highIndegreeProperties,
Map< Property, Integer >  highOutdegreeProperties,
Configuration  config 
)
241  {
242  this(controller, model, highIndegreeProperties, highOutdegreeProperties, config, true);
243  }
final Map< Property, Integer > highIndegreeProperties
Definition: ResourceDescription.java:56
final Map< Property, Integer > highOutdegreeProperties
Definition: ResourceDescription.java:57

References ResourceDescription.config, ResourceDescription.highIndegreeProperties, ResourceDescription.highOutdegreeProperties, and ResourceDescription.model.

◆ ResourceDescription() [3/4]

ResourceDescription ( HypermediaControls  controller,
Model  model,
Map< Property, Integer >  highIndegreeProperties,
Map< Property, Integer >  highOutdegreeProperties,
Configuration  config,
boolean  learnHighDegreeProps 
)
private
248  {
249  this.hypermediaResource = controller;
250  this.model = model;
251  this.resource = model.getResource(controller.getAbsoluteIRI());
252  this.config = config;
254  Collections.<Property, Integer>emptyMap() : highIndegreeProperties;
256  Collections.<Property, Integer>emptyMap() : highOutdegreeProperties;
257  if (learnHighDegreeProps) {
260  }
261  }
final Resource resource
Definition: ResourceDescription.java:54
void learnHighDegreeProperties(boolean isInverse, int limit)
Definition: ResourceDescription.java:821
final HypermediaControls hypermediaResource
Definition: ResourceDescription.java:52
static final int HIGH_DEGREE_CUTOFF
Definition: ResourceDescription.java:50

References ResourceDescription.config, HypermediaControls.getAbsoluteIRI(), ResourceDescription.HIGH_DEGREE_CUTOFF, ResourceDescription.highIndegreeProperties, ResourceDescription.highOutdegreeProperties, ResourceDescription.learnHighDegreeProperties(), and ResourceDescription.model.

◆ ResourceDescription() [4/4]

ResourceDescription ( Resource  resource,
Model  model,
Configuration  config 
)
private
263  {
264  this.hypermediaResource = null;
265  this.model = model;
266  this.resource = resource;
267  this.config = config;
268  this.highIndegreeProperties = Collections.<Property, Integer>emptyMap();
269  this.highOutdegreeProperties = Collections.<Property, Integer>emptyMap();
270  }

References ResourceDescription.config, ResourceDescription.model, and ResourceDescription.resource.

Member Function Documentation

◆ addAllGeoms()

void addAllGeoms ( )
private

Adds geometries to GeoPubby considering a list of geo properties with different literal types.

152  {
153  StmtIterator it= resource.listProperties(GEO.ASWKT);
154  while(it.hasNext()) {
155  Statement s = it.nextStatement();
156  if ( !s.getObject().isAnon() ) {
157  addGeometry2(s.getObject().asLiteral());
158  }
159  }
160  it.close();
161  it= resource.listProperties(GEO.ASGEOJSON);
162  while(it.hasNext()) {
163  Statement s = it.nextStatement();
164  if ( !s.getObject().isAnon() ) {
165  addGeometryGeoJSON(s.getObject().asLiteral());
166  }
167  }
168  it.close();
169  it= resource.listProperties(GEO.LOCATION);
170  while(it.hasNext()) {
171  Statement s = it.nextStatement();
172  if ( !s.getObject().isAnon() ) {
173  addPoint(s.getObject().asResource());
174  }
175  }
176  it.close();
177  it= resource.listProperties(GEO.HASGEOMETRY);
178  while(it.hasNext()) {
179  Statement s = it.nextStatement();
180  if(s.getObject().isURIResource()) {
181  addGeometry(s.getObject().asResource());
182  }
183  }
184  it.close();
185  it= resource.listProperties(GEO.P_GEOMETRY);
186  while(it.hasNext()) {
187  Statement s = it.nextStatement();
188  if(s.getObject().isURIResource()) {
189  addGeometry(s.getObject().asResource());
190  }
191  }
192  it.close();
194  }
void addGeometry(final Resource r)
Adds a geometry described using a WKT literal.
Definition: ResourceDescription.java:141
void addGeometryGeoJSON(final Literal literall)
Adds a geometry described using a GeoJSON literal.
Definition: ResourceDescription.java:123
void addGeometry2(final Literal literall)
Adds a geometry given as a WKT literal and extracts an EPSG code if annotated.
Definition: ResourceDescription.java:99
void addPoint(final Resource r)
Adds a point described by a longitude and latitude coordinate to the list of geometries.
Definition: ResourceDescription.java:85

References ResourceDescription.addGeometry(), ResourceDescription.addGeometry2(), ResourceDescription.addGeometryGeoJSON(), ResourceDescription.addPoint(), GEO.ASGEOJSON, GEO.ASWKT, GEO.HASGEOMETRY, GEO.LOCATION, GEO.P_GEOMETRY, and ResourceDescription.resource.

Referenced by ResourceDescription.getGeoms().

◆ addGeometry()

void addGeometry ( final Resource  r)
private

Adds a geometry described using a WKT literal.

Parameters
rthe literal to analyze
141  {
142  StmtIterator it= resource.listProperties(GEO.ASWKT);
143  while(it.hasNext()) {
144  addGeometry2(it.next().getObject().asLiteral());
145  }
146  it.close();
147  }

References ResourceDescription.addGeometry2(), GEO.ASWKT, and ResourceDescription.resource.

Referenced by ResourceDescription.addAllGeoms().

◆ addGeometry2()

void addGeometry2 ( final Literal  literall)
private

Adds a geometry given as a WKT literal and extracts an EPSG code if annotated.

Parameters
literallthe literal to analyze
99  {
100  String literal=literall.getString();
101  System.out.println("Geometry2: "+literal);
102  Geometry geom;
103  try {
104  String epsgcode="";
105  if(literal.startsWith("<")) {
106  epsgcode=literal.substring(literal.indexOf('<'),literal.lastIndexOf('>')).trim();
107  epsgcode=epsgcode.substring(epsgcode.lastIndexOf('/')+1);
108  literal=literal.substring(literal.lastIndexOf('>')+1).trim();
109  }
110  geom = this.reader.read(literal);
111  if(!epsgcode.isEmpty())
112  geom.setSRID(Integer.valueOf(epsgcode));
113  geoms.add(geom);
114  } catch (ParseException e) {
115  e.printStackTrace();
116  }
117  }
List< Geometry > geoms
List of extracted geometries per resource.
Definition: ResourceDescription.java:63
WKTReader reader
WKTReader to read WKT literals.
Definition: ResourceDescription.java:67

References ResourceDescription.geoms.

Referenced by ResourceDescription.addAllGeoms(), and ResourceDescription.addGeometry().

◆ addGeometryGeoJSON()

void addGeometryGeoJSON ( final Literal  literall)
private

Adds a geometry described using a GeoJSON literal.

Parameters
literallthe literal to analyze
123  {
124  String literal=literall.getString();
125  System.out.println("GeometryGeoJSON: "+literal);
126  GeoJSONReader reader=new GeoJSONReader();
127  if(literal!=null) {
128  try {
129  Geometry geom=reader.read(literal);
130  geoms.add(geom);
131  }catch(RuntimeException e) {
132  e.printStackTrace();
133  }
134  }
135  }

References ResourceDescription.geoms, and ResourceDescription.reader.

Referenced by ResourceDescription.addAllGeoms().

◆ addPoint()

void addPoint ( final Resource  r)
private

Adds a point described by a longitude and latitude coordinate to the list of geometries.

Parameters
rthe resource to analyze
85  {
86  final Statement lngS = r.getProperty(GEO.P_LONG);
87  final Statement latS = r.getProperty(GEO.P_LAT);
88 
89  if ( lngS != null || latS != null ) {
90  geoms.add(fac.createPoint(new Coordinate(lngS.getObject().asLiteral().getDouble(),
91  latS.getObject().asLiteral().getDouble())));
92  }
93  }
GeometryFactory fac
Definition: ResourceDescription.java:68

References ResourceDescription.fac, ResourceDescription.geoms, GEO.P_LAT, and GEO.P_LONG.

Referenced by ResourceDescription.addAllGeoms().

◆ buildProperties()

List<ResourceProperty> buildProperties ( )
private
340  {
341  Map<String,PropertyBuilder> propertyBuilders =
342  new HashMap<String,PropertyBuilder>();
343  StmtIterator it = resource.listProperties();
344  while (it.hasNext()) {
345  Statement stmt = it.nextStatement();
346  if (isEmptyLiteral(stmt.getObject())) continue;
347  Property predicate = stmt.getPredicate();
348  String key = "=>" + predicate;
349  if (!propertyBuilders.containsKey(key)) {
350  propertyBuilders.put(key, new PropertyBuilder(
351  predicate, false, config.getVocabularyStore()));
352  }
353  // TODO: Should distinguish clearly here between adding a
354  // simple value, adding a complex (inlined) value, and
355  // omitting a value. But how to decide whether blank nodes
356  // are omitted or included as complex value? The decision has
357  // already been made earlier when the model was built.
358  propertyBuilders.get(key).addValue(stmt.getObject());
359  }
360  it = model.listStatements(null, null, resource);
361  while (it.hasNext()) {
362  Statement stmt = it.nextStatement();
363  Property predicate = stmt.getPredicate();
364  String key = "<=" + predicate;
365  if (!propertyBuilders.containsKey(key)) {
366  propertyBuilders.put(key, new PropertyBuilder(
367  predicate, true, config.getVocabularyStore()));
368  }
369  // TODO: See TODO above
370  propertyBuilders.get(key).addValue(stmt.getSubject());
371  }
372  for (Property p: highIndegreeProperties.keySet()) {
373  String key = "<=" + p;
374  if (!propertyBuilders.containsKey(key)) {
375  propertyBuilders.put(key, new PropertyBuilder(
376  p, true, config.getVocabularyStore()));
377  }
378  propertyBuilders.get(key).addHighDegreeArcs(highIndegreeProperties.get(p));
379  }
380  for (Property p: highOutdegreeProperties.keySet()) {
381  String key = "=>" + p;
382  if (!propertyBuilders.containsKey(key)) {
383  propertyBuilders.put(key, new PropertyBuilder(
384  p, false, config.getVocabularyStore()));
385  }
386  propertyBuilders.get(key).addHighDegreeArcs(highOutdegreeProperties.get(p));
387  }
388  List<ResourceProperty> results = new ArrayList<ResourceProperty>();
389  Iterator<PropertyBuilder> it2 = propertyBuilders.values().iterator();
390  while (it2.hasNext()) {
391  PropertyBuilder propertyBuilder = (PropertyBuilder) it2.next();
392  results.add(propertyBuilder.toProperty());
393  }
394  System.out.println("Build properties finished!");
395  Collections.sort(results);
396  return results;
397  }
VocabularyStore getVocabularyStore()
Definition: Configuration.java:281
boolean isEmptyLiteral(RDFNode node)
Checks whether a node is an empty literal that should better be skipped.
Definition: ResourceDescription.java:404

References ResourceDescription.config, Configuration.getVocabularyStore(), ResourceDescription.highIndegreeProperties, ResourceDescription.highOutdegreeProperties, ResourceDescription.isEmptyLiteral(), ResourceDescription.model, ResourceDescription.resource, and ResourceDescription.PropertyBuilder.toProperty().

Referenced by ResourceDescription.getProperties().

◆ getBestLanguageMatch()

Literal getBestLanguageMatch ( Collection< RDFNode >  nodes,
String  lang 
)
private
446  {
447  Iterator<RDFNode> it = nodes.iterator();
448  Literal aLiteral = null;
449  while (it.hasNext()) {
450  RDFNode candidate = it.next();
451  if (!candidate.isLiteral()) continue;
452  Literal literal = candidate.asLiteral();
453  if (lang == null
454  || lang.equals(literal.getLanguage())) {
455  return literal;
456  }
457  aLiteral = literal;
458  }
459  return aLiteral;
460  }

Referenced by ResourceDescription.getComment(), and ResourceDescription.getLabel().

◆ getComment()

String getComment ( )
305  {
306  Collection<RDFNode> candidates = getValuesFromMultipleProperties(config.getCommentProperties());
307  Literal l = getBestLanguageMatch(candidates, config.getDefaultLanguage());
308  if (l == null) return null;
309  return toSentenceCase(l.getLexicalForm(), l.getLanguage());
310  }
Collection< Property > getCommentProperties()
Definition: Configuration.java:241
String getDefaultLanguage()
Definition: Configuration.java:249
Collection< RDFNode > getValuesFromMultipleProperties(Collection< Property > properties)
Definition: ResourceDescription.java:430
Literal getBestLanguageMatch(Collection< RDFNode > nodes, String lang)
Definition: ResourceDescription.java:446
String toSentenceCase(String s, String lang)
Converts a string to Sentence Case.
Definition: ResourceDescription.java:749

References ResourceDescription.config, ResourceDescription.getBestLanguageMatch(), Configuration.getCommentProperties(), Configuration.getDefaultLanguage(), ResourceDescription.getValuesFromMultipleProperties(), and ResourceDescription.toSentenceCase().

Referenced by PageURLServlet.doGet().

◆ getEPSG()

String getEPSG ( )

Gets the EPSG code from a statement if it is annotated using an EPSG statement.

Returns
The EPSG code as String
212  {
213  StmtIterator it= resource.listProperties(GEO.EPSG);
214  if(it.hasNext()){
215  Statement s = it.nextStatement();
216  return s.getObject().asLiteral().getString();
217  }
218  return "";
219  }

References GEO.EPSG, and ResourceDescription.resource.

Referenced by PageURLServlet.doGet().

◆ getGeoms()

List<Geometry> getGeoms ( )

Gets the list of geometries existing at the current resource.

Returns
The list of geometries
200  {
201  if (geoms == null) {
202  geoms = new ArrayList<Geometry>();
203  addAllGeoms();
204  }
205  return geoms;
206  }
void addAllGeoms()
Adds geometries to GeoPubby considering a list of geo properties with different literal types.
Definition: ResourceDescription.java:152

References ResourceDescription.addAllGeoms(), and ResourceDescription.geoms.

Referenced by PageURLServlet.doGet().

◆ getImageURL()

String getImageURL ( )
312  {
313  Collection<RDFNode> candidates = getValuesFromMultipleProperties(config.getImageProperties());
314  Iterator<RDFNode> it = candidates.iterator();
315  while (it.hasNext()) {
316  RDFNode candidate = (RDFNode) it.next();
317  if (candidate.isURIResource()) {
318  return ((Resource) candidate.as(Resource.class)).getURI();
319  }
320  }
321  return null;
322  }
Collection< Property > getImageProperties()
Definition: Configuration.java:245
String getURI()
Definition: ResourceDescription.java:272

References ResourceDescription.config, Configuration.getImageProperties(), ResourceDescription.getURI(), and ResourceDescription.getValuesFromMultipleProperties().

Referenced by PageURLServlet.doGet().

◆ getLabel()

◆ getModel()

◆ getPrefixes()

PrefixMapping getPrefixes ( )
private

Returns a prefix mapping containing all prefixes from the input model and from the configuration, with the configuration taking precedence.

419  {
420  if (prefixes == null) {
421  prefixes = new PrefixMappingImpl();
422  prefixes.setNsPrefixes(model);
423  for (String prefix: config.getPrefixes().getNsPrefixMap().keySet()) {
424  prefixes.setNsPrefix(prefix, config.getPrefixes().getNsPrefixURI(prefix));
425  }
426  }
427  return prefixes;
428  }
PrefixMapping getPrefixes()
Definition: Configuration.java:221
PrefixMapping prefixes
Definition: ResourceDescription.java:58

References ResourceDescription.config, Configuration.getPrefixes(), ResourceDescription.model, and ResourceDescription.prefixes.

Referenced by ResourceDescription.Value.getDatatypeLabel(), ResourceDescription.getTitle(), ResourceDescription.ResourceProperty.ResourceProperty(), and ResourceDescription.Value.Value().

◆ getProperties()

List<ResourceProperty> getProperties ( )
333  {
334  if (properties == null) {
336  }
337  return properties;
338  }
List< ResourceProperty > properties
Definition: ResourceDescription.java:59
List< ResourceProperty > buildProperties()
Definition: ResourceDescription.java:340

References ResourceDescription.buildProperties(), and ResourceDescription.properties.

Referenced by PageURLServlet.doGet(), and ResourceDescription.getProperty().

◆ getProperty()

ResourceProperty getProperty ( Property  property,
boolean  isInverse 
)
324  {
325  for (ResourceProperty p: getProperties()) {
326  if (p.getURI().equals(property.getURI()) && p.isInverse() == isInverse) {
327  return p;
328  }
329  }
330  return null;
331  }
List< ResourceProperty > getProperties()
Definition: ResourceDescription.java:333

References ResourceDescription.getProperties().

Referenced by ValuesDataURLServlet.doGet(), and ValuesURLServlet.doGet().

◆ getStyle()

List<StyleObject> getStyle ( )

Gets the EPSG code from a statement if it is annotated using an EPSG statement.

Returns
The EPSG code as String
225  {
226  List<StyleObject> result=new LinkedList<StyleObject>();
227  StmtIterator it= resource.listProperties(GEO.STYLE);
228  while(it.hasNext()){
229  Statement s = it.nextStatement();
230  //if(s.getObject().isResource()) {
231  StyleObject obj=GeoModelWriter.handleStyle(s.getObject().asResource());
232  result.add(obj);
233  //}
234  }
235  return result;
236  }

References GeoModelWriter.handleStyle(), ResourceDescription.resource, and GEO.STYLE.

Referenced by PageURLServlet.doGet().

◆ getTitle()

String getTitle ( )

If getLabel() is non null, return the label.

If it is null, generate an attempt at a human-readable title from the URI. If the resource is blank, return null.

285  {
286  if (!resource.isResource()) return null;
287  Literal l = getLabel();
288  String label = l == null ? null : l.getLexicalForm();
289  String lang = l == null ? null : l.getLanguage();
290  if (label == null) {
291  label = new URIPrefixer(resource, getPrefixes()).getLocalName();
292  }
293  if ("".equals(label)) { // Prefix mapping assigns an empty local name
294  label = resource.getURI();
295  lang = null;
296  }
297  return toTitleCase(label, lang);
298  }
String toTitleCase(String s, String lang)
Converts a string to Title Case.
Definition: ResourceDescription.java:762
PrefixMapping getPrefixes()
Returns a prefix mapping containing all prefixes from the input model and from the configuration,...
Definition: ResourceDescription.java:419
Literal getLabel()
Definition: ResourceDescription.java:300

References ResourceDescription.getLabel(), URIPrefixer.getLocalName(), ResourceDescription.getPrefixes(), ResourceDescription.resource, and ResourceDescription.toTitleCase().

Referenced by ValuesDataURLServlet.doGet(), ValuesURLServlet.doGet(), DataURLServlet.doGet(), and PageURLServlet.doGet().

◆ getURI()

String getURI ( )
272  {
273  return resource.getURI();
274  }

References ResourceDescription.resource.

Referenced by ValuesURLServlet.doGet(), PageURLServlet.doGet(), and ResourceDescription.getImageURL().

◆ getValuesFromMultipleProperties()

Collection<RDFNode> getValuesFromMultipleProperties ( Collection< Property >  properties)
private
431  {
432  Collection<RDFNode> results = new ArrayList<RDFNode>();
433  Iterator<Property> it = properties.iterator();
434  while (it.hasNext()) {
435  org.apache.jena.rdf.model.Property property = (org.apache.jena.rdf.model.Property) it.next();
436  StmtIterator labelIt = resource.listProperties(property);
437  while (labelIt.hasNext()) {
438  RDFNode label = labelIt.nextStatement().getObject();
439  results.add(label);
440  }
441  }
442  return results;
443  }

References ResourceDescription.properties, and ResourceDescription.resource.

Referenced by ResourceDescription.getComment(), ResourceDescription.getImageURL(), and ResourceDescription.getLabel().

◆ isEmptyLiteral()

boolean isEmptyLiteral ( RDFNode  node)
private

Checks whether a node is an empty literal that should better be skipped.

The logic is that those literals are probably an error on the data producer side and are best not shown to the user in HTML views.

404  {
405  if (!node.isLiteral()) return false;
406  Literal l = node.asLiteral();
407  if (l.getDatatypeURI() == null ||
408  l.getDatatypeURI().startsWith(RDF.getURI()) ||
409  l.getDatatypeURI().startsWith(XSD.getURI())) {
410  if ("".equals(l.getLexicalForm())) return true;
411  }
412  return false;
413  }

Referenced by ResourceDescription.buildProperties().

◆ learnHighDegreeProperties()

void learnHighDegreeProperties ( boolean  isInverse,
int  limit 
)
private
821  {
822  CachedPropertyCollection knownHighProps = isInverse
825  Map<Property, Integer> highCounts = isInverse
828  StmtIterator it = isInverse
829  ? model.listStatements(null, null, resource)
830  : resource.listProperties();
831  Map<Property, Integer> valueCounts = new HashMap<Property, Integer>();
832  while (it.hasNext()) {
833  Property p = it.next().getPredicate();
834  if (!valueCounts.containsKey(p)) {
835  valueCounts.put(p, 0);
836  }
837  valueCounts.put(p, valueCounts.get(p) + 1);
838  }
839  for (Property p: valueCounts.keySet()) {
840  if (valueCounts.get(p) <= limit) continue;
841  knownHighProps.reportAdditional(p);
842  if (isInverse) {
843  model.removeAll(null, p, resource);
844  } else {
845  resource.removeAll(p);
846  }
847  highCounts.put(p, valueCounts.get(p));
848  }
849  }
CachedPropertyCollection getHighOutdegreeProperties()
Definition: VocabularyStore.java:123
CachedPropertyCollection getHighIndegreeProperties()
Definition: VocabularyStore.java:119

References ResourceDescription.config, VocabularyStore.getHighIndegreeProperties(), VocabularyStore.getHighOutdegreeProperties(), Configuration.getVocabularyStore(), ResourceDescription.highIndegreeProperties, ResourceDescription.highOutdegreeProperties, ResourceDescription.model, VocabularyStore.CachedPropertyCollection.reportAdditional(), and ResourceDescription.resource.

Referenced by ResourceDescription.ResourceDescription().

◆ normalizeWhitespace()

String normalizeWhitespace ( String  s,
boolean  squash 
)
private
815  {
816  s = s.replaceAll("[ \t\r\n]+", " ");
817  if (squash && " ".equals(s)) return "";
818  return s;
819  }

Referenced by ResourceDescription.toTitleCase().

◆ toSentenceCase()

String toSentenceCase ( String  s,
String  lang 
)

Converts a string to Sentence Case.

In our implementation, this simply means the first letter is uppercased if it isn't already. Also trims surrounding whitespace.

749  {
750  if (s == null) return null;
751  s = s.trim();
752  if ("".equals(s)) return null;
753  return s.substring(0, 1).toUpperCase() + s.substring(1);
754  }

Referenced by ResourceDescription.getComment().

◆ toTitleCase()

String toTitleCase ( String  s,
String  lang 
)

Converts a string to Title Case.

Also trims surrounding whitespace and collapses consecutive whitespace characters within into a single space. If the language is English or null, English rules are used. Also splits CamelCase into separate words to better deal with poor labels.

762  {
763  if (s == null) return null;
764  if (lang == null) {
765  lang = config.getDefaultLanguage();
766  }
767  s = camelCaseBoundaryPattern.matcher(s).replaceAll(" ");
768  s = s.replace(" - ", " \u2013 ");
769  Set<String> uncapitalizedWords = Collections.emptySet();
770  if (lang == null || "".equals(lang) || english.matcher(lang).matches()) {
771  uncapitalizedWords = englishUncapitalizedWords;
772  }
773  StringBuffer result = new StringBuffer();
774  Matcher matcher = wordPattern.matcher(s);
775  boolean first = true;
776  int offset = 0;
777  while (matcher.find()) {
778  result.append(normalizeWhitespace(
779  s.substring(offset, matcher.start()), first));
780  offset = matcher.end();
781  String word = matcher.group();
782  if ("".equals(word)) continue;
783  /*if (first || !uncapitalizedWords.contains(word.toLowerCase())) {
784  word = word.substring(0, 1).toUpperCase() + word.substring(1);
785  } else {
786  word = word.substring(0, 1).toLowerCase() + word.substring(1);
787  }*/
788  result.append(word);
789  first = false;
790  }
791  result.append(normalizeWhitespace(
792  s.substring(offset), true));
793  return result.toString();
794  }
static Pattern camelCaseBoundaryPattern
Definition: ResourceDescription.java:796
static Pattern wordPattern
Definition: ResourceDescription.java:795
static Set< String > englishUncapitalizedWords
Definition: ResourceDescription.java:800
String normalizeWhitespace(String s, boolean squash)
Definition: ResourceDescription.java:815
static Pattern english
Definition: ResourceDescription.java:799

References ResourceDescription.camelCaseBoundaryPattern, ResourceDescription.config, ResourceDescription.english, ResourceDescription.englishUncapitalizedWords, Configuration.getDefaultLanguage(), ResourceDescription.normalizeWhitespace(), and ResourceDescription.wordPattern.

Referenced by ResourceDescription.ResourceProperty.getInverseLabel(), ResourceDescription.Value.getLabel(), ResourceDescription.ResourceProperty.getLabel(), and ResourceDescription.getTitle().

Member Data Documentation

◆ camelCaseBoundaryPattern

Pattern camelCaseBoundaryPattern
staticprivate
Initial value:
= Pattern.compile(
"(?<=(\\p{javaLowerCase}|\\p{javaUpperCase})\\p{javaLowerCase})" +
"(?=\\p{javaUpperCase})")

Referenced by ResourceDescription.toTitleCase().

◆ config

◆ english

Pattern english = Pattern.compile("^en(-.*)?$", Pattern.CASE_INSENSITIVE)
staticprivate

◆ englishUncapitalizedWords

Set<String> englishUncapitalizedWords
staticprivate
Initial value:
=
new HashSet<String>(Arrays.asList(
"above", "about", "across", "against", "along", "among",
"around", "at", "before", "behind", "below", "beneath",
"beside", "between", "beyond", "by", "down", "during",
"except", "for", "from", "in", "inside", "into", "like",
"near", "of", "off", "on", "since", "to", "toward",
"through", "under", "until", "up", "upon", "with", "within",
"a", "an", "the",
"and", "but", "for", "nor", "or", "so", "yet"
))

Referenced by ResourceDescription.toTitleCase().

◆ fac

GeometryFactory fac =new GeometryFactory()
private

◆ geoms

List<Geometry> geoms
private

◆ HIGH_DEGREE_CUTOFF

final int HIGH_DEGREE_CUTOFF = 10
staticprivate

◆ highIndegreeProperties

final Map<Property, Integer> highIndegreeProperties
private

◆ highOutdegreeProperties

final Map<Property, Integer> highOutdegreeProperties
private

◆ hypermediaResource

final HypermediaControls hypermediaResource
private

◆ model

◆ prefixes

PrefixMapping prefixes = null
private

◆ properties

◆ reader

WKTReader reader =new WKTReader()
private

WKTReader to read WKT literals.

Referenced by ResourceDescription.addGeometryGeoJSON().

◆ resource

◆ wordPattern

Pattern wordPattern = Pattern.compile("[^ \t\r\n-]+|")
staticprivate