Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.RDFWriter


      removeOrphans(ont, OWL.Restriction);

      // output
     
      // set base
      RDFWriter writer = ont.getWriter(ctx.getLang());
      writer.setProperty("xmlbase", ctx.getBaseMap().toString());
 
      if (target!=null) {
        if (ctx.isVerbose()) Gloze.logger.info("writing "+target.getPath());
        write(ont, writer, target, ctx.getLang(), ctx.getBaseMap().toString());
      }
      else if (!ctx.isSilent()) {
        writer.write(ont.getBaseModel(),System.out, ctx.getBaseMap().toString());
        System.out.println();
      }
    }
   
   
View Full Code Here


  public void xml_to_rdf( URL source, File target, URI base, Model model) throws Exception {
    xml_to_rdf(source, base, model);
   
    // set base (see http://jena.sourceforge.net/IO/iohowto.html)
    RDFWriter writer = model.getWriter(lang)
    //writer.setProperty("xmlbase", base.toString());
    writer.setProperty("showXmlDeclaration", "true");

    // output options
    if (target != null) {
      if ("true".equals(verbose)) logger.info("writing "+target.getName());
      //model.write(new FileWriter(target), lang);
      writer.write(model,new FileWriter(target), base.toString());
    }
    else if (!silent)
      //model.write(System.out, lang);
      writer.write(model,System.out, base.toString());

   
    // roundtrip xml
    if (roundtrip!=null && roundtrip.equals("true")) {
      Document doc = drop(model, base);
View Full Code Here

  public void xml_to_rdf(File source, File target, URI base, Model model) throws Exception {
    xml_to_rdf(source, base, model);
   
    // set base (see http://jena.sourceforge.net/IO/iohowto.html)
    RDFWriter writer = model.getWriter(lang)
    //writer.setProperty("xmlbase", base.toString());
    writer.setProperty("showXmlDeclaration", "true");

    // output options
    if (target != null) {
      if ("true".equals(verbose)) logger.info("writing "+target.getName());
      //model.write(new FileWriter(target), lang);
      writer.write(model,new FileWriter(target), base.toString());
    }
    else if (!silent)
      //model.write(System.out, lang);
      writer.write(model,System.out, base.toString());

   
    // roundtrip xml
    if (roundtrip!=null && roundtrip.equals("true")) {
      Document doc = drop(model, base);
View Full Code Here

        assertTrue(ont.isIsomorphicWith(ont1));
      }
      // write it the first time
      else {
        // set base
        RDFWriter writer = ont.getWriter(LANG)
        writer.setProperty("xmlbase", currentBase);
        writer.write(ont.getBaseModel(), new FileWriter(target), currentBase);
      }
      return ont;
    }
    catch (Exception e) {
      fail(e.getMessage());
View Full Code Here

    }
  }

  private class RDFXMLWriter implements ModelWriter {
    public void write(Model model, HttpServletResponse response) throws IOException {
      RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
      writer.setProperty("showXmlDeclaration", "true");
      // From Joseki -- workaround for the j.cook.up bug.
      writer.setProperty("blockRules", "propertyAttr");
      writer.write(model,
          new OutputStreamWriter(response.getOutputStream(), "utf-8"), null);
    }
View Full Code Here

      if ( false ) {
        model.write(out, "RDF/XML-ABBREV", base);
      }
      else {
        // TODO When model is OntModel, the following generates a bunch of stuff
        RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
        writer.setProperty("showXmlDeclaration", "true");
        writer.setProperty("relativeURIs", "same-document,relative");
        writer.setProperty("tab", "4");
        if ( xmlbase != null ) {
          writer.setProperty("xmlbase", xmlbase);
        }

        writer.write(model, out, namespace);
      }
    }
    finally {
      IOUtils.closeQuietly(out);
    }
View Full Code Here

  /**
   * Replacement for JenaUtil.getOntModelAsString(OntModel model).
   */ 
  public static String getOntModelAsString(Model model, String lang) {
    StringWriter sw = new StringWriter();
    RDFWriter writer = model.getWriter(lang);
    String baseUri = null;
    String uriForEmptyPrefix = model.getNsPrefixURI("");
    if ( uriForEmptyPrefix != null ) {
      baseUri = removeTrailingFragment(uriForEmptyPrefix);
      writer.setProperty("xmlbase", baseUri);
    }
    writer.setProperty("showXmlDeclaration", "true");
    writer.setProperty("relativeURIs", "same-document");
    writer.setProperty("tab", "4");
    writer.write(model, sw, baseUri);
    return sw.getBuffer().toString();

  }
View Full Code Here

  /**
   * Gets the serialization of a model in the given language.
   */
  static void serializeModelToOutputStream(Model model, String lang, OutputStream os) {
    String uriForEmptyPrefix = model.getNsPrefixURI("");
    RDFWriter writer = model.getWriter(lang);
   
    String baseUri = null;
    if ( uriForEmptyPrefix != null ) {
      baseUri = JenaUtil2.removeTrailingFragment(uriForEmptyPrefix);
      _setWriterProperty(writer, "xmlbase", baseUri);
    }
    _setWriterProperty(writer, "showXmlDeclaration", "true");
    _setWriterProperty(writer, "relativeURIs", "same-document");
    _setWriterProperty(writer, "tab", "4");
   
    writer.write(model, os, baseUri);
  }
View Full Code Here

  /**
   * Serializes a model
   */ 
  public static String getOntModelAsString(Model model, String lang) {
    StringWriter sw = new StringWriter();
    RDFWriter writer = model.getWriter(lang);
    String baseUri = null;
    String uriForEmptyPrefix = model.getNsPrefixURI("");
    if ( uriForEmptyPrefix != null ) {
      // remove trailing fragment, if any
      baseUri = uriForEmptyPrefix.replaceAll("(/|#)+$", "");
      writer.setProperty("xmlbase", baseUri);
    }
    writer.setProperty("showXmlDeclaration", "true");
    writer.setProperty("relativeURIs", "same-document");
    writer.setProperty("tab", "4");
    writer.write(model, sw, baseUri);
    return sw.getBuffer().toString();

  }
View Full Code Here

    private void testJenaWriterRdfJson()
    {
      Model results = FileManager.get().loadModel(output) ;

        RDFWriter writer = new JenaWriterRdfJson() ;
        ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
        writer.write(results, baos, baseIRI) ;

        InputStream in = new ByteArrayInputStream(baos.toByteArray()) ;
        Model model = ModelFactory.createDefaultModel() ;
        RDFReader reader = new JenaReaderRdfJson() ;
        try {
            if ( baseIRI != null )
            {
                Reader r = PeekReader.makeUTF8(in) ;
                reader.read(model, r, baseIRI) ;
            }
            else
                reader.read(model, in, null)

            boolean b = model.isIsomorphicWith(results) ;
            if ( !b )
            {
              write ( model, results ) ;
                System.out.println("---- Parsed");
                // model.write(System.out, "RDF/JSON") ;
                writer.write(model, System.out, baseIRI) ; // for now, until the plumbing with Jena gets released. See JENA-135
                System.out.println("---- Expected");
                // results.write(System.out, "RDF/JSON") ;
                writer.write(results, System.out, baseIRI) ;
                System.out.println("--------");
            }
           
            assertTrue("Models not isomorphic", b) ;
        } catch (RiotParseException ex)
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.RDFWriter

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.