private String getUriFromSolution(QuerySolution solution) { return solution.getResource("uri").getURI(); } }
@Override protected Map<String, String> parseSolutionRow(QuerySolution solution) { Map<String, String> map = new HashMap<String, String>(); map.put("uri", solution.getResource("uri").getURI()); map.put("label", ifLiteralPresent(solution, "label", "")); map.put("classLabel", ""); map.put("imageUrl", placeholderImageUrl); return map; } }
private String extractSampleResource(int maxOffset){ long startTime = System.currentTimeMillis(); int random = randomGen.nextInt(maxOffset); logger.info("Extracting sample resource (" + random + ")..."); String query = String.format("SELECT DISTINCT ?s WHERE {?s a ?type} LIMIT 1 OFFSET %d", random); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); String resource = rs.next().getResource("s").getURI(); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return resource; }
@Override protected void processQuerySolution(QuerySolution qs) { Resource resource = qs.getResource("property"); String uri = resource.getURI(); DataProperty property = getDataPropertyByURI(uri); if (property != null) { properties.add(property); } } });
@Override protected void processQuerySolution(QuerySolution qs) { if (qs != null) { // no idea how this happens, but it seems to RDFNode n = qs.getResource("g"); if (n != null && n.isResource()) { graphURIs.add(((Resource) n).getURI()); } } } });
@Override protected void processQuerySolution(QuerySolution qs) { Resource currRes = qs.getResource("ind"); if (!currRes.isAnon()) { try { filteredIndividualList.add( makeIndividual(currRes.getURI(), null)); } catch (IndividualNotFoundException e) { // don't add } } } });
@Override protected void processQuerySolution(QuerySolution qs) { Resource object = qs.getResource("object"); if (object != null && !sameAsInds.contains(object.getURI())) { sameAsInds.add(object.getURI()); addedURIs.add(object.getURI()); } } });
public SortedSet<OWLClassExpression> getMeaningfulClasses(OWLClassExpression index, SortedSet<OWLClassExpression> targetClasses) { String query = buildMeaningfulClassesQuery(index, targetClasses); if (logger.isDebugEnabled()) logger.debug(sparql_debug, query); SortedSet<OWLClassExpression> meaningfulClasses = new TreeSet<>(); ResultSet rs = executeSelectQuery(query); while(rs.hasNext()) { QuerySolution qs = rs.next(); meaningfulClasses.add(df.getOWLClass(IRI.create(qs.getResource("concept").getURI()))); } return meaningfulClasses; }
public SortedSet<OWLObjectProperty> getInverseObjectProperties(OWLObjectProperty property){ SortedSet<OWLObjectProperty> inverseObjectProperties = new TreeSet<>(); String query = "SELECT ?p WHERE {" + "{<%p> <%ax> ?p.} UNION {?p <%ax> <%p>}}".replace("%p", property.toStringID()).replace("%ax", OWL.inverseOf.getURI()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); inverseObjectProperties.add(df.getOWLObjectProperty(IRI.create(qs.getResource("p").getURI()))); } return inverseObjectProperties; }
public SortedSet<OWLClass> getMostSpecificClasses() { SortedSet<OWLClass> classes = new TreeSet<>(); String query = "SELECT ?cls WHERE {?cls a <http://www.w3.org/2002/07/owl#Class>. " + "FILTER NOT EXISTS{?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?cls. FILTER(?sub != <http://www.w3.org/2002/07/owl#Nothing>)}}"; ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); classes.add(df.getOWLClass(IRI.create(qs.getResource("cls").getURI()))); } return classes; }
public Set<OWLClass> getTypes(String namespace, boolean omitEmptyTypes) { Set<OWLClass> types = new TreeSet<>(); String query = "SELECT DISTINCT ?cls WHERE {[] a ?cls ." + (omitEmptyTypes ? "[] a ?cls ." : "" ) + (namespace != null ? ("FILTER(REGEX(?cls,'^" + namespace + "'))") : "") + "}"; ResultSet rs = executeSelectQuery(query); while(rs.hasNext()){ QuerySolution qs = rs.next(); types.add(df.getOWLClass(IRI.create(qs.getResource("cls").getURI()))); } return types; }
@Override public Set<OWLIndividual> getRelatedIndividualsImpl(OWLIndividual individual, OWLObjectProperty objectProperty) { Set<OWLIndividual> individuals = new HashSet<>(); String query = String.format("SELECT ?ind WHERE {<%s> <%s> ?ind, FILTER(isIRI(?ind))}", individual.toStringID(), objectProperty.toStringID()); ResultSet rs = executeSelectQuery(query); while(rs.hasNext()){ QuerySolution qs = rs.next(); individuals.add(df.getOWLNamedIndividual(IRI.create(qs.getResource("ind").getURI()))); } return individuals; }
public Set<OWLObjectProperty> getAllObjectProperties() { Set<OWLObjectProperty> properties = new TreeSet<>(); String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:ObjectProperty}"; SparqlQuery sq = new SparqlQuery(query, sparqlEndpoint); ResultSet q = sq.send(false); while (q.hasNext()) { QuerySolution qs = q.next(); properties.add(df.getOWLObjectProperty(IRI.create(qs.getResource("p").getURI()))); } return properties; }
public Set<OWLDataProperty> getAllDataProperties() { Set<OWLDataProperty> properties = new TreeSet<>(); String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:DatatypeProperty}"; SparqlQuery sq = new SparqlQuery(query, sparqlEndpoint); ResultSet q = sq.send(false); while (q.hasNext()) { QuerySolution qs = q.next(); properties.add(df.getOWLDataProperty(IRI.create(qs.getResource("p").getURI()))); } return properties; }
public Set<OWLObjectProperty> getObjectPropertiesWithDomain(OWLClass domain) { Set<OWLObjectProperty> properties = new TreeSet<>(); String query = "SELECT ?p WHERE {?p <http://www.w3.org/2000/01/rdf-schema#domain> <" + domain.toStringID() + ">.}"; ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); properties.add(df.getOWLObjectProperty(IRI.create(qs.getResource("p").getURI()))); } return properties; }
public Set<OWLObjectProperty> getObjectProperties(OWLClass cls) { Set<OWLObjectProperty> properties = new TreeSet<>(); String query = "SELECT DISTINCT ?p WHERE {?s a <" + cls.toStringID() + ">. ?s ?p ?o}"; ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); properties.add(df.getOWLObjectProperty(IRI.create(qs.getResource("p").getURI()))); } return properties; }
private Relationship parseSolution(QuerySolution solution) { ItemInfo info = new ItemInfo(); info.uri = solution.getResource("uri").getURI(); info.label = solution.getLiteral("label").getString(); info.externalAuthId = ifLiteralPresent(solution, "externalAuthId", ""); Relationship r = new Relationship(); r.proxyInfos.add(info); return r; } }
private Set<Node> getSuperClasses(Node cls){ Set<Node> superClasses = new HashSet<>(); superClassesQueryTemplate.setIri("sub", cls.getURI()); String query = superClassesQueryTemplate.toString(); QueryExecution qe = qef.createQueryExecution(query); ResultSet rs = qe.execSelect(); while(rs.hasNext()){ QuerySolution qs = rs.next(); superClasses.add(qs.getResource("sup").asNode()); } qe.close(); return superClasses; }
private RDFResourceTree getSimilarTree(RDFResourceTree tree, String property, int maxTreeDepth){ String query = "SELECT ?o WHERE {?s <" + property + "> ?o. FILTER(isURI(?o) && ?o != <" + tree.getData() + ">)} LIMIT 1"; QueryExecution qe = qef.createQueryExecution(query); ResultSet rs = qe.execSelect(); if(rs.hasNext()){ Resource object = rs.next().getResource("o"); Model cbd = cbdGen.getConciseBoundedDescription(object.getURI(), maxTreeDepth); RDFResourceTree similarTree = queryTreeFactory.getQueryTree(object, cbd, maxTreeDepth); similarTree.setData(object.asNode()); return similarTree; } return null; }
@Test public void test_API1() { try(QueryExecution qExec = makeQExec("SELECT * {?s ?p ?o}")) { ResultSet rs = qExec.execSelect() ; assertTrue("No results", rs.hasNext()) ; QuerySolution qs = rs.nextSolution() ; Resource qr = qs.getResource("s") ; //assertSame("Not the same model as queried", qr.getModel(), m) ; Set<Statement> s1 = qr.getModel().listStatements().toSet() ; Set<Statement> s2 = m.listStatements().toSet() ; assertEquals(s1,s2) ; } }