Package org.openrdf.repository

Examples of org.openrdf.repository.Repository


  }

  protected Repository createRepository()
    throws RepositoryException
  {
    Repository dataRep = new DatasetRepository(new SailRepository(new MemoryStore()));
    dataRep.initialize();
    return dataRep;
  }
View Full Code Here


    logger.info("Building test suite for {}", manifestFileURL);

    TestSuite suite = new TestSuite();

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();
    RepositoryConnection con = manifestRep.getConnection();

    con.add(new URL(manifestFileURL), manifestFileURL, RDFFormat.TURTLE);

    suite.setName(getManifestName(manifestRep, con, manifestFileURL));

    // Extract test case information from the manifest file. Note that we only
    // select those test cases that are mentioned in the list.
    StringBuilder query = new StringBuilder(512);
    query.append(" SELECT DISTINCT testURI, testName, resultFile, action, queryFile, defaultGraph ");
    query.append(" FROM {} rdf:first {testURI} dawgt:approval {dawgt:Approved}; ");
    query.append("                             mf:name {testName}; ");
    query.append("                             mf:result {resultFile}; ");
    query.append("                             mf:action {action} qt:query {queryFile}; ");
    query.append("                                               [qt:data {defaultGraph}] ");
    query.append(" USING NAMESPACE ");
    query.append("  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, ");
    query.append("  dawgt = <http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#>, ");
    query.append("  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
    TupleQuery testCaseQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());

    query.setLength(0);
    query.append(" SELECT graph ");
    query.append(" FROM {action} qt:graphData {graph} ");
    query.append(" USING NAMESPACE ");
    query.append(" qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
    TupleQuery namedGraphsQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());

    logger.debug("evaluating query..");
    TupleQueryResult testCases = testCaseQuery.evaluate();
    while (testCases.hasNext()) {
      BindingSet bindingSet = testCases.next();

      String testURI = bindingSet.getValue("testURI").toString();
      String testName = bindingSet.getValue("testName").toString();
      String resultFile = bindingSet.getValue("resultFile").toString();
      String queryFile = bindingSet.getValue("queryFile").toString();
      URI defaultGraphURI = (URI)bindingSet.getValue("defaultGraph");
      Value action = bindingSet.getValue("action");

      logger.debug("found test case : {}", testName);

      // Query named graphs
      namedGraphsQuery.setBinding("action", action);
      TupleQueryResult namedGraphs = namedGraphsQuery.evaluate();

      DatasetImpl dataset = null;

      if (defaultGraphURI != null || namedGraphs.hasNext()) {
        dataset = new DatasetImpl();

        if (defaultGraphURI != null) {
          dataset.addDefaultGraph(defaultGraphURI);
        }

        while (namedGraphs.hasNext()) {
          BindingSet graphBindings = namedGraphs.next();
          URI namedGraphURI = (URI)graphBindings.getValue("graph");
          dataset.addNamedGraph(namedGraphURI);
        }
      }

      suite.addTest(factory.createSPARQLQueryTest(testURI, testName, queryFile, resultFile, dataset));
    }

    testCases.close();
    con.close();

    manifestRep.shutDown();
    logger.info("Created test suite with " + suite.countTestCases() + " test cases.");
    return suite;
  }
View Full Code Here

  protected void runTest() throws Throwable {
    assertEquals(null, operator, compare(term1, term2));
  }

  protected Repository createRepository() throws Exception {
    Repository repository = newRepository();
    repository.initialize();
    RepositoryConnection con = repository.getConnection();
    con.clear();
    con.clearNamespaces();
    con.close();
    return repository;
  }
