Java Code Examples for org.apache.jena.graph.NodeFactory#createBlankNode()

The following examples show how to use org.apache.jena.graph.NodeFactory#createBlankNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RDFPatchReaderBinary.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
public static Node fromThrift(RDF_Term term) {
    if ( term.isSetIri() )
        return NodeFactory.createURI(term.getIri().getIri());

    if ( term.isSetBnode() )
        return NodeFactory.createBlankNode(term.getBnode().getLabel());

    if ( term.isSetLiteral() ) {
        RDF_Literal lit = term.getLiteral();
        String lex = lit.getLex();
        String dtString = null;
        if ( lit.isSetDatatype() )
            dtString = lit.getDatatype();
        RDFDatatype dt = NodeFactory.getType(dtString);

        String lang = lit.getLangtag();
        return NodeFactory.createLiteral(lex, lang, dt);
    }

    throw new PatchException("No conversion to a Node: "+term.toString());
}
 
Example 2
Source File: RdflintParserRdfxml.java    From rdflint with MIT License 5 votes vote down vote up
private Node convert(AResource r) {
  if (!r.isAnonymous()) {
    // URI.
    String uriStr = r.getURI();
    if (errorForSpaceInURI) {
      // Special check for spaces in a URI.
      // Convert to an error like TokernizerText.
      if (uriStr.contains(" ")) {
        int i = uriStr.indexOf(' ');
        String s = uriStr.substring(0, i);
        String msg = String.format("Bad character in IRI (space): <%s[space]...>", s);
        int line = arp.getLocator().getLineNumber();
        int col = arp.getLocator().getColumnNumber();
        riotErrorHandler.error(msg, line, col);// NOPMD
        throw new RiotParseException(msg, line, col);
      }
    }
    return NodeFactory.createURI(uriStr);
  }

  // String id = r.getAnonymousID();
  Node rr = (Node) r.getUserData();
  if (rr == null) {
    rr = NodeFactory.createBlankNode();
    r.setUserData(rr);
  }
  return rr;
}
 
Example 3
Source File: RDFPatchReaderText.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private static Node tokenToNode(Token token) {
    if ( token.isIRI() )
        // URI or <_:...>
        return RiotLib.createIRIorBNode(token.getImage());
    if ( token.isBNode() ) {
        // Blank node as _:...
        String label = token.getImage().substring(bNodeLabelStart.length());
        return NodeFactory.createBlankNode(label);
    }
    Node node = token.asNode();
    if ( node == null )
        throw exception(token, "Expect a Node, got %s",token);
    return node;
}
 
Example 4
Source File: ContextUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private static void createListNodes(final Map<Node_List, Node[]> listNodes, final Node_List list, final int size) {
	Node[] nodes = new Node[size + 1];
	for (int i = 0; i < size; i++) {
		nodes[i] = NodeFactory.createBlankNode();
	}
	nodes[size] = RDF.nil.asNode();
	listNodes.put(list, nodes);
}
 
Example 5
Source File: JSFactory.java    From shacl with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public static Node getNode(Object obj) {
	if(obj == null) {
		return null;
	}
	else if(obj instanceof JSTerm) {
		return ((JSTerm)obj).getNode();
	}
	else if(obj instanceof Map) {
		Map som = (Map) obj;
		String value = (String) som.get(VALUE);
		if(value == null) {
			throw new IllegalArgumentException("Missing value");
		}
		String termType = (String) som.get(TERM_TYPE);
		if(NAMED_NODE.equals(termType)) {
			return NodeFactory.createURI(value);
		}
		else if(BLANK_NODE.equals(termType)) {
			return NodeFactory.createBlankNode(value);
		}
		else if(LITERAL.equals(termType)) {
			String lang = (String) som.get(LANGUAGE);
			Map dt = (Map)som.get(DATATYPE);
			String dtURI = (String)dt.get(VALUE);
			RDFDatatype datatype = TypeMapper.getInstance().getSafeTypeByName(dtURI);
			return NodeFactory.createLiteral(value, lang, datatype);
		}
		else {
			throw new IllegalArgumentException("Unsupported term type " + termType);
		}
	}
	else {
		return null;
	}
}
 
Example 6
Source File: TermFactory.java    From shacl with Apache License 2.0 4 votes vote down vote up
public JSBlankNode blankNode(String value) {
	Node node = value == null ?
			NodeFactory.createBlankNode() :
			NodeFactory.createBlankNode(value);
	return new JSBlankNode(node);
}