Package org.incenp.obofoundry.kgcl
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.KGCLWriter(OutputStream kgclOutput)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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Closes the underlying writer.voidsetPrefixManager(org.semanticweb.owlapi.model.OWLOntology ontology)Deprecated.Using an ontology as the prefix manager is no longer recommended.voidsetPrefixManager(org.semanticweb.owlapi.model.PrefixManager manager)Sets the prefix manager to use to compact identifiers.voidsetPrefixMap(Map<String,String> map)Sets the prefix map to use to compact identifiers.voidwrite(String comment)Writes a comment line to the underlying sink.voidwrite(List<org.incenp.obofoundry.kgcl.model.Change> changes)Serialises and writes a KGCL changeset to the underlying sink.voidwrite(org.incenp.obofoundry.kgcl.model.Change change)Serialise and writes a single KGCL change to the underlying sink.
-
-
-
Constructor Detail
-
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 Detail
-
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 inKGCLReader.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 benull).
-
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 (withsetPrefixManager(PrefixManager)) instead.Sets the prefix manager from the specified ontology. This is a convenience method that automatically gets the prefix manager from a OWL APIOWLOntologyobject 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 aOWLDocumentFormatthat 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<org.incenp.obofoundry.kgcl.model.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(org.incenp.obofoundry.kgcl.model.Change change) throws IOExceptionSerialise 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 aKGCLReaderobject.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 IOExceptionCloses the underlying writer.- Throws:
IOException- If any I/O error occurs.
-
-