Package org.openrdf.model

Examples of org.openrdf.model.Graph


    aBob.getKnows().add(aJoe);
    aBob.getKnows().add(aJane);

    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


            Collection<Class<?>> klasses = new ArrayList<Class<?>>(  );
            klasses.add( MyInterfaceImpl.class );
            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

  }

  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

      Filter<WarcRecord> filter = Filters.adaptFilterBURL2WarcRecord (new TrueFilter());
      WarcFilteredIterator it = new WarcFilteredIterator(in, record, filter);

      WarcHttpResponse response = new WarcHttpResponse();

      Graph mdGraph = new org.openrdf.model.impl.GraphImpl();
      String mdGraphURI = "http://challenge.semanticweb.org/2008/metadata";
      ValueFactory vf = mdGraph.getValueFactory();
      String dcNS = "http://purl.org/dc/elements/1.1/";
      DatatypeFactory dtf = null;

      try {
    dtf = DatatypeFactory.newInstance();
      } catch (DatatypeConfigurationException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
      }

      GregorianCalendar c = new GregorianCalendar ();

      try {
    int cnt = 0;

    //      while (cnt < 10 && it.hasNext()) {
    while (it.hasNext()) {

        WarcRecord nextRecord = it.next();

        //Get the HttpResponse
        try {
      response.fromWarcRecord (nextRecord);

      if (debugMode) {
          System.out.println("RECORD     : " + String.format("%05d", cnt));
          System.out.println(" subjectUri: " + nextRecord.header.subjectUri);
          System.out.println("contentType: " + nextRecord.header.contentType);
          System.out.println(" dataLength: " + nextRecord.header.dataLength);
          System.out.println("actual data: " + nextRecord.block.length());
          System.out.println("    missing: " +
            (nextRecord.header.dataLength - nextRecord.block.length()) + "b");
      }
      l.output(nextRecord.header.subjectUri.toString());

      URI s, p, o;
      Literal lit;
      if (cnt == max ){ return ; }
      if (cnt >= min && cnt < max) {

          s = vf.createURI(nextRecord.header.subjectUri.toString());
          p = vf.createURI(dcNS, "source");
          lit = vf.createLiteral(inFile);

          mdGraph.add(s,p,lit);

          c.setTime(nextRecord.header.creationDate);
          XMLGregorianCalendar xc = dtf.newXMLGregorianCalendar(c);

          p = vf.createURI(dcNS, "date");
          lit = vf.createLiteral(xc);

          mdGraph.add(s,p,lit);

          curFile = w.write(response.contentAsStream(), cnt, start);

          try {
        ldAddStmt.setString(1, curFile);
        ldAddStmt.setString(2, nextRecord.header.subjectUri.toString());
        ResultSet res = ldAddStmt.executeQuery();
          }
          catch (SQLException e) {
        l.error(e);
        l.error("WX0003: Insert to loader table failed. Exiting.");
        System.exit(-1);
          }
      }
        }
        catch (IOException e) {
      e.printStackTrace();
      continue;
        }
        cnt++;
    }
    }


      catch (RuntimeException re) {
    l.error ("WX0004 Unexpected Runtime Error Thrown.");
    l.error (re.toString());
    re.printStackTrace();
    System.exit (-1);
      }
      l.output ("Finish loop ");

      Iterator<Statement> iter = mdGraph.iterator();
      Integer _stmtcnt = 0;
      String mdFile = String.format("%s.md.nt", inFile);

      FileOutputStream outStream = new FileOutputStream(mdFile);
      NTriplesWriter ntw = new NTriplesWriter (outStream);
View Full Code Here

    public void addGraph(QueryLanguage language, String query, boolean joinBlankNodes) throws IOException, AccessDeniedException
    {
  try
  {
      Graph graph = performGraphQuery(language, query);
      addGraph(graph, joinBlankNodes);
  }
  catch (QueryEvaluationException e)
  {
      throw new IOException(e.getMessage());
View Full Code Here

    public void removeGraph(QueryLanguage language, String query) throws IOException, AccessDeniedException
    {
  try
  {
      Graph graph = performGraphQuery(language, query);
      removeGraph(graph);
  }
  catch (QueryEvaluationException e)
  {
      throw new IOException(e.getMessage());
View Full Code Here

        // "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone Device\"}}";
        final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
        final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
        final Object input = JSONUtils.fromString(inputstring);

        final Graph graph = new LinkedHashModel();
        final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
        final ParserConfig parserConfig = new ParserConfig();
        final SesameTripleCallback callback = new SesameTripleCallback(
                new StatementCollector(graph), ValueFactoryImpl.getInstance(), parserConfig,
                parseErrorListener);

        JsonLdProcessor.toRDF(input, callback);

        final Iterator<Statement> statements = graph.iterator();

        // contains only one statement (type)
        while (statements.hasNext()) {
            final Statement stmt = statements.next();
View Full Code Here

TOP

Related Classes of org.openrdf.model.Graph

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.