public List<String> getDbPediaLabel(final String uri) throws QueryException, QueryParseException { final List<String> labellist = new LinkedList<String>(); try { final String query = "SELECT ?label WHERE{ <" + uri + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query); qexec = QueryExecutionFactory.create(cquery, this.labelmodel); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); final String label = sol.getLiteral("label").getLexicalForm(); labellist.add(label); } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return labellist; }
public String getDbPediaShortDescription(final String uri) throws QueryException, QueryParseException { String labellist = ""; try { final String query = "SELECT ?comment WHERE{ <" + uri + "> <http://www.w3.org/2000/01/rdf-schema#comment> ?comment. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query); qexec = QueryExecutionFactory.create(cquery, this.shortdescmodel); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); String desc = sol.getLiteral("comment").getLexicalForm(); labellist = desc; } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return labellist; }
public String getDbPediaLongDescription(final String uri) throws QueryException, QueryParseException { String labellist = ""; try { final String query = "SELECT ?comment WHERE{ <" + uri + "> <http://dbpedia.org/ontology/abstract> ?comment. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query); qexec = QueryExecutionFactory.create(cquery, this.longdescmodel); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); final String desc = sol.getLiteral("comment").getLexicalForm(); labellist = desc; } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return labellist; }
public SelectQueryResponse executeQuerySelect(String query) throws QueryParseException { //Query sparql = QueryFactory.create(query); VirtuosoQueryExecution vqe = queryExecutionFactory.create(query, set); ResultSet resultSet = vqe.execSelect(); SelectQueryResponse selectQueryResponse = new SelectQueryResponse(); Boolean named = false; while (resultSet.hasNext()) { QuerySolution querySolution = resultSet.next(); Iterator <String> varNames = querySolution.varNames(); for (int i = 0; varNames.hasNext(); i++) { if (!named) { String varName = varNames.next(); selectQueryResponse.addColumn(varName); selectQueryResponse.addValue(i, querySolution.get(varName).toString()); } else { selectQueryResponse.addValue(i, querySolution.get(varNames.next()).toString()); } } named = true; } vqe.close(); return selectQueryResponse; }
@Test(expected = QueryParseException.class) public void executeQuerySelectExceptionTest() throws QueryParseException{ String query = "query"; ResultSet resultSet = mock(ResultSet.class); QuerySolution querySolution = mock(QuerySolution.class); RDFNode rDFNode = mock(RDFNode.class); List list = new LinkedList(); list.add("value1"); list.add("value2"); when(virtuosoQueryExecutionFactory.create(eq(query), eq(virtGraph))).thenReturn(vqe); when(vqe.execSelect()).thenThrow(QueryParseException.class); when(resultSet.hasNext()).thenReturn(true, true, false); when(resultSet.next()).thenReturn(querySolution); when(querySolution.get(anyString())).thenReturn(rDFNode); when(querySolution.varNames()).thenReturn(list.iterator()); when(rDFNode.toString()).thenReturn("string"); toTest.executeQuerySelect(query); }
public List<String> getDbPediaLabel(final String uri) throws QueryException, QueryParseException { final List<String> labellist = new LinkedList<String>(); try { final String query = "SELECT ?label WHERE{ <" + uri + "> <http://www.w3.org/2000/01/rdf-schema#label> ?label. }"; ResultSet results = null; // NOPMD by quh on 14.02.14 10:04 QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory .create(query); qexec = QueryExecutionFactory.create(cquery, this.labelmodel); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); final String label = sol.getLiteral("label") .getLexicalForm(); labellist.add(label); } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return labellist; }
public String getDbPediaShortDescription(final String uri) throws QueryException, QueryParseException { String labellist = ""; try { final String query = "SELECT ?comment WHERE{ <" + uri + "> <http://www.w3.org/2000/01/rdf-schema#comment> ?comment. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory .create(query); qexec = QueryExecutionFactory.create(cquery, this.shortdescmodel); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); String desc = sol.getLiteral("comment").getLexicalForm(); labellist = desc; } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return labellist; }
public String getDbPediaLongDescription(final String uri) throws QueryException, QueryParseException { String labellist = ""; try { final String query = "SELECT ?comment WHERE{ <" + uri + "> <http://dbpedia.org/ontology/abstract> ?comment. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory .create(query); qexec = QueryExecutionFactory.create(cquery, this.longdescmodel); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); final String desc = sol.getLiteral("comment") .getLexicalForm(); labellist = desc; } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return labellist; }
public HashSet<String> addAdditionalPersonNameOccurrences(String res) { HashSet<String> names = new HashSet<String>(); try { final String query = "SELECT ?surname WHERE{ <" + res + "> <http://xmlns.com/foaf/0.1/surname> ?surname. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory .create(query); qexec = QueryExecutionFactory.create(cquery, this.mappingbasedproperties); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); final String surname = sol.getLiteral("surname") .getLexicalForm(); names.add(surname); } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } return names; }
private HashSet<String> addSomeMorePersonNames(final String uri) { HashSet<String> names = new HashSet<String>(); try { final String query = "SELECT ?name WHERE{ <" + uri + "> <http://xmlns.com/foaf/0.1/name> ?name. }"; ResultSet results = null; QueryExecution qexec = null; final com.hp.hpl.jena.query.Query cquery = QueryFactory.create(query); qexec = QueryExecutionFactory.create(cquery, this.persondata); results = qexec.execSelect(); if (results != null) { while (results.hasNext()) { final QuerySolution sol = results.nextSolution(); final String surname = sol.getLiteral("name").getLexicalForm(); names.add(surname.toLowerCase()); } qexec.close(); } } catch (QueryParseException e) { Logger.getRootLogger().info("Query parse Exception"); } String reducedUri = uri.replaceAll("http://dbpedia.org/resource/", ""); String splitter[] = reducedUri.split("_"); if(splitter.length == 2) { names.add((splitter[0]+" "+splitter[1]).toLowerCase()); names.add((splitter[1]+" "+splitter[0]).toLowerCase()); } return names; }
@Override public ResultSet execQuery(final String query) throws QueryParseException { parameters.getOutputConsole().println("AggregationEngine: executing query "+query); parameters.getOutputConsole().println("Current state "+state.getStateLabel()); parameters.getOutputConsole().println("Using query engine "+state.getInfo()); final long starTime = System.currentTimeMillis(); final ResultSet result = state.execQuery(query); final long endTime = System.currentTimeMillis(); parameters.getOutputConsole().println("query completed in "+(endTime-starTime)+" milliseconds with returning "+result.getRowNumber()+" rows."); return result; }
@Override public Response execQuery(final String query) throws QueryParseException, IllegalMimeTypeException { final String mimeType = resultSetFormatter.getMimeType(); final ResultSet resultSet = aggregationEngine.execQuery(query); final String result = resultSetFormatter.format(resultSet); return Response.ok(result) .header(CONTENT_TYPE_HEADER_KEY, mimeType) .header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER_KEY, "*") .build(); }
/** * @return * @throws IllegalMimeTypeException * @throws QueryParseException */ private QueryExecutorService createService() throws QueryParseException, IllegalMimeTypeException { final QueryExecutorService service = mock(QueryExecutorService.class); when(service.execQuery(QUERY)).thenReturn(Response.ok(RESPONSE).build()); return service; }
/** * @throws IllegalMimeTypeException * @throws QueryParseException * */ @Test public void shouldReturnAResponseWithCorrectContentTypeAndResult() throws QueryParseException, IllegalMimeTypeException { final QueryEngine engine = createEngine(RESULT_SET); final ResultSetFormatter formatter = createFormatter(MIME_TYPE, FORMATTED_RESULT); final QueryExecutorService testSubject = createTestSubject(engine, formatter); final Response response = testSubject.execQuery(QUERY); assertEquals("Wrong content type", response.getHeaders().get(CONTENT_TYPE_HEADER_KEY).get(0), MIME_TYPE); assertEquals("Wrong response body", response.getEntity(), FORMATTED_RESULT); }
/** * A QueryParseException is thrown is the submitted string is not a valid * SPARQL query * * @throws InterruptedException */ @Test public void shouldThrowAnExceptionOnInvalidQuery() throws InterruptedException { try { final QueryEngine engine = createSuccesTestSubject(Collections.singletonList(utils.ontologySubproperty)); engine.execQuery("An invalid query string"); fail("expected exception not thrown"); } catch (final QueryParseException e) { // expected exception } }
@Override public ResultSet execQuery(String query) throws QueryParseException { if (disposed) throw new IllegalStateException(); assertEquals(expectedQuery, query); assertFalse("Multiple calls to execQuery", called); called=false; return resultSet; }
/** * The Wikipedia Id or -1 if the Id couldn't be retrieved. * * FIXME The method throws an exception for "http://DBpedia.org/resource/Origin_of_the_name_"Empire_State"". this * might be happen because of the quotes inside the URI. * * @param dbpediaUri * @return */ @Deprecated public static int getIdFromDBpedia(String dbpediaUri) { int id = -1; ParameterizedSparqlString query = new ParameterizedSparqlString( "SELECT ?id WHERE { ?dbpedia dbo:wikiPageID ?id .}", prefixes); query.setIri("dbpedia", dbpediaUri); QueryExecution qexec = null; try { qexec = QueryExecutionFactory.create(query.asQuery(), model); } catch (QueryParseException e) { LOGGER.error("Got a bad dbpediaUri \"" + dbpediaUri + "\" which couldn't be parse inside of a SPARQL query. Returning -1.", e); return id; } ResultSet result = qexec.execSelect(); if (result.hasNext()) { id = result.next().get("id").asLiteral().getInt(); return id; } qexec = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", query.asQuery()); result = qexec.execSelect(); if (result.hasNext()) { id = result.next().get("id").asLiteral().getInt(); model.add(new StatementImpl(model.createResource(dbpediaUri), model .createProperty("http://dbpedia.org/ontology/wikiPageID"), model.createTypedLiteral(id))); return id; } model.add(new StatementImpl(model.createResource(dbpediaUri), model .createProperty("http://dbpedia.org/ontology/wikiPageID"), model.createTypedLiteral(id))); return id; }
public String executeQueryConstruct(String query, String type) throws QueryParseException { ByteArrayOutputStream output = new ByteArrayOutputStream(); VirtuosoQueryExecution vqe = queryExecutionFactory.create(query, set); Model model = vqe.execConstruct(); model.write(output, type, null); return output.toString(); }
public boolean executeQueryAsk(String query) throws QueryParseException { boolean response; VirtuosoQueryExecution vqe = queryExecutionFactory.create(query, set); response = vqe.execAsk(); return response; }
public String executeQueryDescribe (String query, String type) throws QueryParseException { ByteArrayOutputStream output = new ByteArrayOutputStream(); VirtuosoQueryExecution vqe = queryExecutionFactory.create(query, set); Model model = vqe.execDescribe(); model.write(output, type, null); return output.toString(); }
@Test(expected = QueryParseException.class) public void executeQueryConstructExceptionTest() throws QueryParseException{ String query = "query"; String type = "type"; when(virtuosoQueryExecutionFactory.create(eq(query), eq(virtGraph))).thenReturn(vqe); when(vqe.execConstruct()).thenThrow(QueryParseException.class); toTest.executeQueryConstruct(query, type); }
@Test(expected = QueryParseException.class) public void executeQueryAskExceptionTest() throws QueryParseException{ String query = "query"; when(virtuosoQueryExecutionFactory.create(eq(query), eq(virtGraph))).thenReturn(vqe); when(vqe.execAsk()).thenThrow(QueryParseException.class); toTest.executeQueryAsk(query); }
@Test(expected = QueryParseException.class) public void executeQueryDescribeExceptionTest() throws QueryParseException { String query = "query"; String type = "type"; when(virtuosoQueryExecutionFactory.create(eq(query), eq(virtGraph))).thenReturn(vqe); when(vqe.execDescribe()).thenThrow(QueryParseException.class); toTest.executeQueryDescribe(query, type); }
@Override public ResultSet execQuery(final String query) throws QueryParseException { System.out.println("Unsing model "+model); final QueryExecution execution = QueryExecutionFactory.create(QueryFactory.create(query), model); return execution.execSelect(); }
/** * Perform a query against the aggregated ontology * * @param String * query * @return * @throws QueryParseException */ ResultSet execQuery(String query) throws QueryParseException;
/** * @param query * @return * @throws QueryParseException */ public final ResultSet execQuery(final String query) throws QueryParseException{ return delegate.execQuery(query); }
/** * Executes a certain SPARQL SELECT query * * @param query * * @return An HTTP {@link Response} containing the result of query * @throws IllegalMimeTypeException * @throws QueryParseException */ Response execQuery(final String query) throws QueryParseException, IllegalMimeTypeException;