pss.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pss.setIri("msgUri", msg.getUri()); pss.setLiteral("crawlDate", msg.getCrawlDate());
pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setCommandText(queryString);
@Test public void test_param_string_copy_6() { // Test selective copying - copying without copying prefixes ParameterizedSparqlString query = new ParameterizedSparqlString(); query.setNsPrefix("ex", "http://example.org"); ParameterizedSparqlString copy = query.copy(true, true, false); Assert.assertFalse("http://example.org".equals(copy.getNsPrefixURI("ex"))); }
/** * Retrieve resource data of all known won nodes that are saved in the Sparql endpoint. * * @return Set of all known won node resource data */ public Set<WonNodeInfo> retrieveAllWonNodeInfo() { Set<WonNodeInfo> wonNodeInfos = new HashSet<>(); String queryString = "SELECT ?graphUri ?nodeUri WHERE { GRAPH ?graphUri {?nodeUri won:hasUriPrefixSpecification ?c} }"; ParameterizedSparqlString pps = new ParameterizedSparqlString(); pps.setCommandText(queryString); pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); log.debug("Query SPARQL Endpoint: {}", sparqlEndpoint); log.debug("Execute query: {}", pps.toString()); QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, pps.asQuery()); ResultSet results = qexec.execSelect(); while (results.hasNext()) { QuerySolution qs = results.nextSolution(); RDFNode rdfNode = qs.get("graphUri"); if (rdfNode != null) { String graphUri = rdfNode.asResource().getURI(); Dataset ds = retrieveDataset(graphUri); WonNodeInfo nodeInfo = getWonNodeInfoFromDataset(ds); wonNodeInfos.add(nodeInfo); } } qexec.close(); return wonNodeInfos; }
@Test public void test_param_string_prefixes_1() { // Test prefixes are prepended String cmdText = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString query = new ParameterizedSparqlString(cmdText); query.setNsPrefix("ex", "http://example.org"); test(query, new String[] { "PREFIX", "ex:", "<http://example.org>" }, new String[] {}); testAsQuery(query); }
@Test public void test_param_string_prefixes_2() { // Test prefixes are prepended String cmdText = "SELECT * WHERE { ?s ex:predicate ?o }"; ParameterizedSparqlString query = new ParameterizedSparqlString(cmdText); query.setNsPrefix("ex", "http://example.org"); test(query, new String[] { "PREFIX", "ex:", "<http://example.org>", "ex:predicate" }, new String[] {}); testAsQuery(query); }
/** * To start crawling (http modification query) from a certain point in time, take last * modification date from a need known in the database that is in status 'DONE' which means * it has been crawled. * * @param wonNodeUri won node uri for which need modification dates should be retrieved * @return modification date to start crawling from or null if none exists */ public String retrieveNeedModificationDateForCrawling(String wonNodeUri) { String queryString = "SELECT ?modificationDate WHERE {\n" + " ?needUri a won:Need.\n" + " ?needUri won:hasWonNode ?wonNodeUri. \n" + " ?needUri dcterms:modified ?modificationDate. \n" + " ?needUri won:crawlStatus 'DONE'. \n" + "} ORDER BY DESC(?modificationDate) LIMIT 1\n"; ParameterizedSparqlString pps = new ParameterizedSparqlString(); pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setNsPrefix("dcterms", "http://purl.org/dc/terms/"); pps.setCommandText(queryString); pps.setIri("wonNodeUri", wonNodeUri); QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, pps.asQuery()); ResultSet results = qexec.execSelect(); String modificationDate = null; if (results.hasNext()) { QuerySolution qs = results.nextSolution(); modificationDate = qs.get("modificationDate").asLiteral().getString(); } qexec.close(); return modificationDate; }
/** * To start crawling (http modification query) from a certain point in time, take last * modification date from a connection known in the database that is in status 'DONE' which means * it has been crawled. * * @param wonNodeUri won node uri for which connection modification dates should be retrieved * @return modification date to start crawling from or null if none exists */ public String retrieveConnectionModificationDateForCrawling(String wonNodeUri) { String queryString = "SELECT ?modificationDate WHERE {\n" + " ?connectionUri a won:Connection.\n" + " ?connectionUri won:hasWonNode ?wonNodeUri. \n" + " ?connectionUri dcterms:modified ?modificationDate. \n" + " ?connectionUri won:crawlStatus 'DONE'. \n" + "} ORDER BY DESC(?modificationDate) LIMIT 1\n"; ParameterizedSparqlString pps = new ParameterizedSparqlString(); pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setNsPrefix("dcterms", "http://purl.org/dc/terms/"); pps.setCommandText(queryString); pps.setIri("wonNodeUri", wonNodeUri); QueryExecution qexec = QueryExecutionFactory.sparqlService(sparqlEndpoint, pps.asQuery()); ResultSet results = qexec.execSelect(); String modificationDate = null; if (results.hasNext()) { QuerySolution qs = results.nextSolution(); modificationDate = qs.get("modificationDate").asLiteral().getString(); } qexec.close(); return modificationDate; }
@Test public void test_param_string_copy_3() { // Test copying - copying should copy prefixes ParameterizedSparqlString query = new ParameterizedSparqlString(); query.setNsPrefix("ex", "http://example.org"); ParameterizedSparqlString copy = query.copy(); Assert.assertEquals("http://example.org", copy.getNsPrefixURI("ex")); }
pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setCommandText(queryString); pps.setLiteral("status", status.toString());
pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setCommandText(queryTemplate); pps.setLiteral("fromDate", fromDate);