Examples of RepositoryConnection


Examples of org.openrdf.repository.RepositoryConnection

    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;
  }

Examples of org.openrdf.repository.RepositoryConnection

    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;
  }

Examples of org.openrdf.repository.RepositoryConnection

    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;
  }

Examples of org.openrdf.repository.RepositoryConnection

    throws StoreException
  {
    // Fetch statements from rep1 and rep2
    Set<Statement> model1, model2;

    RepositoryConnection con1 = rep1.getConnection();
    try {
      model1 = con1.match(null, null, null, true).asSet();
    }
    finally {
      con1.close();
    }

    RepositoryConnection con2 = rep2.getConnection();
    try {
      model2 = con2.match(null, null, null, true).asSet();
    }
    finally {
      con2.close();
    }

    return ModelUtil.equals(model1, model2);
  }

Examples of org.openrdf.repository.RepositoryConnection

  public static boolean isSubset(Repository rep1, Repository rep2)
    throws StoreException
  {
    Set<Statement> model1, model2;

    RepositoryConnection con1 = rep1.getConnection();
    try {
      model1 = con1.match(null, null, null, true).asSet();
    }
    finally {
      con1.close();
    }

    RepositoryConnection con2 = rep2.getConnection();
    try {
      model2 = con2.match(null, null, null, true).asSet();
    }
    finally {
      con2.close();
    }

    return ModelUtil.isSubset(model1, model2);
  }

Examples of org.openrdf.repository.RepositoryConnection

    throws StoreException
  {
    Collection<Statement> model1 = new HashSet<Statement>();
    Collection<Statement> model2 = new HashSet<Statement>();

    RepositoryConnection con1 = rep1.getConnection();
    try {
      con1.match(null, null, null, false).addTo(model1);
    }
    finally {
      con1.close();
    }

    RepositoryConnection con2 = rep2.getConnection();
    try {
      con2.match(null, null, null, false).addTo(model2);
    }
    finally {
      con2.close();
    }

    return difference(model1, model2);
  }

Examples of org.openrdf.repository.RepositoryConnection

      format = RDFParserRegistry.getInstance().getFileFormatForFileName(url.getFile(), RDFFormat.RDFXML);
    }

    InputStream stream = urlCon.getInputStream();
    try {
      RepositoryConnection repCon = getRepositoryConnection();
      try {
        repCon.begin();
        repCon.clear(context);
        repCon.add(stream, url.toExternalForm(), format, context);
        repCon.commit();
        lastModified.put(url, modified);
      }
      finally {
        repCon.close();
      }
    }
    finally {
      stream.close();
    }

Examples of org.openrdf.repository.RepositoryConnection

    if (repository == null) {
      writeError("please open a repository first");
      return;
    }

    RepositoryConnection con;
    try {
      con = repository.getConnection();

      try {
        NamespaceResult namespaces = con.getNamespaces();

        try {
          if (namespaces.hasNext()) {
            writeln("+----------");
            while (namespaces.hasNext()) {
              Namespace ns = namespaces.next();
              writeln("|" + ns.getPrefix() + "  " + ns.getName());
            }
            writeln("+----------");
          }
          else {
            writeln("--no namespaces found--");
          }
        }
        finally {
          namespaces.close();
        }
      }
      finally {
        con.close();
      }
    }
    catch (StoreException e) {
      writeError(e.getMessage());
      logger.error("Failed to show namespaces", e);

Examples of org.openrdf.repository.RepositoryConnection

    if (repository == null) {
      writeError("please open a repository first");
      return;
    }

    RepositoryConnection con;
    try {
      con = repository.getConnection();

      try {
        ContextResult contexts = con.getContextIDs();

        try {
          if (contexts.hasNext()) {
            writeln("+----------");
            while (contexts.hasNext()) {
              Resource context = contexts.next();
              writeln("|" + context.toString());
            }
            writeln("+----------");
          }
          else {
            writeln("--no contexts found--");
          }
        }
        finally {
          contexts.close();
        }
      }
      finally {
        con.close();
      }
    }
    catch (StoreException e) {
      writeError(e.getMessage());
      logger.error("Failed to show contexts", e);

Examples of org.openrdf.repository.RepositoryConnection

      RDFFormat format = Rio.getParserFormatForFileName(dataPath, RDFFormat.RDFXML);

      writeln("Loading data...");
      long startTime = System.nanoTime();

      RepositoryConnection con = repository.getConnection();
      try {
        Resource[] contexts = new Resource[0];

        if (context != null) {
          Resource contextURI;
          if (context.startsWith("_:")) {
            contextURI = con.getValueFactory().createBNode(context.substring(2));
          }
          else {
            contextURI = con.getValueFactory().createURI(context);
          }

          contexts = new Resource[] { contextURI };
        }
        if (dataURL != null) {
          con.add(dataURL, baseURI, format, contexts);
        }
        else {
          con.add(dataFile, baseURI, format, contexts);
        }
      }
      finally {
        con.close();
      }

      long endTime = System.nanoTime();
      writeln("Data has been added to the repository (" + (endTime - startTime) / 1000000 + " ms)");
    }
TOP
Copyright © 2018 www.massapi.com. 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.