Package org.openrdf.repository

Examples of org.openrdf.repository.RepositoryConnection


  }

  private void removeProtectedStatement()
    throws StoreException
  {
    RepositoryConnection con = repository.getConnection();
    try {
      ValueFactory vf = con.getValueFactory();
      con.removeMatch(vf.createURI(RNA_RECYCLE), null, null);
    }
    finally {
      con.close();
    }
  }
View Full Code Here


  }

  private boolean hasProtectedStatement()
    throws StoreException
  {
    RepositoryConnection con = repository.getConnection();
    try {
      ValueFactory vf = con.getValueFactory();
      return con.hasMatch(vf.createURI(RNA_RECYCLE), RDF.TYPE, vf.createURI(SKOS_CONCEPT), true);
    }
    finally {
      con.close();
    }
  }
View Full Code Here

  private List<String> evaluate(String name, String query)
    throws Exception
  {
    List<String> labels = new ArrayList<String>();
    RepositoryConnection con = repository.getConnection();
    try {
      assertTrue(con.size() > 0);
      TupleQuery qry = con.prepareTupleQuery(SPARQL, query);
      TupleResult result = qry.evaluate();
      try {
        while (result.hasNext()) {
          Value value = result.next().getValue(name);
          if (value == null) {
            labels.add(null);
          } else {
            labels.add(value.stringValue());
          }
        }
      }
      finally {
        result.close();
      }
    }
    finally {
      con.close();
    }
    return labels;
  }
View Full Code Here

  }

  private void load(String resource)
    throws Exception
  {
    RepositoryConnection con = repository.getConnection();
    try {
      ClassLoader cl = getClass().getClassLoader();
      URL url = cl.getResource(resource);
      con.add(url, "", RDFFormat.forFileName(resource));
    } finally {
      con.close();
    }
  }
