Я получаю org.apache.jena.sparql.engine.ResultSetCheckCondition@51e0b99a при выполнении запроса к виртуозу на jena API - PullRequest
0 голосов
/ 25 мая 2019

Я использую провайдера Virtuoso Jena и использую Spring Boot для развертывания программы на сервере Tomcat. В параметрах запроса я отправляю весь запрос и выполняю его для конечной точки Virtuoso SPARQL. Проблема в том, что когда я запрашиваю что-то в форме:

PREFIX sosa: <http://www.w3.org/ns/sosa/> 
PREFIX ex: <http://example.org/data/>
SELECT ?p  ?o  WHERE {ex:PCBBoard2 ?p ?o}

Я получаю org.apache.jena.sparql.engine.ResultSetCheckCondition@51e0b99a

Но когда я запрашиваю что-то подобное:

PREFIX sosa: <http://www.w3.org/ns/sosa/> 
PREFIX ex: <http://example.org/data/>
SELECT ?s  ?o  WHERE {?s sosa:observes  ?o}

Я получаю правильный ответ с результатами:

[{FunVar(s)=http://example.org/data/windSensor14, FunVar(o)=http://example.org/data/windSpeedLocation4687}, {FunVar(s)=http://example.org/data/iphoneSpeedSensor, FunVar(o)=http://example.org/data/iphoneSpeed}, {FunVar(s)=http://example.org/data/tempSensor23, FunVar(o)=http://example.org/data/tempSensor23temperature}, {FunVar(s)=http://example.org/data/VCAB-DP1-BP-40, FunVar(o)=http://example.org/data/VCAB-DP1-BP-40groundDisplacementSpeed}, {FunVar(s)=http://example.org/data/Appartment134Sensor926, FunVar(o)=http://example.org/data/Appartment134electricConsumption}, {FunVar(s)=http://example.org/data/DHT224578, FunVar(o)=http://example.org/data/Room145temperature}, {FunVar(s)=http://example.org/data/DHT224580, FunVar(o)=http://example.org/data/Room245temperature}, {FunVar(s)=http://example.org/data/BMP282Sensor, FunVar(o)=http://example.org/data/BMP282SensorAtmosphericPressure}, {FunVar(s)=http://example.org/data/DHT224581, FunVar(o)=http://example.org/data/Room245humidity}, {FunVar(s)=http://example.org/data/DHT224579, FunVar(o)=http://example.org/data/Room145humidity}]

Я отправляю запросы с postman.

@RestController
public class Controller {

    @GetMapping("/")
    @ResponseBody
    public String query(@RequestParam String thequery) throws UnirestException {
        Reasoner reasoner = PelletReasonerFactory.theInstance().create();
VirtGraph vg = new VirtGraph("http://147.27.60.65/sensorOntology", "jdbc:virtuoso://147.27.60.65:1111", "dba", "boto");
            Query sparql = QueryFactory.create("PREFIX sosa: <http://www.w3.org/ns/sosa/>\r\n" + 
                    "PREFIX owl: <http://www.w3.org/2002/07/owl#>\r\n" + 
                    "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
                    "CONSTRUCT FROM <http://147.27.60.65/sensorOntology> WHERE {?s ?p ?o}");


            QueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, vg);

            Model model1 = vqe.execConstruct();
            Graph g = model1.getGraph();
InfModel infModel = ModelFactory.createInfModel( reasoner, model1 );
            //Query sparql1 = QueryFactory.create("PREFIX sosa: <http://www.w3.org/ns/sosa/> SELECT ?s ?o WHERE {?s sosa:actuationEnabled ?o }");
            Query sparql1 = QueryFactory.create(thequery);

            QueryExecution qe = SparqlDLExecutionFactory.create(sparql1, infModel);
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            ResultSet results = qe.execSelect();
qe.close();
            return results.toString();
}

Не берите в голову рассуждающие части VirtGraph и CONSTRUCT, которые работают правильно и служат для обоснования графика, хранящегося в Virtuoso, фактический запрос происходит здесь:

InfModel infModel = ModelFactory.createInfModel( reasoner, model1 );
Query sparql1 = QueryFactory.create(thequery);

            QueryExecution qe = SparqlDLExecutionFactory.create(sparql1, infModel);
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            ResultSet results = qe.execSelect();
                        qe.close();
            return results.toString();

thequery - это запрос, отправленный в виде строки в @RequestParam

1 Ответ

0 голосов
/ 25 мая 2019

Неважно, мне удалось получить хорошее представление, изменив: return results.toString(); на

ByteArrayOutputStream b = new ByteArrayOutputStream();
QueryExecution qe = SparqlDLExecutionFactory.create(sparql1, infModel);
ResultSet results = qe.execSelect();
ResultSetFormatter.outputAsJSON(b, results);
qe.close();
return b.toString();
...