View Full Code Here

    else {
      sail.shutDown();
      fail("Invalid value for entailment level:" + entailment);
    }

    Repository dataRep = new SailRepository(sail);
    dataRep.initialize();

    RepositoryConnection dataCon = dataRep.getConnection();

    // Add unnamed gaph
    dataCon.add(new URL(dataFile), null, RDFFormat.forFileName(dataFile));

    // add named graphs
    for (String graphName : graphNames) {
      dataCon.add(new URL(graphName), null, RDFFormat.forFileName(graphName), new URIImpl(graphName));
    }

    // Evaluate the query on the query data
    GraphQueryResult result = dataCon.prepareGraphQuery(QueryLanguage.SERQL, query).evaluate();
    Collection<Statement> actualStatements = Iterations.addAll(result, new ArrayList<Statement>(1));
    result.close();

    dataCon.close();
    dataRep.shutDown();

    // Create a repository with the expected result data
    Repository expectedResultRep = new SailRepository(new MemoryStore());
    expectedResultRep.initialize();

    RepositoryConnection erCon = expectedResultRep.getConnection();

    erCon.add(new URL(resultFile), null, RDFFormat.forFileName(resultFile));

    Collection<Statement> expectedStatements = Iterations.addAll(erCon.getStatements(null, null, null,
        false), new ArrayList<Statement>(1));

    erCon.close();
    expectedResultRep.shutDown();

    // Compare query result to expected data
    if (!ModelUtil.equals(actualStatements, expectedStatements)) {
      // Found differences between expected and actual results
      StringBuilder message = new StringBuilder(128);
View Full Code Here

    throws Exception
  {
    TestSuite suite = new TestSuite();

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();

    RepositoryConnection con = manifestRep.getConnection();

    URL manifestURL = SeRQLQueryTest.class.getResource(MANIFEST_FILE);
    con.add(manifestURL, null, RDFFormat.forFileName(MANIFEST_FILE));

    String query = "SELECT testName, entailment, input, query, result " + "FROM {} mf:name {testName};"
        + "        mf:result {result}; " + "        tck:entailment {entailment}; "
        + "        mf:action {} qt:query {query}; " + "                     qt:data {input} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>, "
        + "  tck = <urn:openrdf.org:sesame:tests#> ";

    TupleQueryResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = ((Literal)testBindings.getValue("testName")).getLabel();
      String inputFile = testBindings.getValue("input").toString();
      String queryFile = testBindings.getValue("query").toString();
      String resultFile = testBindings.getValue("result").toString();
      String entailment = ((Literal)testBindings.getValue("entailment")).getLabel();

      query = "SELECT graph " + "FROM {} mf:name {testName}; "
          + "        mf:action {} qt:graphData {graph} " + "WHERE testName = \""
          + SeRQLUtil.encodeString(testName) + "\" " + "USING NAMESPACE"
          + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>,"
          + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

      List<String> graphNames = new ArrayList<String>();

      TupleQueryResult graphs = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
      while (graphs.hasNext()) {
        BindingSet graphBindings = graphs.next();
        graphNames.add(graphBindings.getValue("graph").toString());
      }
      graphs.close();

      suite.addTest(new SeRQLQueryTest(testName, inputFile, graphNames, queryFile, resultFile, entailment));
    }

    tests.close();
    con.close();
    manifestRep.shutDown();

    return suite;
  }
View Full Code Here

    TestSuite negativeTests = new TestSuite();
    negativeTests.setName("Negative Syntax Tests");

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();
    RepositoryConnection con = manifestRep.getConnection();

    URL manifestURL = SeRQLParserTest.class.getResource(MANIFEST_FILE);
    con.add(manifestURL, null, RDFFormat.forFileName(MANIFEST_FILE));

    String query = "SELECT testName, query, result " + "FROM {} mf:name {testName}; "
        + "        mf:action {query}; " + "        mf:result {result} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  mfx = <http://www.openrdf.org/test-manifest-extensions#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleQueryResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = testBindings.getValue("testName").toString();
      String queryFile = testBindings.getValue("query").toString();
      Value result = testBindings.getValue("result");
      if (MFX_CORRECT.equals(result)) {
        positiveTests.addTest(new SeRQLParserTest(testName, queryFile, result));
      }
      else if (MFX_PARSE_ERROR.equals(result)) {
        negativeTests.addTest(new SeRQLParserTest(testName, queryFile, result));
      }
      else {
        logger.warn("Unexpected result value for test \"" + testName + "\": " + result);
      }
    }

    tests.close();
    con.close();
    manifestRep.shutDown();

    suite.addTest(positiveTests);
    suite.addTest(negativeTests);
    return suite;
  }
