Package org.openrdf.repository

Examples of org.openrdf.repository.Repository


  protected void setRequestAttributes(HttpServletRequest request)
    throws ClientHTTPException, ServerHTTPException
  {
    if (repositoryID != null) {
      try {
        Repository repository = repositoryManager.getRepository(repositoryID);

        if (repository == null) {
          throw new ClientHTTPException(SC_NOT_FOUND, "Unknown repository: " + repositoryID);
        }

        repositoryCon = repository.getConnection();
        request.setAttribute(REPOSITORY_ID_KEY, repositoryID);
        request.setAttribute(REPOSITORY_KEY, repository);
        request.setAttribute(REPOSITORY_CONNECTION_KEY, repositoryCon);
      }
      catch (RepositoryConfigException e) {
View Full Code Here


    String outputURL = inputURL;
    String baseURL = NTRIPLES_TEST_URL;
    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 = TurtleParserTest.class.getResource(MANIFEST_GOOD_URL);
    con.add(url, 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#>";

    TupleQueryResult 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 = TurtleParserTest.class.getResource(MANIFEST_BAD_URL);
    con.add(url, 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

    /** add the classes and properties of an ontology into the store
     *@param docURI the ontology's URI
     *@param locationPath an alternative local path where the ontology can be found (null if none); cam be given as a relative path
     */
    public void addOntology(String docURI, String locationPath){
  Repository r = new SailRepository(new MemoryStore());
  try {
      r.initialize();
      RepositoryConnection c = r.getConnection();
      if (DEBUG){
    System.out.println("Retrieving ontology "+docURI);
      }
      try {
     c.add(new URL(docURI), docURI, RDFFormat.RDFXML);
View Full Code Here

  }

  private void createRepository(String templateName)
    throws IOException
  {
    Repository systemRepo = manager.getSystemRepository();

    try {
      // FIXME: remove assumption of .ttl extension
      String templateFileName = templateName + ".ttl";

      File templatesDir = new File(appConfig.getDataDir(), TEMPLATES_DIR);

      File templateFile = new File(templatesDir, templateFileName);
      InputStream templateStream;

      if (templateFile.exists()) {
        if (!templateFile.canRead()) {
          writeError("Not allowed to read template file: " + templateFile);
          return;
        }

        templateStream = new FileInputStream(templateFile);
      }
      else {
        // Try classpath for built-ins
        templateStream = Console.class.getResourceAsStream(templateFileName);

        if (templateStream == null) {
          writeError("No template called " + templateName + " found in " + templatesDir);
          return;
        }
      }

      String template = IOUtil.readString(new InputStreamReader(templateStream, "UTF-8"));
      templateStream.close();

      ConfigTemplate configTemplate = new ConfigTemplate(template);

      Map<String, String> valueMap = new HashMap<String, String>();
      Map<String, List<String>> variableMap = configTemplate.getVariableMap();

      if (!variableMap.isEmpty()) {
        writeln("Please specify values for the following variables:");
      }

      for (Map.Entry<String, List<String>> entry : variableMap.entrySet()) {
        String var = entry.getKey();
        List<String> values = entry.getValue();

        write(var);
        if (values.size() > 1) {
          write(" (");
          for (int i = 0; i < values.size(); i++) {
            if (i > 0) {
              write("|");
            }
            write(values.get(i));
          }
          write(")");
        }
        if (!values.isEmpty()) {
          write(" [" + values.get(0) + "]");
        }
        write(": ");

        String value = in.readLine();
        if (value == null) {
          // EOF
          return;
        }

        value = value.trim();
        if (value.length() == 0) {
          value = null;
        }
        valueMap.put(var, value);
      }

      String configString = configTemplate.render(valueMap);
      // writeln(configString);

      ValueFactory vf = systemRepo.getValueFactory();

      Graph graph = new GraphImpl(vf);

      RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE, vf);
      rdfParser.setRDFHandler(new StatementCollector(graph));
View Full Code Here

      return;
    }

    String id = tokens[1];

    Repository systemRepo = manager.getSystemRepository();

    try {
      ValueFactory vf = systemRepo.getValueFactory();

      RepositoryConnection con = systemRepo.getConnection();

      try {
        Resource context;
        TupleQuery query = con.prepareTupleQuery(QueryLanguage.SERQL, REPOSITORY_CONTEXT_QUERY);
        query.setBinding("ID", vf.createLiteral(id));
View Full Code Here

    }
  }

  private void openRepository(String id) {
    try {
      Repository newRepository = manager.getRepository(id);

      if (newRepository != null) {
        // Close current repository, if any
        closeRepository(false);
View Full Code Here

    }
  }

  private void showRepositories() {
    try {
      Repository systemRepo = manager.getSystemRepository();
      RepositoryConnection con = systemRepo.getConnection();
      try {
        TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, REPOSITORY_LIST_QUERY).evaluate();
        try {
          if (!queryResult.hasNext()) {
            writeln("--no repositories found--");
View Full Code Here

  }

  public void testWrite()
    throws RepositoryException, 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);

    con1.close();

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

    RepositoryConnection con2 = rep2.getConnection();

    con2.add(new StringReader(writer.toString()), "foo:bar", RDFFormat.RDFXML);
    con2.close();

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

  protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
    throws Exception
  {
    ProtocolUtil.logRequestParameters(request);

    Repository repository = RepositoryInterceptor.getRepository(request);
    RepositoryConnection repositoryCon = RepositoryInterceptor.getRepositoryConnection(request);

    ValueFactory vf = repository.getValueFactory();
    Resource[] contexts = ProtocolUtil.parseContextParam(request, Protocol.CONTEXT_PARAM_NAME, vf);

    long size = -1;

    try {
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();

    logger.debug("Loading manifest data");
    URL manifest = new URL(MANIFEST_FILE);
    RDFFormat rdfFormat = RDFFormat.forFileName(MANIFEST_FILE, RDFFormat.TURTLE);
    con.add(manifest, MANIFEST_FILE, rdfFormat);

    logger.info("Searching for sub-manifests");
    List<String> subManifestList = new ArrayList<String>();

    TupleQueryResult subManifests = con.prepareTupleQuery(QueryLanguage.SERQL, SUBMANIFEST_QUERY).evaluate();
    while (subManifests.hasNext()) {
      BindingSet bindings = subManifests.next();
      subManifestList.add(bindings.getValue("subManifest").toString());
    }
    subManifests.close();

    logger.info("Found {} sub-manifests", subManifestList.size());

    for (String subManifest : subManifestList) {
      logger.info("Loading sub manifest {}", subManifest);
      con.clear();

      URL subManifestURL = new URL(subManifest);
      rdfFormat = RDFFormat.forFileName(subManifest, RDFFormat.TURTLE);
      con.add(subManifestURL, subManifest, rdfFormat);

      TestSuite subSuite = new TestSuite(subManifest.substring(HOST.length()));

      logger.info("Creating test cases for {}", subManifest);
      TupleQueryResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, TESTCASE_QUERY).evaluate();
      while (tests.hasNext()) {
        BindingSet bindingSet = tests.next();

        String testURI = bindingSet.getValue("TestURI").toString();
        String testName = bindingSet.getValue("Name").toString();
        String testAction = bindingSet.getValue("Action").toString();
        boolean positiveTest = bindingSet.getValue("Type").toString().equals(
            "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#PositiveSyntaxTest");

        subSuite.addTest(new SPARQLSyntaxTest(testURI, testName, testAction, positiveTest));
      }
      tests.close();

      suite.addTest(subSuite);
    }

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

    logger.info("Created test suite containing " + suite.countTestCases() + " test cases");
    return suite;
  }
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.