private String getId(Resource r) { if (r.isURIResource()) return r.getURI(); String id = bnodes.get(r); if (id == null) bnodes.put(r, id = "_:B" + bnodes.size()); return id; }
protected String parseResourceGenerator(Resource resourceGenerator, String value, String dsoIRI) { if (resourceGenerator.isURIResource() && resourceGenerator.equals(DMRM.DSpaceObjectIRI)) { return dsoIRI; } return parseValueProcessor(resourceGenerator, value); }
private void addIdentification( Trail t, Element e, Resource x ) { if (x.isURIResource()) e.setAttribute( "href", x.getURI() ); else if (t.hasSeen( x )) { e.setAttribute( "ref", idFor( e, x ) ); } else { e.setAttribute( "id", idFor( e, x ) ); } }
/** * 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(); } }
/** * Given a query result from a SPARQL query, obtain the given variable value * as a URL * * @param resultRow the result from a SPARQL query * @param variableName the name of the variable to obtain * @return the value or null if it could not be obtained */ private static URL getUrlValueFromRow(QuerySolution resultRow, String variableName) { // Check the input and exit immediately if null if (resultRow == null) { return null; } URL result = null; Resource res = resultRow.getResource(variableName); // Ignore and track services that are blank nodes if (res.isAnon()) { log.warn("Blank node found and ignored " + res.toString()); } else if (res.isURIResource()) { try { result = new URL(res.getURI()); } catch (MalformedURLException e) { log.error("Malformed URL for node", e); } catch (ClassCastException e) { log.error("The node is not a URI", e); } } return result; }
if (pred.equals(stat.getPredicate())) { final Resource subj = stat.getSubject(); if (resType.equals(ResourceTypes.NAMED) && subj.isURIResource()) { subjs.add(subj.getURI()); } else if (resType.equals(ResourceTypes.ANON) && subj.isAnon()) {
/** * @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; }
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()) ; // Literals do not need converting. return r ; }
/** * Fakes a de-reference operation, returning a byte stream over the node. */ public InputStream openStream(ReferenceContext context) { try { String result = ""; if (node == null) { result = ""; } else if (node.isLiteral()) { result = ((Literal) node).getLexicalForm(); } else if (node.isResource()) { Resource resource = (Resource) node; if (resource.isURIResource()) { result = resource.getURI(); } else { Model model = ResourceUtils.reachableClosure(resource); StringWriter stringWriter = new StringWriter(); model.write(stringWriter, "RDF/XML-ABBREV"); result = stringWriter.toString(); } } return new ByteArrayInputStream(result.getBytes(getCharset())); } catch (UnsupportedEncodingException e) { throw new DereferenceException(e); } }
public Set<NamedClass> getAllClasses() { Set<NamedClass> classes = new TreeSet<NamedClass>(); String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?c WHERE {?c a owl:Class} LIMIT 1000"; ResultSet q = queryable.query(query); while (q.hasNext()) { QuerySolution qs = q.next(); if(qs.getResource("c").isURIResource()){ classes.add(new NamedClass(qs.getResource("c").getURI())); } } //remove trivial classes classes.remove(new NamedClass(OWL.Nothing.toStringID())); classes.remove(new NamedClass(OWL.Thing.toStringID())); return classes; }
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; } }
/** Answer the default OntModelSpec for this root, which will be <code>DEFAULT</code> unless <code>root</code> has the JA namespace and a local name which is the name of an OntModelSpec constant (in OntModelSpec), in which case it's that constant's value. */ private OntModelSpec getDefault( Resource root ) { if (root.isURIResource() && root.getNameSpace().equals( JA.uri )) { OntModelSpec oms = getOntModelSpecField( root.getLocalName() ); return oms == null ? DEFAULT : oms; } else { Resource like = getUniqueResource( root, JA.likeBuiltinSpec ); return like == null ? DEFAULT : getRequiredOntModelSpecField( like.getLocalName() ); } }
destination = soln.getResource(MATCH_VAR + index); if (origin != null && origin.isURIResource() && destination != null && destination.isURIResource()) { originUri = new URI(origin.getURI()); matchUri = new URI(destination.getURI());
public static MapLookup createMapLookup(Resource root, final Source ds) { final Map<String, SPARQLMapLookup.Element> maps = new HashMap<String, SPARQLMapLookup.Element>(); // List<Resource> mapSpecs = root.getModel().listSubjectsWithProperty(RDF.type, ELDA_API.SPARQLMap).toList(); for (Resource mapSpec: mapSpecs) { String mapName = mapSpec.isURIResource() ? mapSpec.getURI() : getResourceValue(mapSpec, ELDA_API.mapName).getURI() ; String inName = getStringValue(mapSpec, ELDA_API.mapIn, "input"); String outName = getStringValue(mapSpec, ELDA_API.mapOut, "result"); String queryString = getStringValue(mapSpec,ELDA_API.mapQuery); maps.put(mapName, new Element(inName, queryString, outName)); } return new SPARQLMapLookup(ds, maps); }
protected static void addSubclassesFrom( Model result, Model schema ) { for (StmtIterator it = schema.listStatements( ANY, RDFS.subClassOf, ANY ); it.hasNext();) { Statement s = it.nextStatement(); if (s.getSubject().isURIResource() && s.getObject().isURIResource()) result.add( s ); } }
protected Literal parseLiteralGenerator(Model m, Resource literalGenerator, String value, String lang) { if (literalGenerator.isURIResource() && literalGenerator.equals(DMRM.DSpaceValue)) { return m.createLiteral(value);
public static String toSPARQL(Resource n){ if (n != null && (n.isResource() || n.isLiteral())){ if (n.isURIResource()) return "<" + n.getURI() + ">"; else if (n.isLiteral()) { String sparql = "'''" + sparqlEncode(n.asLiteral().toString()) + "'''"; //does it have a Datatype Literal? if (n.asLiteral().getDatatypeURI() != null){ sparql = sparql + "'''^^<" + n.asLiteral().getDatatypeURI().toString() + ">"; } if (n.asLiteral().getLanguage() != ""){ sparql = sparql + "'''@" + n.asLiteral().getLanguage(); } return sparql; } else return null; //TODO: throws exception } else return null; //TODO: throws exception }
/** * @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; }
if (!r.isURIResource()) continue;