Exemple #1
0
 public static TupleQuery getQuery(
     RepositoryConnection connection, ParsedTupleQuery tupleQueryModel, boolean includeInferred) {
   try {
     // System.err.println(tupleQueryModel.getTupleExpr());
     QUERY_HOLDER.set(tupleQueryModel);
     TupleQuery tupleQuery = connection.prepareTupleQuery(DirectQuery.DIRECTQUERY, "");
     tupleQuery.setIncludeInferred(includeInferred);
     return tupleQuery;
   } catch (MalformedQueryException e) {
     throw new RepositoryException(e);
   } catch (org.openrdf.repository.RepositoryException e) {
     throw new RepositoryException(e);
   }
 }
  // sparql
  public void sparql() throws IOException, RepositoryException, QueryEvaluationException {

    // find all expired data to avoid them participating the query:
    this.toDeleteCounter = 0;
    this.dropQueryString = "";
    ArrayList<GraphIdCounterPair> expiredData = new ArrayList<GraphIdCounterPair>();
    LocalTime evictionTime = LocalTime.now();
    for (GraphIdCounterPair x : this.cacheContentOfGraphIds) {
      System.out.print(
          this.evictCounter
              + ", "
              + this.size
              + ", "
              + this.evictAmount
              + ", "
              + x.graphId
              + ", "
              + x.arrivalTime
              + ", "
              + x.expirationTime);
      if (x.expirationTime.isBefore(evictionTime)) {
        expiredData.add(x);
        dropQueryString += "drop graph <" + x.graphId + ">;";
        System.out.println(", expired");
        ++toDeleteCounter;
      } else {
        System.out.println();
      }
    }
    System.out.println("[INFO] " + expiredData.size() + " data expired!");
    if (!expiredData.isEmpty()) {
      // delete expired data from the cache
      for (GraphIdCounterPair x : expiredData) {
        this.cacheContentOfGraphIds.remove(x);
      }
      // delete the expired data from the database
      QueryExecution qe =
          AGQueryExecutionFactory.create(AGQueryFactory.create(dropQueryString), model);
      qe.execAsk();
      qe.close();
    }

    // after deleting expired data, load the cache again
    this.streamEmulation();
    System.out.println(this.reasoner.getEntailmentRegime());
    this.infModel = new AGInfModel(this.reasoner, this.model);
    String queryString =
        "select distinct ?s "
            + "where { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"
            + "<http://swat.cse.lehigh.edu/onto/univ-bench.owl#Professor>.}";
    AGRepositoryConnection conn = this.client.getAGConn();
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleQuery.setIncludeInferred(true);
    long sparqlStartTime = System.currentTimeMillis();
    TupleQueryResult resultSet = tupleQuery.evaluate();
    long sparqlEndTime = System.currentTimeMillis();
    this.aveSparql += (sparqlEndTime - sparqlStartTime);

    ArrayList<String> results = new ArrayList<String>();
    while (resultSet.hasNext()) {
      String result = resultSet.next().toString();
      System.out.println("result");
      int length = result.length();
      results.add(result.substring(3, length - 1));
    }
    resultSet.close();

    this.fMeasureBench(results);
    this.infModel.close();
  }