public static AnonId create( String id ) { return new AnonId( id ); }
/** Answer the label of this blank node or throw an UnsupportedOperationException if it's not blank. */ public String getBlankNodeLabel() { return getBlankNodeId().getLabelString(); }
/** * Parses the given input as a blank node. * * @param blankNodeAsString the blank node string value. * @return the {@link Node} Blank node representation of the given value. */ private static Node internalAsBlankNode(final String blankNodeAsString) { return NodeFactory.createAnon(AnonId.create(blankNodeAsString.substring(2))); }
@Override public Collection<Node> listObjects(Node subject, Node property) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && subject.isURI() && subject.getURI().startsWith(bnodePrefix)){ subject = NodeFactory.createAnon(new AnonId(subject.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(subject, property, null); while(it.hasNext()){ //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation Node object = it.next().getObject(); if(bnodePrefix != null && object.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(object.getBlankNodeId().getLabelString()); object = NodeFactory.createURI(sb.toString()); } nodes.add(object); } it.close(); return nodes; } @Override
protected static String anonName(AnonId id) { String name = "_:A"; String sid = id.toString(); for (int i = 0; i < sid.length(); i++) { char c = sid.charAt(i); if (c == 'X') { name = name + "XX"; } else if (Character.isLetterOrDigit(c)) { name = name + c; } else { name = name + "X" + Integer.toHexString(c) + "X"; } } return name; } }
@Override public Collection<Node> listSubjects(Node property, Node object) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && object.isURI() && object.getURI().startsWith(bnodePrefix)){ object = NodeFactory.createAnon(new AnonId(object.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(null, property, object); while(it.hasNext()){ Node subject = it.next().getSubject(); //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation if(bnodePrefix != null && subject.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(subject.getBlankNodeId().getLabelString()); subject = NodeFactory.createURI(sb.toString()); } nodes.add(subject); } it.close(); return nodes; } /**
/** * Find a name to give a resource */ public static String getNameFor(Resource r) { String label = getStringValue(r, RDFS.label); if (label != null) return label; if (r.isURIResource()) { String uri = r.getURI(); int split = uri.lastIndexOf('#'); if (split == -1) split = uri.lastIndexOf('/'); return uri.substring(split + 1); } else { return r.getId().toString(); } }
public static AnonId create() { return new AnonId(); }
protected String genStringForNode(Node n) { if ( bNodesAsFakeURIs && n.isBlank() ) return "<_:"+n.getBlankNodeId().getLabelString()+">" ; return prefixString+(bNodeCounter++) ; }
@Override public Collection<Node> listObjects(Node subject, Node property) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && subject.isURI() && subject.getURI().startsWith(bnodePrefix)){ subject = NodeFactory.createAnon(new AnonId(subject.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(subject, property, null); while(it.hasNext()){ //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation Node object = it.next().getObject(); if(bnodePrefix != null && object.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(object.getBlankNodeId().getLabelString()); object = NodeFactory.createURI(sb.toString()); } nodes.add(object); } it.close(); return nodes; } @Override
/** make a blank node with a fresh anon id */ public static Node createAnon() { return createAnon( AnonId.create() ); }
private String longAnonId(Resource r) { String rid = r.getId().toString(); return XMLChar.isValidNCName( rid ) ? rid : escapedId( rid ); }
public Node create(String label) { String $ = format("B0x%04X", ++counter) ; return Node.createAnon(new AnonId($)) ; }
protected String genStringForNode(Node n) { if ( bNodesAsFakeURIs && n.isBlank() ) return "<_:"+n.getBlankNodeId().getLabelString()+">" ; return prefixString+(bNodeCounter++) ; }
@Override public Collection<Node> listSubjects(Node property, Node object) { Collection<Node> nodes = new ArrayList<Node>(); if(bnodePrefix != null && object.isURI() && object.getURI().startsWith(bnodePrefix)){ object = NodeFactory.createAnon(new AnonId(object.getURI().substring(bnodePrefix.length()))); } ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(null, property, object); while(it.hasNext()){ Node subject = it.next().getSubject(); //STANBOL-765: we need also to transform bnodes to URIs for the //RDFBackend implementation if(bnodePrefix != null && subject.isBlank()){ StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(subject.getBlankNodeId().getLabelString()); subject = NodeFactory.createURI(sb.toString()); } nodes.add(subject); } it.close(); return nodes; } /**
private void boostrap(List<Variable> variables) { for(Variable variable:variables) { Resource blankNode = this.model.createResource(AnonId.create(variable.name())); this.pendingResources.add(blankNode); this.resourceTarget.put(blankNode, variable); } }
/** * @return A name for the resource. By preference, this will be a label property * of the resource. Otherwise, a curie or localname will be used if no naming property is found. * Special cases for displaying names of nodes with no labels in Elda: * <ul> * <li>if the name would otherwise be empty, and the URI ends with `.../` or `.../-`, * use the preceding path segment</li> * <li>if the name would otherwise be empty, and the node is a bNode, use the anon-ID</li> * <li>if the name would otherwise be empty, use the full URI</li> * </ul> */ @Override public String getName() { String name = super.getName(); if (name.isEmpty() || name.matches("^\\s*$") || name.equals( getURI() )) { if (isAnon()) { name = asRDFNode().asResource().getId().toString(); } else { Matcher match = lnmatch.matcher(getURI()); if (match.matches()) { name = match.group(1); } else { name = getURI(); } } } return name; }
@Override public Node create() { String label = SysRIOT.BNodeGenIdPrefix + (counter.getAndIncrement()) ; return NodeFactory.createAnon(new AnonId(label)) ; } }
/** * Used to create the Representation the first time * {@link #getRepresentation()} is called for the current entity. The * information for the Representation are already stored in {@link #data} */ private Representation createRepresentation() { final String uri; if(currentEntity.isBlank()){ //STANBOL-765: support bNodes StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(currentEntity.getBlankNodeId().getLabelString()); uri = sb.toString(); } else { uri = currentEntity.getURI(); } Representation representation = vf.createRepresentation(uri); Iterator<Node> it = data.iterator(); while(it.hasNext()){ //data contains field,value pairs //because of that we call two times next for String field = it.next().getURI(); //the field Node value = it.next();//and the value processValue(value, representation, field); } return representation; } }
/** * Since STANBOL-765 BlankNodes are converted to URIs if a {@link #bnodePrefix} * is configured. This also means that one needs to expect calls to the * {@link RDFBackend} interface with transformed Nodes. <p> * This method ensures that if someone requests an uri {@link Node} for a * URI that represents a transformed Bnode (when the URI starts with * {@link #bnodePrefix}) that the according bnode {@link Node} is created * @param node the node * @return */ @Override public Node createURI(String uri) { if(bnodePrefix != null && uri.startsWith(bnodePrefix)){ return NodeFactory.createAnon(AnonId.create(uri.substring(bnodePrefix.length()))); } else { return super.createURI(uri); } } /**