View Full Code Here

  public static TestSuite suite(SPARQLQueryTest.Factory factory)
    throws Exception
  {
    TestSuite suite = new TestSuite();

    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();
    RepositoryConnection con = manifestRep.getConnection();

    con.add(new URL(MANIFEST_FILE), MANIFEST_FILE, RDFFormat.TURTLE);

    String query = "SELECT DISTINCT manifestFile " + "FROM {x} rdf:first {manifestFile} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleQueryResult manifestResults = con.prepareTupleQuery(QueryLanguage.SERQL, query, MANIFEST_FILE).evaluate();

    while (manifestResults.hasNext()) {
      BindingSet bindingSet = manifestResults.next();
      String manifestFile = bindingSet.getValue("manifestFile").toString();
      suite.addTest(SPARQLQueryTest.suite(manifestFile, factory));
    }

    manifestResults.close();
    con.close();
    manifestRep.shutDown();

    logger.info("Created aggregated test suite with " + suite.countTestCases() + " test cases.");
    return suite;
  }
View Full Code Here

    throws Exception
  {
    Collection<? extends Statement> entailedStatements = null;
    Collection<? extends Statement> expectedStatements = null;

    Repository repository = new SailRepository(sailStack);
    repository.initialize();

    RepositoryConnection con = repository.getConnection();
    con.setAutoCommit(false);

    // clear the input store
    con.clear();
    con.commit();

    // Upload input data
    InputStream stream = getClass().getResourceAsStream(inputData);
    try {
      con.add(stream, inputData, RDFFormat.NTRIPLES);
      con.commit();

      entailedStatements = Iterations.addAll(con.getStatements(null, null, null, true),
          new HashSet<Statement>());
    }
    finally {
      stream.close();
      con.close();
    }

    // Upload output data
    Repository outputRepository = new SailRepository(new MemoryStore());
    outputRepository.initialize();
    con = outputRepository.getConnection();
    con.setAutoCommit(false);

    stream = getClass().getResourceAsStream(outputData);
    try {
      con.add(stream, outputData, RDFFormat.NTRIPLES);
      con.commit();

      expectedStatements = Iterations.addAll(con.getStatements(null, null, null, false),
          new HashSet<Statement>());
    }
    finally {
      stream.close();
      con.close();
      outputRepository.shutDown();
      repository.shutDown();
    }

    // Check whether all expected statements are present in the entailment
    // closure set.
View Full Code Here

      System.err.println(e.getMessage());
      Options.usage();
      System.exit(0);
    }
   
    Repository confRepo = null, ontoRepo = null, dataRepo = null;
    try {
      confRepo = new SailRepository(new MemoryStore());
      ontoRepo = new SailRepository(new MemoryStore());
      dataRepo = new SailRepository(new MemoryStore());
      confRepo.initialize();
      ontoRepo.initialize();
      dataRepo.initialize();
    } catch (Exception e) { ; }
   
    try {
View Full Code Here

   * Can be used externally to get other models than default
   * @param repoSpec
   * @return
   */
  public Model parseModel(String repoSpec) {
    Repository repository = null;
   
    if(repoSpec == null)
      repository = new SailRepository(new MemoryStore());
    else if(!repoSpec.matches(patDef.toString())) {
      logger.warning("Provided parameter jonto.repository.spec  is not correct: "+repoSpec+"; Using memory repository instead");
      repository = new SailRepository(new MemoryStore());
    }else {
      Matcher m = patDef.matcher(repoSpec);
     
      if(m.find()) {
        String type = m.group(1);
        String param = m.group(2);
       
        if("HTTP".equals(type))
          repository = new HTTPRepository(param);
        else if("Memory".equals(type)) {
          if(param == null || "".equals(param))
            repository = new SailRepository(new MemoryStore());
          else
            repository = new SailRepository(new MemoryStore(new File(param)));
        }else
          repository = new SailRepository(new NativeStore(new File(param)));
      }else {
        logger.warning("Something was wrong when processing the jonto.repository.spec parameter ("+repoSpec+"); Using memory repository instead");
        repository = new SailRepository(new MemoryStore());
      }
    }
   
    Model _model;
    try {
      repository.initialize();

      // Then 'wrap' the sesame thing in an RDF2Go Model:
      _model = new RepositoryModel(repository)
      _model.open();
    } catch (RepositoryException e) {
View Full Code Here

TOP

Related Classes of org.openrdf.repository.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.