Пример #1
0
  /**
   * This method constructs numeric {@link OpFilter} instance with given index value and using given
   * substituted {@link OpFilter} instance
   *
   * @param index to add all variables in filter block
   * @param substitutedOp {@link OpFilter} instance whose filter block will be turned into numeric
   *     one.
   * @return numeric {@link OpFilter} instance
   */
  private static Op constructNumericOpFilter(int index, Op substitutedOp) {
    Op numericOpFilter = substitutedOp;

    // check whether op instance is an OpFilter
    if (substitutedOp instanceof OpFilter) {
      // turn OpFilter into query
      Query query = OpAsQuery.asQuery(substitutedOp);

      // System.out.println("Query before: " + query);

      // assign index
      final int finalIndex = index;
      // construct numeric filter block
      List<VariablePair> variablePairs = constructVariablePairs(query, finalIndex);
      // get query as text
      String queryStr = query.toString();
      // split query and get filter including second part of query text
      String[] splittedQuery = queryStr.split(FILTER_KEYWORD);
      // replace variables of given text
      String filterIncludingPart = replaceVariables(variablePairs, splittedQuery[1]);

      // construct final query
      String finalQueryText = splittedQuery[0] + FILTER_KEYWORD + filterIncludingPart;

      // System.out.println("Query after: " + finalQueryText);

      // create plan for query and get OpFilter instance from it
      numericOpFilter =
          QueryExecutionFactory.createPlan(
                  QueryFactory.create(finalQueryText), DatasetGraphFactory.createMem(), null)
              .getOp();
    }
    return numericOpFilter;
  }
Пример #2
0
 public static DatasetGraph initFuseki(URL rdfFile, String datasetName) {
   URI rdfFileUri = new File(rdfFile.getFile()).toURI();
   DatasetGraph datasetGraph = DatasetGraphFactory.createMem();
   RDFDataMgr.read(datasetGraph, rdfFileUri.toString());
   ServerConfig serverConfig = FusekiConfig.defaultConfiguration(datasetName, datasetGraph, true);
   SPARQLServer fusekiServer = new SPARQLServer(serverConfig);
   Fuseki.setServer(fusekiServer);
   fusekiServer.start();
   return datasetGraph;
 }