Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.Literal


    Literal getCached(String iri, String preferredLang) {
      return getBestMatch(getCached(iri), preferredLang);
    }
    private Literal getBestMatch(Collection<Literal> candidates, String preferredLang) {
      if (candidates == null) return null;
      Literal bestMatch = null;
      int bestMatchLength = -1;
      for (Literal l: candidates) {
        int matchLength = getMatchLength(l.getLanguage(), preferredLang);
        if (matchLength >= bestMatchLength) {
          bestMatch = l;
View Full Code Here


    @Override
    Collection<Literal> pickBestValue(Set<RDFNode> candidates) {
      Collection<Literal> result = new ArrayList<Literal>(candidates.size());
      for (RDFNode node: candidates) {
        if (!node.isLiteral()) continue;
        Literal l = node.asLiteral();
        String dt = l.getDatatypeURI();
        if (dt == null || dt.equals(XSD.xstring.getURI()) || dt.equals(RDF.getURI() + "langString")) {
          result.add(l);
        }
      }
      return result;
View Full Code Here

   * generate an attempt at a human-readable title from the URI. If the
   * resource is blank, return null.
   */
  public String getTitle() {
    if (!resource.isResource()) return null;
    Literal l = getLabel();
    String label = l == null ? null : l.getLexicalForm();
    String lang = l == null ? null : l.getLanguage();
    if (label == null) {
      label = new URIPrefixer(resource, getPrefixes()).getLocalName();
    }
    if ("".equals(label)) { // Prefix mapping assigns an empty local name
      label = resource.getURI();
View Full Code Here

    return getBestLanguageMatch(candidates, config.getDefaultLanguage());
  }
 
  public String getComment() {
    Collection<RDFNode> candidates = getValuesFromMultipleProperties(config.getCommentProperties());
    Literal l = getBestLanguageMatch(candidates, config.getDefaultLanguage());
    if (l == null) return null;
    return toSentenceCase(l.getLexicalForm(), l.getLanguage());
  }
View Full Code Here

   * 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.
   */
  private boolean isEmptyLiteral(RDFNode node) {
    if (!node.isLiteral()) return false;
    Literal l = node.asLiteral();
    if (l.getDatatypeURI() == null ||
        l.getDatatypeURI().startsWith(RDF.getURI()) ||
        l.getDatatypeURI().startsWith(XSD.getURI())) {
      if ("".equals(l.getLexicalForm())) return true;
    }
    return false;
  }
View Full Code Here

  }
 
  // TODO: There is some better (?) code doing the same in VocabularyStore.I18nStringValueCache
  private Literal getBestLanguageMatch(Collection<RDFNode> nodes, String lang) {
    Iterator<RDFNode> it = nodes.iterator();
    Literal aLiteral = null;
    while (it.hasNext()) {
      RDFNode candidate = it.next();
      if (!candidate.isLiteral()) continue;
      Literal literal = candidate.asLiteral();
      if (lang == null
          || lang.equals(literal.getLanguage())) {
        return literal;
      }
      aLiteral = literal;
    }
    return aLiteral;
View Full Code Here

    }
    public String getLabel() {
      return getLabel(isMultiValued());
    }
    public String getLabel(boolean preferPlural) {
      Literal label = vocabularyStore.getLabel(predicate.getURI(), preferPlural);
      if (label == null) return null;
      return toTitleCase(label.getLexicalForm(), label.getLanguage());
    }
View Full Code Here

    }
    public String getInverseLabel() {
      return getInverseLabel(isMultiValued());
    }
    public String getInverseLabel(boolean preferPlural) {
      Literal label = vocabularyStore.getInverseLabel(predicate.getURI(), preferPlural);
      if (label == null) return null;
      return toTitleCase(label.getLexicalForm(), label.getLanguage());
    }
View Full Code Here

      }
      return prefixer.getLocalName();
    }
    public String getLabel() {
      if (!node.isResource()) return null;
      Literal result = null;
      if (node.isURIResource()) {
        if (predicate.equals(RDF.type)) {
          // Look up class labels in vocabulary store
          result = vocabularyStore.getLabel(node.asNode().getURI(), false);
        } else if (node.isURIResource()) {
          // If it's not a class, see if we happen to have a label cached
          result = vocabularyStore.getCachedLabel(node.asResource().getURI(), false);
        }
      }
      if (result == null) {
        // Use any label that may be included in the description model
        result = new ResourceDescription(node.asResource(), model, config).getLabel();
      }
      if (result == null) return null;
      return toTitleCase(result.getLexicalForm(), result.getLanguage());
    }
View Full Code Here

    }
   
    String creationDate = node.toString();
    String version = _getVersionFromCreationDate(creationDate);
    if ( version != null ) {
      Literal versionLit = ResourceFactory.createPlainLiteral(version);
      ontology.setPropertyValue(Omv.version, versionLit);
      return version;
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.Literal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.