Class KGCLWriter

java.lang.Object
org.incenp.obofoundry.kgcl.KGCLWriter

public class KGCLWriter extends Object
A writer to serialise KGCL change objects into a KGCL program that is written to a file or file-like sink.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KGCLWriter(File kgclFile)
    Creates a new instance to write to a file.
    Creates a new instance to write to a stream.
    KGCLWriter(Writer kgclOutput)
    Creates a new instance to write to a character stream writer.
    KGCLWriter(String kgclFilename)
    Creates a new instance to write to a file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the underlying writer.
    void
    setPrefixManager(org.semanticweb.owlapi.model.OWLOntology ontology)
    Deprecated.
    Using an ontology as the prefix manager is no longer recommended.
    void
    setPrefixManager(org.semanticweb.owlapi.model.PrefixManager manager)
    Sets the prefix manager to use to compact identifiers.
    void
    Sets the prefix map to use to compact identifiers.
    void
    write(String comment)
    Writes a comment line to the underlying sink.
    void
    write(List<Change> changes)
    Serialises and writes a KGCL changeset to the underlying sink.
    void
    write(Change change)
    Serialise and writes a single KGCL change to the underlying sink.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KGCLWriter

      public KGCLWriter(OutputStream kgclOutput)
      Creates a new instance to write to a stream.
      Parameters:
      kgclOutput - The stream to write to.
    • KGCLWriter

      public KGCLWriter(Writer kgclOutput)
      Creates a new instance to write to a character stream writer.
      Parameters:
      kgclOutput - The character stream to write to.
    • KGCLWriter

      public KGCLWriter(File kgclFile) throws IOException
      Creates a new instance to write to a file.
      Parameters:
      kgclFile - The file to write to.
      Throws:
      IOException - If the file cannot be found or written to.
    • KGCLWriter

      public KGCLWriter(String kgclFilename) throws IOException
      Creates a new instance to write to a file.
      Parameters:
      kgclFilename - The name of the file to write to.
      Throws:
      IOException - If the file cannot be found or written to.
  • Method Details

    • setPrefixManager

      public void setPrefixManager(org.semanticweb.owlapi.model.PrefixManager manager)
      Sets the prefix manager to use to compact identifiers. The prefix manager in this class will perform the opposite task to the prefix manager in KGCLReader.setPrefixManager(PrefixManager). Given a full-length identifier, it will convert it into a short-form (“CURIEfied”) identifier.

      The prefix manager should be set prior to any call to the write(java.util.List<org.incenp.obofoundry.kgcl.model.Change>) methods.

      If no prefix manager is set, no default compaction is performed and all identifiers will be written as they are.

      Parameters:
      manager - The OWL API prefix manager to use (may be null).
    • setPrefixManager

      @Deprecated public void setPrefixManager(org.semanticweb.owlapi.model.OWLOntology ontology)
      Deprecated.
      Using an ontology as the prefix manager is no longer recommended. Provide the reader with an explicit PrefixManager (with setPrefixManager(PrefixManager)) instead.
      Sets the prefix manager from the specified ontology. This is a convenience method that automatically gets the prefix manager from a OWL API OWLOntology object and sets it as the prefix manager for the writer.
      Parameters:
      ontology - The ontology whose prefix manager shall be used. If the ontology has been read from a OWLDocumentFormat that does not support prefixes, it is ignored and a default prefix manager is used instead.
    • setPrefixMap

      public void setPrefixMap(Map<String,String> map)
      Sets the prefix map to use to compact identifiers.

      This is equivalent to calling setPrefixManager(PrefixManager) with a PrefixManager object initialised with the provided map.

      Parameters:
      map - The map of prefix names to prefixes to use to compact identifiers.
    • write

      public void write(List<Change> changes) throws IOException
      Serialises and writes a KGCL changeset to the underlying sink.
      Parameters:
      changes - The list of KGCL changes to serialise.
      Throws:
      IOException - If any I/O error occurs when writing.
    • write

      public void write(Change change) throws IOException
      Serialise and writes a single KGCL change to the underlying sink.
      Parameters:
      change - The KGCL change to serialise.
      Throws:
      IOException - If any I/O error occurs when writing.
    • write

      public void write(String comment) throws IOException
      Writes a comment line to the underlying sink. This method writes its argument preceded by a hash character (#), so that it would be ignored if the file is later read by a KGCLReader object.

      Note that the KGCL specification says nothing about comments in a KGCL file. A file containing such comments may not be successfully parsed by other KGCL implementations.

      Parameters:
      comment - The comment to write.
      Throws:
      IOException - If any I/O error occurs when writing.
    • close

      public void close() throws IOException
      Closes the underlying writer.
      Throws:
      IOException - If any I/O error occurs.