private boolean seenbNode(Resource r) { return bNodes.containsKey( r.getId() ); }
private int bNodeIdFor(Resource r) { AnonId id = r.getId(); Integer shortId = bNodes.get( id ); if (shortId == null) { shortId = bnodeCount++; bNodes.put(id, shortId); } return shortId; }
protected static void writeResource(Resource r, PrintWriter writer) { if (r.isAnon()) { writer.print(anonName(r.getId())); } else { writer.print("<"); writeURIString(r.getURI(), writer); writer.print(">"); } } static private boolean okURIChars[] = new boolean[128];
/** * 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(); } }
private String longAnonId(Resource r) { String rid = r.getId().toString(); return XMLChar.isValidNCName( rid ) ? rid : escapedId( rid ); }
@Override protected void consumeResource(FilterBuilder builder, Resource resource) { builder.withVariable(ProtocolFactory.newVariable(resource.getId().getLabelString())); } }
private static Resource otherModel(Resource r, Model model) { if ( r.isURIResource() ) return model.createResource(r.getURI()) ; if ( r.isAnon() ) return model.createResource(r.getId()) ; // Literals do not need converting. return r ; }
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; }
/** * @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; }
protected String spelling( RDFNode n ) { if (n.isURIResource()) return resourceSpelling( (Resource) n ); if (n.isLiteral()) return ((Literal) n).getLexicalForm(); String id = ((Resource) n).getId().toString(); return id; }
private static Resource otherModel(Resource r, Model model) { if ( r.isURIResource() ) return model.createResource(r.getURI()) ; if ( r.isAnon() ) return model.createResource(r.getId()) ; // Literals do not need converting. return r ; }
private static Resource otherModel(Resource r, Model model) { if (r.isURIResource()) return model.createResource(r.getURI()); if (r.isAnon()) return model.createResource(r.getId()); return r; } }
/** * 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()); } }
private static void closureNoTest(Resource r, Model closureBlob, Collection<Resource> visited, ClosureTest test, Collection<String> resources) { visited.add(r); String gid = ((DB2Graph) r.getModel().getGraph()).getGraphID(); String key = null; if (r.isAnon()) { key = gid + ":" + r.getId(); } else { key = gid + ":" + r.getURI(); } if (resources.contains(key)) { return; } resources.add(key); StmtIterator sIter = r.listProperties(); for (; sIter.hasNext();) { Statement stmt = sIter.nextStatement(); closure(stmt, closureBlob, visited, test, resources); } }
/** * @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; }
label = resource.getId().getLabelString() ; else
/** * @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())); } }