Package org.openrdf.model.impl

Examples of org.openrdf.model.impl.GraphImpl


    testCon.add(alice, name, nameAlice);

    Graph graph;
    RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, true);
    try {
      graph = new GraphImpl(vf, statements.asList());
    }
    finally {
      statements.close();
    }
View Full Code Here


   * Provides empty in-memory graph instance
   *
   * @return instanec of Graph interface
   */
  public static Graph getEmptyGraph() {
    return new GraphImpl();
  }
View Full Code Here

    private ValueFactory vf;

    private Graph storageGraph;

    public SesameTripleCallback() {
        this(new GraphImpl());
    }
View Full Code Here

   * Convert the Jena Model to a Sesame Graph
   * @param theModel the model to convert
   * @return the set of statements in the Jena model saved in a sesame Graph
   */
  public static Graph asSesameGraph(Model theModel) {
    Graph aGraph = new GraphImpl();

    StmtIterator sIter = theModel.listStatements();
    while (sIter.hasNext()) {
      aGraph.add(asSesameStatement(sIter.nextStatement()));
    }

    sIter.close();

    return aGraph;
View Full Code Here

          if (aDbObj != null) {
            aExistingData = ((EmpireGenerated) aDbObj).getInstanceTriples();
          }
          else {
            aExistingData = new GraphImpl();
          }
        }
        else {
          // as a fall back, we can perform a describe to find all related triples for the individual;
          // unfortunately, describe returns more information (in fact, it probably gives us more what getAllTriples() would return
          // rather than getInstanceTriples()), but there is not much else we can do
          aExistingData = assertContainsAndDescribe(theT);
        }
      }
      catch (IllegalArgumentException e) {
        // when everything else fails, just assume that existing data was indeed empty ...
        aExistingData = new GraphImpl();
      }
    }

    try {
      preUpdate(theT);
View Full Code Here

    try {
      Graph aGraph = RdfGenerator.asRdf(aBob);

      // this is the set of data that would normally be in the database
      Graph aSourceGraph = new GraphImpl();
      aSourceGraph.addAll(aGraph);
      aSourceGraph.addAll(RdfGenerator.asRdf(aJoe));
      aSourceGraph.addAll(RdfGenerator.asRdf(aJane));

      TestPerson aPerson = RdfGenerator.fromRdf(TestPerson.class, aBob.getRdfId(), new TestDataSource(aSourceGraph));

      assertEquals(aBob, aPerson);

      // now lets test the round trip w/ the added trick of a circular dependency
      aBob.setSpouse(aJane);

      aGraph = RdfGenerator.asRdf(aBob);

      // this is the set of data that would normally be in the database
      aSourceGraph = new GraphImpl();
      aSourceGraph.addAll(aGraph);
      aSourceGraph.addAll(RdfGenerator.asRdf(aJoe));
      aSourceGraph.addAll(RdfGenerator.asRdf(aJane));

      aPerson = RdfGenerator.fromRdf(TestPerson.class, aBob.getRdfId(), new TestDataSource(aSourceGraph));

      // should still be equal, should have re-used Jane
      assertEquals(aBob, aPerson);
View Full Code Here

            klasses.add( MyRootClass.class );
            RdfGenerator.init( klasses );

            Graph aGraph = RdfGenerator.asRdf( root );

            Graph aSourceGraph = new GraphImpl();
            aSourceGraph.addAll(aGraph);

            MyRootClass aRoot = RdfGenerator.fromRdf(MyRootClass.class, "urn:id:00", new TestDataSource(aSourceGraph));
            assertSame( aRoot.getFoo().get( 0 ).getClass(), aImpl.getClass() );
        } catch ( Exception e ) {
            e.printStackTrace();
View Full Code Here

      }
      endTest(ok && result); // should return sz > 0 results 
     
      // do construct
      startTest();
      Graph g = new GraphImpl();
      boolean statementFound = false;
      try {
        ok = true;
        log("Sending construct query");
        query = "CONSTRUCT {?s <http://myopenlink.net/mlo/handle> ?o} FROM <" + context + "> WHERE {?s <http://myopenlink.net/foaf/name> ?o}";
        g = doGraphQuery(con, query);
        Iterator<Statement> it = g.iterator();
        statementFound = true;
        while(it.hasNext()) {
          Statement st = it.next();
          if( !st.getPredicate().stringValue().equals("http://myopenlink.net/mlo/handle")) statementFound = false;
        }
      }
      catch (Exception e) {
        System.out.println("Error[" + e + "]");
        e.printStackTrace();
        ok = false;
      }
      endTest(ok && g.size() > 0); // should return sz > 0 results 
     
      // do describe
      startTest();
      g = new GraphImpl();
      statementFound = false;
      try {
        ok = true;
        log("Sending describe query");
        query = "DESCRIBE ?s FROM <" + context + "> WHERE {?s <http://myopenlink.net/foaf/name> ?o}";
        g = doGraphQuery(con, query);
        Iterator<Statement> it = g.iterator();
        statementFound = it.hasNext();
//        while(it.hasNext()) {
//          Statement st = it.next();
//          if( !st.getPredicate().stringValue().equals("http://myopenlink.net/mlo/handle")) statementFound = false;
//        }
View Full Code Here

  }

  private static Graph doGraphQuery(RepositoryConnection con, String query) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    GraphQuery resultsTable = con.prepareGraphQuery(QueryLanguage.SPARQL, query);
    GraphQueryResult statements = resultsTable.evaluate();
    Graph g = new GraphImpl();

    Vector<Value[]> results = new Vector<Value[]>();
    for (int row = 0; statements.hasNext(); row++) {
      Statement pairs = statements.next();
      g.add(pairs);
//      List<String> names = statements.getBindingNames();
//      Value[] rv = new Value[names.size()];
//      for (int i = 0; i < names.size(); i++) {
//        String name = names.get(i);
//        Value value = pairs.getValue(name);
View Full Code Here

      }
      endTest(ok && result); // should return sz > 0 results 
     
      // do construct
      startTest();
      Graph g = new GraphImpl();
      boolean statementFound = false;
      try {
        ok = true;
        log("Sending construct query");
        query = "CONSTRUCT {?s <http://myopenlink.net/mlo/handle> ?o} FROM <" + context + "> WHERE {?s <http://myopenlink.net/foaf/name> ?o}";
        g = doGraphQuery(con, query);
        Iterator<Statement> it = g.iterator();
        statementFound = true;
        while(it.hasNext()) {
          Statement st = it.next();
          if( !st.getPredicate().stringValue().equals("http://myopenlink.net/mlo/handle")) statementFound = false;
        }
      }
      catch (Exception e) {
        System.out.println("Error[" + e + "]");
        e.printStackTrace();
        ok = false;
      }
      endTest(ok && g.size() > 0); // should return sz > 0 results 
     
      // do describe
      startTest();
      g = new GraphImpl();
      statementFound = false;
      try {
        ok = true;
        log("Sending describe query");
        query = "DESCRIBE ?s FROM <" + context + "> WHERE {?s <http://myopenlink.net/foaf/name> ?o}";
        g = doGraphQuery(con, query);
        Iterator<Statement> it = g.iterator();
        statementFound = it.hasNext();
//        while(it.hasNext()) {
//          Statement st = it.next();
//          if( !st.getPredicate().stringValue().equals("http://myopenlink.net/mlo/handle")) statementFound = false;
//        }
View Full Code Here

TOP

Related Classes of org.openrdf.model.impl.GraphImpl

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.