GeoPubby  Version 0.1.0.0
VocabularyStore.I18nStringValueCache Class Reference
Inheritance diagram for VocabularyStore.I18nStringValueCache:
Collaboration diagram for VocabularyStore.I18nStringValueCache:

Package Functions

 I18nStringValueCache (Property p, boolean inverse)
 
Literal get (String iri, String preferredLang)
 
Literal getCached (String iri, String preferredLang)
 
Collection< Literal > pickBestValue (Set< RDFNode > candidates)
 
get (String iri)
 
getCached (String iri)
 

Private Member Functions

Literal getBestMatch (Collection< Literal > candidates, String preferredLang)
 
int getMatchLength (String langTag1, String langTag2)
 
pickBestFromModel (Model m, String iri)
 
Set< RDFNode > getValues (Resource r)
 
Set< RDFNode > getInverseValues (Resource r)
 

Private Attributes

final Property property
 
final boolean inverse
 
final Map< String, K > cache
 

Constructor & Destructor Documentation

◆ I18nStringValueCache()

I18nStringValueCache ( Property  p,
boolean  inverse 
)
package
223  {
224  super (p, inverse);
225  }
final boolean inverse
Definition: VocabularyStore.java:155

References VocabularyStore.ValueCache< Collection< Literal > >.inverse.

Member Function Documentation

◆ get() [1/2]

K get ( String  iri)
packageinherited
162  {
163  if (cache.containsKey(iri)) {
164  return cache.get(iri);
165  }
166  K best = null;
167  if (dataSource.canDescribe(iri)) {
168  best = pickBestFromModel(dataSource.describeResource(iri), iri);
169  }
170  cache.put(iri, best);
171  return best;
172  }
K pickBestFromModel(Model m, String iri)
Definition: VocabularyStore.java:176
final Map< String, K > cache
Definition: VocabularyStore.java:156

◆ get() [2/2]

Literal get ( String  iri,
String  preferredLang 
)
package
227  {
228  return getBestMatch(get(iri), preferredLang);
229  }
Literal getBestMatch(Collection< Literal > candidates, String preferredLang)
Definition: VocabularyStore.java:233

References VocabularyStore.I18nStringValueCache.getBestMatch().

Referenced by VocabularyStore.getDescription(), VocabularyStore.getInverseLabel(), and VocabularyStore.getLabel().

◆ getBestMatch()

Literal getBestMatch ( Collection< Literal >  candidates,
String  preferredLang 
)
private
233  {
234  if (candidates == null) return null;
235  Literal bestMatch = null;
236  int bestMatchLength = -1;
237  for (Literal l: candidates) {
238  int matchLength = getMatchLength(l.getLanguage(), preferredLang);
239  if (matchLength >= bestMatchLength) {
240  bestMatch = l;
241  bestMatchLength = matchLength;
242  }
243  }
244  return bestMatch;
245  }
int getMatchLength(String langTag1, String langTag2)
Definition: VocabularyStore.java:246

References VocabularyStore.I18nStringValueCache.getMatchLength().

Referenced by VocabularyStore.I18nStringValueCache.get(), and VocabularyStore.I18nStringValueCache.getCached().

◆ getCached() [1/2]

K getCached ( String  iri)
packageinherited
173  {
174  return cache.get(iri);
175  }

◆ getCached() [2/2]

Literal getCached ( String  iri,
String  preferredLang 
)
package
230  {
231  return getBestMatch(getCached(iri), preferredLang);
232  }
Literal getCached(String iri, String preferredLang)
Definition: VocabularyStore.java:230

References VocabularyStore.I18nStringValueCache.getBestMatch().

Referenced by VocabularyStore.getCachedLabel().

◆ getInverseValues()

Set<RDFNode> getInverseValues ( Resource  r)
privateinherited
189  {
190  Set<RDFNode> nodes = new HashSet<RDFNode>();
191  StmtIterator it = r.listProperties(OWL.inverseOf);
192  while (it.hasNext()) {
193  RDFNode object = it.next().getObject();
194  if (!object.isResource()) continue;
195  StmtIterator it2 = object.asResource().listProperties(property);
196  while (it2.hasNext()) {
197  nodes.add(it2.next().getObject());
198  }
199  }
200  return nodes;
201  }
final Property property
Definition: VocabularyStore.java:154

◆ getMatchLength()

int getMatchLength ( String  langTag1,
String  langTag2 
)
private
246  {
247  // TODO: This is very dodgy. It reports a decent match between "xx" and "xxx". Requires some research to do properly.
248  int i = 0;
249  while (i < langTag1.length() && i < langTag2.length()) {
250  char c1 = langTag1.charAt(i);
251  char c2 = langTag2.charAt(i);
252  if (Character.toLowerCase(c1) != Character.toLowerCase(c2)) break;
253  i++;
254  }
255  return i;
256  }

Referenced by VocabularyStore.I18nStringValueCache.getBestMatch().

◆ getValues()

Set<RDFNode> getValues ( Resource  r)
privateinherited
181  {
182  Set<RDFNode> nodes = new HashSet<RDFNode>();
183  StmtIterator it = r.listProperties(property);
184  while (it.hasNext()) {
185  nodes.add(it.next().getObject());
186  }
187  return nodes;
188  }

◆ pickBestFromModel()

K pickBestFromModel ( Model  m,
String  iri 
)
privateinherited
176  {
177  Resource r = m.getResource(iri);
178  Set<RDFNode> nodes = inverse ? getInverseValues(r) : getValues(r);
179  return pickBestValue(nodes);
180  }
Set< RDFNode > getValues(Resource r)
Definition: VocabularyStore.java:181
Set< RDFNode > getInverseValues(Resource r)
Definition: VocabularyStore.java:189

◆ pickBestValue()

Collection<Literal> pickBestValue ( Set< RDFNode >  candidates)
package
259  {
260  Collection<Literal> result = new ArrayList<Literal>(candidates.size());
261  for (RDFNode node: candidates) {
262  if (!node.isLiteral()) continue;
263  Literal l = node.asLiteral();
264  String dt = l.getDatatypeURI();
265  if (dt == null || dt.equals(XSD.xstring.getURI()) || dt.equals(RDF.getURI() + "langString")) {
266  result.add(l);
267  }
268  }
269  return result;
270  }

Member Data Documentation

◆ cache

final Map<String, K> cache
privateinherited

◆ inverse

final boolean inverse
privateinherited

◆ property

final Property property
privateinherited