Package org.openrdf.model

Examples of org.openrdf.model.ValueFactory


  {
    String ns1 = "a:";
    String ns2 = "b:";
    String ns3 = "c:";

    ValueFactory vf = new ValueFactoryImpl();
    URI uri1 = vf.createURI(ns1, "r1");
    URI uri2 = vf.createURI(ns2, "r2");
    URI uri3 = vf.createURI(ns3, "r3");
    Statement st = vf.createStatement(uri1, uri2, uri3);

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.handleNamespace("", ns1);
    rdfWriter.handleNamespace("", ns2);
View Full Code Here


  {
    String ns1 = "a:";
    String ns2 = "b:";
    String ns3 = "c:";

    ValueFactory vf = new ValueFactoryImpl();
    URI uri1 = vf.createURI(ns1, "r1");
    URI uri2 = vf.createURI(ns2, "r2");
    URI uri3 = vf.createURI(ns3, "r3");
    Statement st = vf.createStatement(uri1, uri2, uri3);

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.handleNamespace("1", ns1);
    rdfWriter.handleNamespace("_", ns2);
View Full Code Here

              && bindingSet.getValue("object") instanceof Value
              && (context == null || context instanceof Resource);
        }
      };

      final ValueFactory vf = getConnection().getRepository().getValueFactory();

      // Convert the BindingSet objects to actual RDF statements
      CloseableIteration<Statement, QueryEvaluationException> stIter;
      stIter = new ConvertingIteration<BindingSet, Statement, QueryEvaluationException>(bindingsIter) {

        @Override
        protected Statement convert(BindingSet bindingSet) {
          Resource subject = (Resource)bindingSet.getValue("subject");
          URI predicate = (URI)bindingSet.getValue("predicate");
          Value object = bindingSet.getValue("object");
          Resource context = (Resource)bindingSet.getValue("context");

          if (context == null) {
            return vf.createStatement(subject, predicate, object);
          }
          else {
            return vf.createStatement(subject, predicate, object, context);
          }
        }
      };

      return new GraphQueryResultImpl(getParsedQuery().getQueryNamespaces(), stIter);
View Full Code Here

    throws Exception
  {
    MemoryStore store = new MemoryStore(dataDir);
    store.initialize();

    ValueFactory factory = store.getValueFactory();
    URI foo = factory.createURI("http://www.foo.example/foo");
    URI bar = factory.createURI("http://www.foo.example/bar");

    SailConnection con = store.getConnection();
    con.addStatement(foo, RDF.TYPE, bar);
    con.commit();

    ParsedTupleQuery query = QueryParserUtil.parseTupleQuery(QueryLanguage.SERQL,
        "SELECT X, P, Y FROM {X} P {Y}", null);
    TupleExpr tupleExpr = query.getTupleExpr();

    CloseableIteration<? extends BindingSet, QueryEvaluationException> iter = con.evaluate(tupleExpr, null,
        EmptyBindingSet.getInstance(), false);

    BindingSet bindingSet = iter.next();

    assertEquals(bindingSet.getValue("X"), foo);
    assertEquals(bindingSet.getValue("P"), RDF.TYPE);
    assertEquals(bindingSet.getValue("Y"), bar);
    iter.close();
    con.close();

    store.shutDown();

    store = new MemoryStore(dataDir);
    store.initialize();

    factory = store.getValueFactory();
    foo = factory.createURI("http://www.foo.example/foo");
    bar = factory.createURI("http://www.foo.example/bar");

    con = store.getConnection();

    iter = con.evaluate(tupleExpr, null, EmptyBindingSet.getInstance(), false);
View Full Code Here

    repository.shutDown();
  }

  private void createEmployee(String id, String name, int empId)
      throws RepositoryException {
    ValueFactory vf = repository.getValueFactory();
    String foafName = "http://xmlns.com/foaf/0.1/name";
    String exEmpId = "http://example.org/ns#empId";
    RepositoryConnection conn = repository.getConnection();
    conn.add(vf.createURI("http://example.org/ns#" + id), vf
        .createURI(foafName), vf.createLiteral(name));
    conn.add(vf.createURI("http://example.org/ns#" + id), vf
        .createURI(exEmpId), vf.createLiteral(empId));
    conn.close();
  }
View Full Code Here

    }
    implConfig.validate();
  }

  public void export(Graph graph) {
    ValueFactory vf = graph.getValueFactory();

    BNode repositoryNode = vf.createBNode();

    graph.add(repositoryNode, RDF.TYPE, REPOSITORY);

    if (id != null) {
      graph.add(repositoryNode, REPOSITORYID, vf.createLiteral(id));
    }
    if (title != null) {
      graph.add(repositoryNode, RDFS.LABEL, vf.createLiteral(title));
    }
    if (implConfig != null) {
      Resource implNode = implConfig.export(graph);
      graph.add(repositoryNode, REPOSITORYIMPL, implNode);
    }
View Full Code Here

   * @throws RepositoryConfigException
   */
  public static void updateRepositoryConfigs(RepositoryConnection con, RepositoryConfig... configs)
    throws RepositoryException, RepositoryConfigException
  {
    ValueFactory vf = con.getRepository().getValueFactory();

    boolean wasAutoCommit = con.isAutoCommit();
    con.setAutoCommit(false);

    for (RepositoryConfig config : configs) {
      Resource context = getContext(con, config.getID());

      if (context != null) {
        con.clear(context);
      }
      else {
        context = vf.createBNode();
      }

      con.add(context, RDF.TYPE, REPOSITORY_CONTEXT);

      Graph graph = new GraphImpl(vf);
View Full Code Here

      }

      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

    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));
        TupleQueryResult queryResult = query.evaluate();

        try {
          if (!queryResult.hasNext()) {
            writeError("Unable to find context information for repository '" + id + "'");
View Full Code Here

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

    ValueFactory valueFactory = repository.getValueFactory();

    Resource[] contexts = new Resource[tokens.length - 1];

    for (int i = 1; i < tokens.length; i++) {
      String contextID = tokens[i];

      if (contextID.equalsIgnoreCase("null")) {
        contexts[i - 1] = null;
      }
      else if (contextID.startsWith("_:")) {
        contexts[i - 1] = valueFactory.createBNode(contextID.substring(2));
      }
      else {
        try {
          contexts[i - 1] = valueFactory.createURI(contextID);
        }
        catch (IllegalArgumentException e) {
          writeError("illegal URI: " + contextID);
          printHelpClear();
          return;
View Full Code Here

TOP

Related Classes of org.openrdf.model.ValueFactory

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.