View Full Code Here

    TestSuite suite = new TestSuite(TriGParserTestCase.class.getName());

    // Add the manifest for positive test cases to a repository and query it
    Repository repository = new SailRepository(new MemoryStore());
    repository.initialize();
    RepositoryConnection con = repository.getConnection();

    URL url = TriGParserTestCase.class.getResource(MANIFEST_GOOD_URL);
    con.add(url, base(url.toExternalForm()), RDFFormat.TURTLE);

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

    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all positive parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testName = bindingSet.getValue("testName").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();
      String outputURL = bindingSet.getValue("outputURL").toString();

      String baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new PositiveParserTest(testName, inputURL, outputURL, baseURL));
    }

    queryResult.close();

    // Add the manifest for negative test cases to a repository and query it
    con.clear();
    url = TriGParserTestCase.class.getResource(MANIFEST_BAD_URL);
    con.add(url, base(url.toExternalForm()), RDFFormat.TURTLE);

    query = "SELECT testName, inputURL " + "FROM {} mf:name {testName}; "
        + "        mf:action {} qt:data {inputURL} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all negative parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testName = bindingSet.getValue("testName").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();

      String baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new NegativeParserTest(testName, inputURL, baseURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

    throws StoreException, RDFParseException, IOException, RDFHandlerException
  {
    Repository rep1 = new SailRepository(new MemoryStore());
    rep1.initialize();

    RepositoryConnection con1 = rep1.getConnection();

    URL ciaScheme = this.getClass().getResource("/cia-factbook/CIA-onto-enhanced.rdf");
    URL ciaFacts = this.getClass().getResource("/cia-factbook/CIA-facts-enhanced.rdf");

    con1.add(ciaScheme, ciaScheme.toExternalForm(), RDFFormat.forFileName(ciaScheme.toExternalForm()));
    con1.add(ciaFacts, ciaFacts.toExternalForm(), RDFFormat.forFileName(ciaFacts.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();

    Repository rep2 = new SailRepository(new MemoryStore());
    rep2.initialize();

    RepositoryConnection con2 = rep2.getConnection();

    con2.add(new StringReader(writer.toString()), "foo:bar", rdfWriterFactory.getRDFFormat());
    long after = con2.size();
    con2.close();

    assertEquals("result of serialization and re-upload should be equal to original", before, after);

    assertTrue("result of serialization and re-upload should be equal to original", RepositoryUtil.equals(
        rep1, rep2));
View Full Code Here

    throws StoreException, RDFParseException, IOException, RDFHandlerException
  {
    Repository rep1 = new SailRepository(new MemoryStore());
    rep1.initialize();

    RepositoryConnection con1 = rep1.getConnection();

    URL ciaScheme = this.getClass().getResource("/cia-factbook/CIA-onto-enhanced.rdf");
    URL ciaFacts = this.getClass().getResource("/cia-factbook/CIA-facts-enhanced.rdf");

    con1.add(ciaScheme, ciaScheme.toExternalForm(), RDFFormat.forFileName(ciaScheme.toExternalForm()));
    con1.add(ciaFacts, ciaFacts.toExternalForm(), RDFFormat.forFileName(ciaFacts.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.setBaseURI(ciaFacts.toExternalForm());
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();

    Repository rep2 = new SailRepository(new MemoryStore());
    rep2.initialize();

    RepositoryConnection con2 = rep2.getConnection();

    con2.add(new StringReader(writer.toString()), ciaFacts.toExternalForm(),
        rdfWriterFactory.getRDFFormat());
    long after = con2.size();
    con2.close();

    assertEquals("result of serialization and re-upload should be equal to original", before, after);

    assertTrue("result of serialization and re-upload should be equal to original", RepositoryUtil.equals(
        rep1, rep2));
View Full Code Here

    TestSuite suite = new TestSuite(N3ParserTestCase.class.getName());

    // Add the manifest to a repository and query it
    Repository repository = new SailRepository(new MemoryStore());
    repository.initialize();
    RepositoryConnection con = repository.getConnection();

    URL url = url(MANIFEST_URL);
    con.add(url, base(MANIFEST_URL), RDFFormat.TURTLE);

    // Add all positive parser tests to the test suite
    String query = "SELECT testURI, inputURL, outputURL "
        + "FROM {testURI} rdf:type {n3test:PositiveParserTest}; "
        + "               n3test:inputDocument {inputURL}; "
        + "               n3test:outputDocument {outputURL} "
        + "USING NAMESPACE n3test = <http://www.w3.org/2004/11/n3test#>";

    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testURI = bindingSet.getValue("testURI").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();
      String outputURL = bindingSet.getValue("outputURL").toString();

      suite.addTest(new PositiveParserTest(testURI, inputURL, outputURL));
    }

    queryResult.close();

    // Add all negative parser tests to the test suite
    query = "SELECT testURI, inputURL " + "FROM {testURI} rdf:type {n3test:NegativeParserTest}; "
        + "               n3test:inputDocument {inputURL} "
        + "USING NAMESPACE n3test = <http://www.w3.org/2004/11/n3test#>";

    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testURI = bindingSet.getValue("testURI").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();

      suite.addTest(new NegativeParserTest(testURI, inputURL));
    }
    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

    suite.addTest(new PositiveParserTest(testName, inputURL, outputURL, baseURL));

    // Add the manifest for positive test cases to a repository and query it
    Repository repository = new SailRepository(new MemoryStore());
    repository.initialize();
    RepositoryConnection con = repository.getConnection();

    url = TurtleParserTestCase.class.getResource(MANIFEST_GOOD_URL);
    con.add(url, base(url.toExternalForm()), RDFFormat.TURTLE);

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

    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all positive parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      testName = ((Literal)bindingSet.getValue("testName")).getLabel();
      inputURL = ((URI)bindingSet.getValue("inputURL")).toString();
      outputURL = ((URI)bindingSet.getValue("outputURL")).toString();

      baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new PositiveParserTest(testName, inputURL, outputURL, baseURL));
    }

    queryResult.close();

    // Add the manifest for negative test cases to a repository and query it
    con.clear();
    url = TurtleParserTestCase.class.getResource(MANIFEST_BAD_URL);
    con.add(url, base(url.toExternalForm()), RDFFormat.TURTLE);

    query = "SELECT testName, inputURL " + "FROM {} mf:name {testName}; "
        + "        mf:action {} qt:data {inputURL} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all negative parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      testName = ((Literal)bindingSet.getValue("testName")).toString();
      inputURL = ((URI)bindingSet.getValue("inputURL")).toString();

      baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new NegativeParserTest(testName, inputURL, baseURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

    throws Exception
  {
    // Create an RDF repository for the manifest data
    Repository repository = new SailRepository(new MemoryStore());
    repository.initialize();
    RepositoryConnection con = repository.getConnection();

    // Add W3C's manifest
    URL w3cManifest = resolveURL(W3C_MANIFEST_FILE);
    con.add(w3cManifest, base(W3C_MANIFEST_FILE), RDFFormat.RDFXML);

    // Add our own manifest
    URL localManifest = resolveURL(OPENRDF_MANIFEST_FILE);
    con.add(localManifest, base(localManifest.toString()), RDFFormat.RDFXML);

    // Create test suite
    TestSuite suite = new TestSuite(RDFXMLParserTestCase.class.getName());

    // Add all positive parser tests
    String query = "select TESTCASE, INPUT, OUTPUT "
        + "from {TESTCASE} rdf:type {test:PositiveParserTest}; "
        + "                test:inputDocument {INPUT}; "
        + "                test:outputDocument {OUTPUT}; "
        + "                test:status {\"APPROVED\"} "
        + "using namespace test = <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>";
    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String caseURI = bindingSet.getValue("TESTCASE").toString();
      String inputURL = bindingSet.getValue("INPUT").toString();
      String outputURL = bindingSet.getValue("OUTPUT").toString();
      suite.addTest(new PositiveParserTest(caseURI, inputURL, outputURL));
    }

    queryResult.close();

    // Add all negative parser tests
    query = "select TESTCASE, INPUT " + "from {TESTCASE} rdf:type {test:NegativeParserTest}; "
        + "                test:inputDocument {INPUT}; " + "                test:status {\"APPROVED\"} "
        + "using namespace test = <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String caseURI = bindingSet.getValue("TESTCASE").toString();
      String inputURL = bindingSet.getValue("INPUT").toString();
      suite.addTest(new NegativeParserTest(caseURI, inputURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

TOP

Related Classes of org.openrdf.repository.RepositoryConnection

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.