예제 #1
0
 public String getCurrentQuery() throws AutoSPARQLException {
   try {
     //			return exampleFinder.getCurrentQueryHTML();
     return exampleFinder.getCurrentQuery();
   } catch (Exception e) {
     logger.error("Error while getting current query.", e);
     throw new AutoSPARQLException(e);
   }
 }
예제 #2
0
  public PagingLoadResult<Example> getCurrentQueryResult(PagingLoadConfig config)
      throws SPARQLQueryException {
    logger.debug("Retrieving results for current query.");
    List<Example> queryResult = new ArrayList<Example>();

    String currentQuery = exampleFinder.getCurrentQuery();
    logger.debug("Current query:\n");
    logger.debug(currentQuery);
    int limit = config.getLimit();
    int offset = config.getOffset();
    int totalLength = 10;

    try {
      ResultSetRewindable rs =
          SparqlQuery.convertJSONtoResultSet(
              selectCache.executeSelectQuery(endpoint, getCountQuery(currentQuery)));
      totalLength = rs.next().getLiteral(rs.getResultVars().get(0)).getInt();
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      ResultSetRewindable rs =
          SparqlQuery.convertJSONtoResultSet(
              selectCache.executeSelectQuery(
                  endpoint, modifyQuery(currentQuery + " LIMIT " + limit + " OFFSET " + offset)));

      String uri;
      String label = "";
      String imageURL = "";
      String comment = "";
      QuerySolution qs;
      while (rs.hasNext()) {
        qs = rs.next();
        uri = qs.getResource("x0").getURI();
        label = qs.getLiteral("label").getLexicalForm();
        queryResult.add(new Example(uri, label, imageURL, comment));
      }
    } catch (Exception e) {
      logger.error("Error while getting result for query \n" + currentQuery, e);
    }

    PagingLoadResult<Example> result = new BasePagingLoadResult<Example>(queryResult);
    result.setOffset(offset);
    result.setTotalLength(totalLength);

    return result;
  }
예제 #3
0
 public void saveSPARQLQuery(Store store) throws AutoSPARQLException {
   List<Example> posExamples = new ArrayList<Example>();
   for (String uri : exampleFinder.getPositiveExamples()) {
     posExamples.add(examplesCache.get(uri));
   }
   List<Example> negExamples = new ArrayList<Example>();
   for (String uri : exampleFinder.getNegativeExamples()) {
     negExamples.add(examplesCache.get(uri));
   }
   store.saveSPARQLQuery(
       question,
       exampleFinder.getCurrentQuery(),
       endpoint.getLabel(),
       posExamples,
       negExamples,
       exampleFinder.getLastSuggestedExample());
 }