/** * {@inheritDoc} */ @Override public QuerySolution next() { return super.object.next(); }
@Override public QuerySolution next() { return resultset.next(); }
public SlicedResultSet( ResultSet results, long offset, long limit ) { this.results = results; this.row = 0; this.limit = limit; for( int i = 0; i < offset && results.hasNext(); i++ ) { results.next(); } }
@Override public Term next() { QuerySolution next = this.rs.next(); return createTerm(next.get("?x")); }
/** * Returns the number of triples where the object belongs to the given class. * @param cls * @return */ public int getOccurencesInObjectPosition(NamedClass cls){ log.trace(String.format("Computing number of occurences in object position for %s", cls.getName())); String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?o a <%s>. ?s ?p ?o.}", cls.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); return classOccurenceCnt; }
@Override public Integer call() throws Exception { int size = qe.execSelect().next().get("count").asLiteral().getInt(); System.out.println(size); return size; } });
public Set<DatatypeProperty> getAllDataProperties() { Set<DatatypeProperty> properties = new TreeSet<DatatypeProperty>(); String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:DatatypeProperty}"; ResultSet q = queryable.query(query); while (q.hasNext()) { QuerySolution qs = q.next(); properties.add(new DatatypeProperty(qs.getResource("p").getURI())); } return properties; }
/** * Returns the number triples with the given property as predicate. * @param prop * @return */ public int getOccurences(Property prop){ log.trace(String.format("Computing number of occurences as predicate for %s", prop.getName())); String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}", prop.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int propOccurenceCnt = rs.next().getLiteral("cnt").getInt(); return propOccurenceCnt; }
/** * Returns the number of triples where the subject belongs to the given class. * @param cls * @return */ public int getOccurencesInSubjectPosition(NamedClass cls){ log.trace(String.format("Computing number of occurences in subject position for %s", cls.getName())); String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?s a <%s>. ?s ?p ?o.}", cls.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); return classOccurenceCnt; }
/** * Returns the number of triples where the subject or object belongs to the given class. * (This is not the same as computing the number of instances of the given class {@link SPARQLEndpointMetrics#getPopularity(NamedClass)}) * @param cls * @return */ public int getOccurences(NamedClass cls){ log.trace(String.format("Computing number of occurences in subject or object position for %s", cls.getName())); String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?s a <%s>.{?s ?p1 ?o1.} UNION {?o2 ?p2 ?s} }", cls.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); return classOccurenceCnt; }
public Set<ObjectProperty> getAllObjectProperties() { Set<ObjectProperty> properties = new TreeSet<ObjectProperty>(); String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:ObjectProperty}"; ResultSet q = queryable.query(query); while (q.hasNext()) { QuerySolution qs = q.next(); properties.add(new ObjectProperty(qs.getResource("p").getURI())); } return properties; }
/** * Returns the number of triples where the given individual is in object position(in-going links). * @param cls * @return */ public int getOccurencesInObjectPosition(Individual ind){ log.trace(String.format("Computing number of occurences in object position for %s", ind.getName())); String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p <%s>.}", ind.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); return classOccurenceCnt; }
/** * Returns the number of instances of the given class. * @param cls * @return */ public int getPopularity(NamedClass cls){ String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?s a <%s>.{?s ?p1 ?o1.} UNION {?o2 ?p2 ?s} }", cls.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); return classOccurenceCnt; }
/** * Returns the number of triples with the given property as predicate and where the subject belongs to the given class. * @param cls * @return */ public int getOccurencesSubjectPredicate(NamedClass cls, Property prop){ log.trace(String.format("Computing number of occurences as subject and predicate for [%s, %s]", cls.getName(), prop.getName())); String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s <%s> ?o}", cls.getName(), prop.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int cnt = rs.next().getLiteral("cnt").getInt(); return cnt; }
/** * Returns the number of triples with the given property as predicate and where the object belongs to the given class. * @param cls * @return */ public int getOccurencesPredicateObject(Property prop, NamedClass cls){ log.trace(String.format("Computing number of occurences as predicate and object for [%s, %s]", prop.getName(), cls.getName())); String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?o a <%s>. ?s <%s> ?o}", cls.getName(), prop.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int cnt = rs.next().getLiteral("cnt").getInt(); return cnt; }
@Override public Atom next() { QuerySolution next = this.rs.next(); Predicate predicate = this.predicate; if(predicate == null) predicate = createPredicate(next.get("?p"), 2); Term subject = this.subject; if(subject == null) subject = createTerm(next.get("?s")); Term object = this.object; if (object == null) object = createTerm(next.get("?o")); return new DefaultAtom(predicate, subject, object); }
/** * Returns the number of triples with the first given class as subject and the second given class as object. * @param cls * @return */ public int getOccurencesSubjectObject(NamedClass subject, NamedClass object){ log.trace(String.format("Computing number of occurences as subject and object for [%s, %s]", subject.getName(), object.getName())); String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s ?p ?o. ?o a <%s>}", subject.getName(), object.getName()); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); int cnt = rs.next().getLiteral("cnt").getInt(); return cnt; }
@Override public Integer call() throws Exception{ String query = "SELECT DISTINCT (count(?s) AS ?count) { { ?s ?p ?o . } UNION { GRAPH ?g { ?s ?p ?o .} } }"; QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(sparqlEndPoint,query); int size = qe.execSelect().next().get("count").asLiteral().getInt(); return size; } });
/** Output a result set in BIO format */ public static void outputAsBIO(OutputStream out, ResultSet results) { List<Var> vars = Var.varList(results.getResultVars()) ; BindingOutputStream bout = new BindingOutputStream(out, vars) ; for ( ; results.hasNext() ; ) { Binding b = BindingUtils.asBinding(results.next()) ; bout.write(b) ; } bout.flush() ; }
public String getComputedOn(){ String selectQuery = "SELECT ?cOn { graph <"+currentGraphURI+"> { ?s <"+DAQ.computedOn.getURI()+"> ?cOn } }"; QueryExecution exec = QueryExecutionFactory.create(QueryFactory.create(selectQuery), dsLoader.getInternalDataset()); ResultSet set = exec.execSelect(); while(set.hasNext()){ QuerySolution qs = set.next(); Resource computedOn = qs.getResource("cOn"); return computedOn.getURI(); } return null; }