Package org.ontoware.rdf2go.model

Examples of org.ontoware.rdf2go.model.Model


   * @return the rdf/xml representation of all the posts on the current resource
   */
  @SuppressWarnings("unchecked")
  public String exportPosts2RDF()
  {
    Model tempModel = null;
    try
    {
      tempModel = DbFace.getTempModel();
     
      StringWriter stringWriter = new StringWriter();
     
      List<Person> authors = getPostsAuthors();
   
      ClosableIterator<Statement> reif = model.queryConstruct(RdfQuery.RDFQ_GIVEN_RESOURCE_POST_GRAPH.toString(
            SIOC.postedResource, SIOC.Post, SIOC.postedWhen, SIOC.postedBy, SIOC.postBody, SIOC.title, SIOC.hasReply,SIOC.topic, uri),
            "SPARQL").iterator();
      while (reif.hasNext()){
        tempModel.addStatement(reif.next());
      }
      reif.close();
     
      ClosableIterator<Statement> statements = tempModel.findStatements(Variable.ANY, new URIImpl(SIOC.postedBy), Variable.ANY);
     
      Collection addedAuthors = new ArrayList();
      /* Exported XML must apply to the  SIOC convent, so foreach post the created_by should no longer be set to
       * the author's mbox, but must point to the Sioc:User node (it must be added).
       * Foaf:Person pointing to the Sioc:User must be added as well.
       * In other words: the statement from the graph must be removed, and two new must be added. 
       */
      while(statements.hasNext()) {
        Statement stmt = statements.next();
        tempModel.removeStatement(stmt);

        /* given up, as a user doesn't have an account, Sioc:User does not intrduce any new information
        //Sioc:User node
        BNode bNode =  graph.getValueFactory().createBNode();
        graph.add(new StatementImpl(stmt.getSubject(), stmt.getPredicate(), bNode));
        graph.add(new StatementImpl(bNode, valueFactory.createURI(XFOAF_SSCF.accountOf), valueFactory.createLiteral(stmt.getObject().toString())));
        graph.add(new StatementImpl(bNode, valueFactory.createURI(RDF.TYPE), valueFactory.createURI(XFOAF_SSCF.User)));
       
        //dodanie Foaf:Person holdsAccount
        graph.add(new StatementImpl((Resource)stmt.getObject(), valueFactory.createURI(FOAF.maker), bNode));
        */
         
        tempModel.addStatement(stmt.getSubject(),model.createURI(FOAF.maker.toString()),stmt.getObject());
        tempModel.addStatement(stmt.getObject().asURI(), RDF.type, model.createURI(FOAF.Person.toString()));
       
        Person tmpPerson = null;
        for (Person p : authors) {
          if (!addedAuthors.contains(p) && stmt.getObject().toString().equals(p.getMbox().toString())) {
            tmpPerson = p;
            break;
          }
        }
       
        //System.out.println(s.getObject().toString());
        if (tmpPerson != null) {
          tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.mbox.toString()),tmpPerson.getMbox().toString());
         
          if (tmpPerson.getName() != null && !"".equals(tmpPerson.getName()) && !"nullnull".equals(tmpPerson.getName())) {
            tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.name.toString()),tmpPerson.getName());
          }
          if (tmpPerson.getGivenname() != null && !"".equals(tmpPerson.getGivenname())) {
            tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.givenname.toString()),tmpPerson.getGivenname());
          }
          if (tmpPerson.getFamily_name() != null && !"".equals(tmpPerson.getFamily_name())) {
            tempModel.addStatement(stmt.getObject().asURI(),model.createURI(FOAF.family_name.toString()),tmpPerson.getFamily_name());
          }
          addedAuthors.add(tmpPerson);
        }
      }
     
      tempModel.writeTo(stringWriter);
      tempModel = null;
     
      statements.close();
     
      return stringWriter.toString();
View Full Code Here


       
        List<Statement> stToRemove = new ArrayList<Statement>();
   
    try
    {
      Model tempModel = DbFace.getTempModel();
     
      URI issuedBy = tempModel.createURI(S3B_SSCF.issuedBy);
      URI importedFrom =tempModel.createURI(S3B_SSCF.importedFrom);
      URI tagger = tempModel.createURI(S3B_SSCF.Tagger);
      URI rdf_type =  RDF.type;
      URI isIn =  tempModel.createURI(S3B_SSCF.isIn);
     
      //1. get taggers and where they are placed 
      Iterator<Statement> it = DbFace.getModel().findStatements(null,null,rdf_type ,tagger);
     
      while(it.hasNext())
      {
        Statement st = it.next();
        Resource taggerUri = st.getSubject();
        Node creator = null;
       
        //2. get sscf person for this tagger.
        Iterator<Statement> uriIt = DbFace.getModel().findStatements(null,taggerUri,isIn ,Variable.ANY);
        while(uriIt.hasNext())
        {
          creator = uriIt.next().getObject();
          if(creator!=null)
            break;
        }
       
        if(taggerUri!=null&&creator!=null)
        {
          //3. We are ready to do some changes...
          sb.append("Changing for: ");
          sb.append(taggerUri.toString()).append(" - ").append(creator.toString()).append("<BR>");
          Iterator<Statement> toChange = DbFace.getModel().findStatements(null,null, issuedBy, taggerUri);
         
          while(toChange.hasNext())
          {
            Statement stTmp = toChange.next();         

            tempModel.addStatement(stTmp.getSubject(), importedFrom, stTmp.getObject());
            tempModel.addStatement(stTmp.getSubject(), issuedBy, creator);
            stToRemove.add(stTmp);
           
            statementsChanged++;
          }
        }
View Full Code Here

            }
        };

        final RDF2GoRDFParser parser = new RDF2GoRDFParser();

        final Model modelResult = RDF2Go.getModelFactory().createModel().open();
        modelResult.readFrom(new ByteArrayInputStream(turtle.getBytes()), Syntax.Turtle);
        final Object json = JsonLdProcessor.fromRDF(modelResult, parser);

        assertTrue(Obj.equals(json, expected));
    }
View Full Code Here

            }
        };

        final RDF2GoRDFParser parser = new RDF2GoRDFParser();

        final Model modelResult = RDF2Go.getModelFactory().createModel().open();
        modelResult.readFrom(new ByteArrayInputStream(turtle.getBytes()), Syntax.Turtle);
        final Object json = JsonLdProcessor.fromRDF(modelResult, parser);

        assertTrue(Obj.equals(json, expected));
    }
View Full Code Here

TOP

Related Classes of org.ontoware.rdf2go.model.Model

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.