Ejemplo n.º 1
0
 @Override
 public QueryResultList<Representation> find(FieldQuery parsedQuery) throws IOException {
   long start = System.currentTimeMillis();
   final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
   query.setEndpointType(EndpointTypeEnum.LARQ);
   String sparqlQuery = query.toSparqlConstruct();
   long initEnd = System.currentTimeMillis();
   log.info("  > InitTime: " + (initEnd - start));
   log.info("  > SPARQL query:\n" + sparqlQuery);
   InputStream in =
       SparqlEndpointUtils.sendSparqlRequest(
           getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE);
   long queryEnd = System.currentTimeMillis();
   log.info("  > QueryTime: " + (queryEnd - initEnd));
   if (in != null) {
     MGraph graph;
     TripleCollection rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE);
     if (rdfData instanceof MGraph) {
       graph = (MGraph) rdfData;
     } else {
       graph = new SimpleMGraph(rdfData);
     }
     long parseEnd = System.currentTimeMillis();
     log.info("  > ParseTime: " + (parseEnd - queryEnd));
     return new RdfQueryResultList(query, graph);
   } else {
     return null;
   }
 }
Ejemplo n.º 2
0
 @Override
 public QueryResultList<String> findEntities(FieldQuery parsedQuery) throws IOException {
   final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
   query.setEndpointType(EndpointTypeEnum.LARQ);
   String sparqlQuery = query.toSparqlSelect(false);
   InputStream in =
       SparqlEndpointUtils.sendSparqlRequest(
           getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_SPARQL_RESULT_CONTENT_TYPE);
   // Move to util class!
   final List<String> entities =
       SparqlSearcher.extractEntitiesFromJsonResult(in, query.getRootVariableName());
   return new QueryResultListImpl<String>(query, entities.iterator(), String.class);
 }