Example #1
0
  /**
   * LDP-Style to serialize a resource.
   *
   * @param writer the writer to serialize to
   * @param subject the resource to serialize
   * @param iteration the Iteration containing the data
   * @throws RDFHandlerException
   * @throws RepositoryException
   */
  public static void exportIteration(
      RDFWriter writer, URI subject, CloseableIteration<Statement, RepositoryException> iteration)
      throws RDFHandlerException, RepositoryException {
    writer.startRDF();

    writer.handleNamespace(LDP.PREFIX, LDP.NAMESPACE);
    writer.handleNamespace(RDF.PREFIX, RDF.NAMESPACE);
    writer.handleNamespace(XSD.PREFIX, XSD.NAMESPACE);
    writer.handleNamespace(DCTERMS.PREFIX, DCTERMS.NAMESPACE);

    writer.handleNamespace("parent", subject.getNamespace());
    writer.handleNamespace("child", subject.stringValue().replaceFirst("/*$", "/"));
    writer.handleNamespace("this", subject.stringValue().replaceFirst("/*$", "#"));

    while (iteration.hasNext()) {
      writer.handleStatement(iteration.next());
    }

    writer.endRDF();
  }
 public static void writeNanopub(Nanopub nanopub, OutputStream out, RDFFormat format)
     throws RDFHandlerException {
   RDFWriter writer = Rio.createWriter(format, out);
   writer.startRDF();
   String s = nanopub.getUri().toString();
   writer.handleNamespace("this", s);
   writer.handleNamespace("sub", s + ".");
   writer.handleNamespace("blank", s + "..");
   writer.handleNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
   writer.handleNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
   writer.handleNamespace("rdfg", "http://www.w3.org/2004/03/trix/rdfg-1/");
   writer.handleNamespace("xsd", "http://www.w3.org/2001/XMLSchema#");
   writer.handleNamespace("owl", "http://www.w3.org/2002/07/owl#");
   writer.handleNamespace("dc", "http://purl.org/dc/terms/");
   writer.handleNamespace("pav", "http://swan.mindinformatics.org/ontologies/1.2/pav/");
   writer.handleNamespace("np", "http://www.nanopub.org/nschema#");
   for (Statement st : NanopubUtils.getStatements(nanopub)) {
     writer.handleStatement(st);
   }
   writer.endRDF();
 }