use of org.eol.globi.export.ExporterRDF in project eol-globi-data by jhpoelen.
the class SPARQLTest method executeQuerySampleGloBIData.
@Test
public void executeQuerySampleGloBIData() throws NodeFactoryException, ParseException, IOException {
ExporterRDF exporter = new ExporterRDF();
StringWriter writer = new StringWriter();
Study study = ExportTestUtil.createTestData(nodeFactory);
exporter.exportStudy(study, writer, true);
Model model = ModelFactory.createDefaultModel();
model.read(new ByteArrayInputStream(writer.toString().getBytes("UTF-8")), null, "N-TRIPLE");
System.out.println(writer.toString());
String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "SELECT ?individual WHERE { " + " ?individual rdf:type <http://purl.obolibrary.org/obo/CARO_0010004> . " + "}";
Query query = QueryFactory.create(queryString);
QueryExecution exec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = exec.execSelect();
int numberOfOrganisms = 0;
while (results.hasNext()) {
QuerySolution solution = results.nextSolution();
assertThat(solution.get("individual"), is(notNullValue()));
numberOfOrganisms++;
}
final int expectedNumberOfOrganisms = 3;
assertThat(numberOfOrganisms, is(expectedNumberOfOrganisms));
} finally {
exec.close();
}
}
Aggregations