/** Answer the label of this blank node or throw an UnsupportedOperationException if it's not blank. */ public String getBlankNodeLabel() { return getBlankNodeId().getLabelString(); }
protected String genStringForNode(Node n) { if ( bNodesAsFakeURIs && n.isBlank() ) return "<_:"+n.getBlankNodeId().getLabelString()+">" ; return prefixString+(bNodeCounter++) ; }
protected String genStringForNode(Node n) { if ( bNodesAsFakeURIs && n.isBlank() ) return "<_:"+n.getBlankNodeId().getLabelString()+">" ; return prefixString+(bNodeCounter++) ; }
/** * 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; } }
/** * @param type * Whether statements to retrieve are anonymous or named. * @return A list of internal ID or URI (depending on <code>type</code>) representing every reified statements in the model */ public List<String> listReifiedStatements(final ResourceTypes type) { final List<String> idsOrUris = new ArrayList<String>(); if (type.equals(ResourceTypes.ANON)) { for (final ReifiedStatement rs : this.listReifStats(type)) { idsOrUris.add(rs.getId().getLabelString()); } } else if (type.equals(ResourceTypes.NAMED)) { for (final ReifiedStatement rs : this.listReifStats(type)) { idsOrUris.add(rs.getURI()); } } else { LogFactory.getLog(this.getClass()).warn("Error in listReifiedStatement " + "ResourceType was neither an " + "anon nor a named resource..."); } return idsOrUris; }
@Override protected void consumeResource(FilterBuilder builder, Resource resource) { builder.withVariable(ProtocolFactory.newVariable(resource.getId().getLabelString())); } }
/** * @param resType * The type of the resources to retrieve, i.e. named or anonymous one. * @return A <code>Set</code> of URIs or internal IDs resources that are subjects of statements in this model. */ protected Set<String> getSubjects(final ResourceTypes resType) { final List<Statement> stats = this.listStatements(); final HashSet<String> subjs = new HashSet<String>(); for (final Statement stat : stats) { final Resource subj = stat.getSubject(); if (resType.equals(ResourceTypes.NAMED) && subj.isURIResource()) { subjs.add(subj.getURI()); } else if (resType.equals(ResourceTypes.ANON) && subj.isAnon()) { subjs.add(subj.getId().getLabelString()); } } return subjs; }
void printResource(Resource r) { if ( r.isAnon() ) { String label ; if ( outputGraphBNodeLabels ) label = r.asNode().getBlankNodeId().getLabelString() ; else { if ( ! bNodeMap.containsKey(r)) bNodeMap.put(r, "b"+(bNodeCounter++)) ; label = bNodeMap.get(r) ; } out.println("<"+dfBNode+">"+label+"</"+dfBNode+">") ; } else { out.println("<"+dfURI+">"+xml_escape(r.getURI())+"</"+dfURI+">") ; } }
@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; } /**
@Override public NodeValue exec(NodeValue v) { Node n = v.asNode() ; if ( ! n.isBlank() ) throw new ExprEvalException("bnode: not a blank node") ; NodeValue nv = NodeValue.makeString(n.getBlankNodeId().getLabelString()) ; return nv ; } }
@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
@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
private NamedValue createNamedValue(Resource resource) { NamedValue result=null; if(resource.isAnon()) { result=ProtocolFactory.newVariable(resource.getId().getLabelString()); } else { // MUST BE RESOURCE result=ProtocolFactory.newResource(resource.getURI()); } return result; }
@Override public NodeValue exec(NodeValue v) { Node n = v.asNode() ; if ( ! n.isBlank() ) throw new ExprEvalException("bnode: not a blank node") ; NodeValue nv = NodeValue.makeString(n.getBlankNodeId().getLabelString()) ; return nv ; } }
private JsonObject resourceAsJSON(Resource resource) { JsonObject jsonValue = new JsonObject() ; if (resource.isAnon()) { String label; if (outputGraphBNodeLabels) label = resource.asNode().getBlankNodeId().getLabelString(); else { if (!bNodeMap.containsKey(resource)) bNodeMap.put(resource, "b" + (bNodeCounter++)); label = bNodeMap.get(resource); } jsonValue.put(dfType, dfBNode); jsonValue.put(dfValue, label) ; } else { jsonValue.put(dfType, dfURI); jsonValue.put(dfValue, resource.getURI()) ; } return jsonValue ; }
/** * Convert the given Jena Resource into a Sesame Resource * @param theRes the jena resource to convert * @return the jena resource as a sesame resource */ public static org.openrdf.model.Resource asSesameResource(Resource theRes) { if (theRes == null) { return null; } else if (theRes.canAs(Property.class)) { return asSesameURI(theRes.as(Property.class)); } else { return FACTORY.createURI("urn:anno4j:" + theRes.getId().getLabelString()); } }
/** * @param rs * The reified statement to look for subject. * @param type * The type of the subject. * @return The subject (uri or id) or null if an error occurs */ protected String getReifiedStatementSubject(final ReifiedStatement rs, final ResourceTypes type) { String toRet = null; final Resource subj = rs.getStatement().getSubject(); if (type.equals(ResourceTypes.ANON) && subj.isAnon()) { toRet = subj.getId().getLabelString(); } else if (type.equals(ResourceTypes.NAMED) && subj.isURIResource()) { toRet = subj.getURI(); } return toRet; }
protected void _setNode(com.hp.hpl.jena.graph.Node n) { unset(); isSet = true; isGraphNode = true; valGraphNode = n ; isString = false ; valString = null ; if ( n.isLiteral() ) valString = n.getLiteralLexicalForm() ; if ( n.isURI() ) { valString = n.getURI() ; valURI = n.getURI() ; isURI = true ; } if ( n.isBlank() ) valString = n.getBlankNodeId().getLabelString() ; if ( valString != null ) isString = true ; }
/** * @param rs * The reified statement to look for object. * @param type * The type of the object. * @return The object (literal value, id or uri) or null if an error occurs */ protected String getReifiedStatementObject(final ReifiedStatement rs, final RDFNodeTypes type) { String toRet = null; final RDFNode obj = rs.getStatement().getObject(); if (type.equals(RDFNodeTypes.ANON_R) && obj.isAnon()) { toRet = ((Resource) obj).getId().getLabelString(); } else if (type.equals(RDFNodeTypes.LITERAL) && obj.isLiteral()) { toRet = ((Literal) obj).getLexicalForm(); } else if (type.equals(RDFNodeTypes.NAMED_R) && obj.isURIResource()) { toRet = ((Resource) obj).getURI(); } return toRet; }
private void populateBindingValue(BindingBuilder builder, RDFNode node) { LOGGER.trace("- Value {}",node); if(node.isLiteral()) { Literal literal=node.asLiteral(); builder. withValue( ProtocolFactory. newLiteral(). withLexicalForm(literal.getLexicalForm()). withDatatype(literal.getDatatypeURI()). withLanguage(literal.getLanguage())); } else if(node.isURIResource()) { builder.withValue(ProtocolFactory.newResource(node.asResource().getURI())); } else { builder.withValue(ProtocolFactory.newVariable(node.asResource().getId().getLabelString())); } }