@Override
 public Triple createValue() {
   System.out.println("selfdebug: create Triple value");
   Triple returnable = new Triple(Node.createAnon(), Node.createAnon(), Node.createAnon());
   System.out.println("selfdebug: Triple created");
   return returnable;
 }
Ejemplo n.º 2
0
  /**
   * Gets the Jena node for given NXRelations Node instance.
   *
   * @param nuxNode NXrelations Node instance
   * @return Jena node instance
   */
  private static com.hp.hpl.jena.graph.Node getJenaNode(Node nuxNode) {
    if (nuxNode == null) {
      return null;
    }

    com.hp.hpl.jena.graph.Node jenaNodeInst;
    if (nuxNode.isBlank()) {
      Blank blank = (Blank) nuxNode;
      String id = blank.getId();
      if (id == null) {
        jenaNodeInst = com.hp.hpl.jena.graph.Node.createAnon();
      } else {
        jenaNodeInst = com.hp.hpl.jena.graph.Node.createAnon(new AnonId(id));
      }
    } else if (nuxNode.isLiteral()) {
      Literal lit = (Literal) nuxNode;
      String value = lit.getValue();
      if (value == null) {
        throw new IllegalArgumentException(String.format("Invalid literal node %s", nuxNode));
      }
      String language = lit.getLanguage();
      String type = lit.getType();
      if (language != null) {
        jenaNodeInst = com.hp.hpl.jena.graph.Node.createLiteral(value, language, false);
      } else if (type != null) {
        jenaNodeInst =
            com.hp.hpl.jena.graph.Node.createLiteral(value, null, new BaseDatatype(type));
      } else {
        jenaNodeInst = com.hp.hpl.jena.graph.Node.createLiteral(value);
      }
    } else if (nuxNode.isResource()) {
      Resource resource = (Resource) nuxNode;
      String uri = resource.getUri();
      jenaNodeInst = com.hp.hpl.jena.graph.Node.createURI(uri);

    } else {
      throw new IllegalArgumentException(String.format("Invalid NXRelations node %s", nuxNode));
    }
    return jenaNodeInst;
  }
Ejemplo n.º 3
0
  /**
   * Convert a Mulgara Value to a Jena graph node.
   *
   * @param obj The Mulgara value to convert.
   * @return A new Jena graph node.
   */
  static Node o2n(org.jrdf.graph.Node obj) {
    if (obj == null) return Node.ANY;

    // testing for org.jrdf.graph.URIReference
    if (obj.isURIReference()) {
      URIReference uRef = (URIReference) obj;
      if (skolemizedBlankNodes) {
        String x = uRef.getURI().toString();
        if (x.startsWith(bNodeScheme)) {
          x = x.substring(bNodeScheme.length());
          Node n = Node.createAnon(new AnonId(x));
          return n;
        }
      }
      return Node.createURI(uRef.getURI().toString());
    }

    // testing for org.jrdf.graph.Literal
    if (obj.isLiteral()) {
      Literal literal = (Literal) obj;
      if (literal.getDatatypeURI() != null) {
        RDFDatatype type =
            TypeMapper.getInstance().getSafeTypeByName(literal.getDatatypeURI().toString());
        return Node.createLiteral(literal.getLexicalForm(), null, type);
      }

      return Node.createLiteral(literal.getLexicalForm(), literal.getLanguage(), null);
    }

    if (obj.isBlankNode()) {
      BlankNodeImpl b = (BlankNodeImpl) obj;
      // check if this was a Jena-allocated node
      Node jenaNode = valuesToNodes.get(b);
      // if not known, then create a Jena node from the Mulgara ID
      return jenaNode != null ? jenaNode : Node.createAnon(new AnonId(b.getID()));
    }
    throw new RuntimeException("Can't convert to Jena Node : " + obj);
  }
 @Override
 public Node create(String label) {
   String strLabel = "mrbnode_" + runId.hashCode() + "_" + path.hashCode() + "_" + label;
   log.debug("create({}) = {}", label, strLabel);
   return Node.createAnon(new AnonId(strLabel));
 }