コード例 #1
0
  public static Byte node2Byte(Node node) {
    if (node == null) return null;

    if (node instanceof PlainLiteral) {
      return toByte(node.asLiteral());
    }

    if (node instanceof LanguageTagLiteral) {
      throw new RDFDataException(
          "Cannot convert a language tagged literal to an Byte - it makes no sense");
    }

    if (node instanceof DatatypeLiteral) {
      URI datatype = node.asDatatypeLiteral().getDatatype();
      if (datatype.equals(XSD._byte)) {
        return toByte(node.asDatatypeLiteral());
      } else {
        throw new RDFDataException("Cannot convert from datatype " + datatype + " to URI");
      }
    }

    throw new RDFDataException("Cannot convert from " + node.getClass() + " to Byte");
  }
コード例 #2
0
  /**
   * Take a URI and generate a legal and unique Java Bean Identifier from it.
   *
   * @param uriOrBlankNode - URI or BlankNode for which a bean identifiers has to be created.
   * @param usedNames - Set of already used bean identifiers
   * @return a legal and unique Java Bean Identifier
   */
  public static String uri2beanname(Object uriOrBlankNode, Set<String> usedNames) {

    if (uriOrBlankNode instanceof BlankNode) {
      return "blankNode";
      // TODO create names for anonymous resource
      // throw new RuntimeException(
      // "Cannot create names for anonymous resources (yet)");
    }

    URI uri = (URI) uriOrBlankNode;

    String rawname;
    if (uri != null) {
      if (getLocalPart(uri.toString()) != null) {
        rawname = getLocalPart(uri.toString());
      } else {
        rawname = uri.toString();
      }
    } else {
      // generate name! only needed for blank nodes
      rawname = "genBean" + System.currentTimeMillis();
    }

    // remove preceeding 'has'
    if (rawname.toLowerCase().startsWith("has") && rawname.length() > 3) {
      rawname = rawname.substring(3);
    }

    // make rawname bean-style
    String beanname = toLegalJavaIdentifier(rawname);

    // now we have a nice bean name - but is it unique?
    if (usedNames.contains(beanname)) {

      // TODO check when this happens and deal better with it
      if (uri == null) {
        throw new IllegalStateException("");
      }

      // try to use namespace prefix for disambiguation
      String namespacePrefix = guessNSPrefix(uri.toString());
      String prefixedBeanName = toLegalJavaIdentifier(namespacePrefix + beanname);
      if (usedNames.contains(prefixedBeanName)) {
        // fallback to plain uri
        beanname = toLegalJavaIdentifier(uri.toString());
      } else {
        beanname = prefixedBeanName;
      }
    }

    return beanname;
  }
コード例 #3
0
ファイル: SubjectFilter.java プロジェクト: WorkshopRVL/rvl
  /**
   * @return - A string of SPARQL statements that can be used in a SPARQL query to restrict the
   *     variable "?s"
   * @throws UnsupportedSelectorTypeException
   */
  public String getFilterString() throws UnsupportedSelectorTypeException {

    String selectorSPARQLString;
    Literal selector = pm.getSubjectFilter();
    URI selectorType = getSelectorType(selector);

    String selectorValue = selector.getValue();
    String filterSubjectVarString = "?s";

    LOGGER.info("Processing selector type " + selectorType);

    if (selectorType.toString().equals("http://purl.org/rvl/fslSelector")) {

      // RVLs basic "fsl selector"

      String[] fslParts = selectorValue.split("::");
      URI filterPredicate = new URIImpl(fslParts[0]).asURI();
      URI filterObject = new URIImpl(fslParts[1]).asURI();

      selectorSPARQLString =
          filterSubjectVarString
              + " "
              + filterPredicate.toSPARQL()
              + " "
              + filterObject.toSPARQL()
              + " . "
              + " FILTER( ?s !="
              + filterObject.toSPARQL()
              + ") "; // HACK: we exclude reflexive occurences for now to avoid showing classes
                      // being the subclass of itself ...

    } else if (selectorType.toString().equals("http://purl.org/rvl/sparqlSelector")) {

      // RVLs basic "sparql selector"

      selectorSPARQLString = selectorValue;

    } else if (selectorType.toString().equals("http://purl.org/rvl/classSelector")) {

      // default: class selector (a class name is expected)
      // will be interpreted as a constraint on the type of resources

      selectorSPARQLString =
          filterSubjectVarString
              + " "
              + RDF.type.toSPARQL()
              + " "
              + new URIImpl(selectorValue).asResource().toSPARQL()
              + " . ";
    } else {

      throw new UnsupportedSelectorTypeException(
          "The selector type " + selectorType + " is noty yet supported.");
    }

    LOGGER.info(
        "Applying subject filter. Only resources matching "
            + selectorSPARQLString
            + " will be affected by the mapping "
            + "(and thus shown, which is not the default behavior --> TODO!)");

    return selectorSPARQLString;
  }
コード例 #4
0
ファイル: DefaultOntologies.java プロジェクト: conwetlab/fast
 /**
  * return true, if the ontology identified by the passed URI is a default ontology
  *
  * @param ontologyUri a ontology URI
  * @return true, if this is a default ontology
  */
 public static boolean containsOntologyUri(URI ontologyUri) {
   for (Ontology o : defaults) {
     if (o.uri.equals(ontologyUri.toString())) return true;
   }
   return false;
 }