Package org.obolibrary.robot
Class IOHelper
- java.lang.Object
-
- org.obolibrary.robot.IOHelper
-
public class IOHelper extends Object
Provides convenience methods for working with ontology and term files.- Author:
- James A. Overton
-
-
Constructor Summary
Constructors Constructor Description IOHelper()
Create a new IOHelper with the default prefixes.IOHelper(boolean defaults)
Create a new IOHelper with or without the default prefixes.IOHelper(File file)
Create a new IOHelper with prefixes from a file.IOHelper(String path)
Create a new IOHelper with prefixes from a file path.IOHelper(Map<String,Object> map)
Create a new IOHelper with the specified prefixes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addBaseNamespace(String baseNamespace)
Add a base namespace to the IOHelper.void
addBaseNamespaces(String baseNamespacePath)
Add a set of base namespaces to the IOHelper from file.void
addPrefix(String combined)
Add a prefix mapping as a single string "foo: http://example.com#".void
addPrefix(String prefix, String target)
Add a prefix mapping to the current JSON-LD context, as a prefix string and target string.void
addPrefixes(com.github.jsonldjava.core.Context context1)
Given a Context, add the prefix mappings to the current JSON-LD context.void
addPrefixes(String prefixPath)
Given a path to a JSON-LD prefix file, add the prefix mappings in the file to the current JSON-LD context.void
addPrefixesAndSave(org.semanticweb.owlapi.model.OWLOntology ontology, File outputFile, List<String> addPrefixes)
Deprecated.static String
cellToA1(int rowNum, int colNum)
Convert a row index and column index for a cell to A1 notation.protected static boolean
cleanTDB(String tdbDir)
Given a directory containing TDB mappings, remove the files and directory.org.semanticweb.owlapi.model.IRI
createIRI(String term)
Given a term string, use the current prefixes to create an IRI.org.semanticweb.owlapi.model.IRI
createIRI(String term, boolean qName)
Deprecated.replaced bycreateIRI(String)
Set<org.semanticweb.owlapi.model.IRI>
createIRIs(Set<String> terms)
Given a set of term identifier strings, return a set of IRIs.static org.semanticweb.owlapi.model.OWLLiteral
createLiteral(String value)
Create an OWLLiteral.static org.semanticweb.owlapi.model.OWLLiteral
createTaggedLiteral(String value, String lang)
Create an OWLLiteral with a language tag.org.semanticweb.owlapi.model.OWLLiteral
createTypedLiteral(String value, String type)
Create a typed OWLLiteral.org.semanticweb.owlapi.model.OWLLiteral
createTypedLiteral(String value, org.semanticweb.owlapi.model.IRI type)
Create a typed OWLLiteral.Set<String>
extractTerms(String input)
Extract a set of term identifiers from an input string by removing comments, trimming lines, and removing empty lines.Set<String>
getBaseNamespaces()
Get the base namespaces.com.github.jsonldjava.core.Context
getContext()
Get a copy of the current context.String
getContextString()
Return the current prefixes as a JSON-LD string.com.github.jsonldjava.core.Context
getDefaultContext()
Get a copy of the default context.static org.semanticweb.owlapi.model.OWLDocumentFormat
getFormat(String formatName)
Given the name of a file format, return an instance of it.Map<String,String>
getPrefixes()
Get a copy of the current prefix map.org.semanticweb.owlapi.util.DefaultPrefixManager
getPrefixManager()
Get a prefix manager with the current prefixes.Boolean
getXMLEntityFlag()
Get the useXMLEntities flag.File
guessCatalogFile(File ontologyFile)
Try to guess the location of the catalog.xml file.static boolean
isValidCURIE(CharSequence s)
Determine if a string is a CURIE.org.semanticweb.owlapi.model.OWLOntology
loadOntology(File ontologyFile)
Load an ontology from a File, using a catalog file if available.org.semanticweb.owlapi.model.OWLOntology
loadOntology(File ontologyFile, boolean useCatalog)
Load an ontology from a File, with option to use a catalog file.org.semanticweb.owlapi.model.OWLOntology
loadOntology(File ontologyFile, File catalogFile)
Load an ontology from a File, with optional catalog File.org.semanticweb.owlapi.model.OWLOntology
loadOntology(InputStream ontologyStream)
Load an ontology from an InputStream, without a catalog file.org.semanticweb.owlapi.model.OWLOntology
loadOntology(InputStream ontologyStream, String catalogPath)
Load an ontology from an InputStream with a catalog file.org.semanticweb.owlapi.model.OWLOntology
loadOntology(String ontologyPath)
Load an ontology from a String path, using a catalog file if available.org.semanticweb.owlapi.model.OWLOntology
loadOntology(String ontologyPath, boolean useCatalog)
Load an ontology from a String path, with option to use catalog file.org.semanticweb.owlapi.model.OWLOntology
loadOntology(String ontologyPath, String catalogPath)
Load an ontology from a String path, with optional catalog file.org.semanticweb.owlapi.model.OWLOntology
loadOntology(org.semanticweb.owlapi.model.IRI ontologyIRI)
Given an ontology IRI, load the ontology from the IRI.org.semanticweb.owlapi.model.OWLOntology
loadOntology(org.semanticweb.owlapi.model.IRI ontologyIRI, String catalogPath)
Given an IRI and a path to a catalog file, load the ontology from the IRI with the catalog.org.semanticweb.owlapi.model.OWLOntology
loadOntology(org.semanticweb.owlapi.model.OWLOntologyManager manager, org.semanticweb.owlapi.io.OWLOntologyDocumentSource source)
Given an ontology manager and a document source, load the ontology from the source using the manager.static org.apache.jena.query.Dataset
loadToTDBDataset(String inputPath, String tdbDir)
Given a path to an RDF/XML or TTL file and a RDF language, load the file as the default model of a TDB dataset backed by a directory to improve processing time.static org.semanticweb.owlapi.util.DefaultPrefixManager
makePrefixManager(Map<String,String> prefixes)
Make an OWLAPI DefaultPrefixManager from a map of prefixes.static org.apache.jena.query.Dataset
openTDBDataset(String tdbDir)
Given a path to a TDB directory, load the TDB as a Dataset.static com.github.jsonldjava.core.Context
parseContext(String jsonString)
Load a map of prefixes from the "@context" of a JSON-LD string.Set<org.semanticweb.owlapi.model.IRI>
parseTerms(String input)
Parse a set of IRIs from a space-separated string, ignoring '#' comments.static List<List<String>>
readCSV(InputStream stream)
Read comma-separated values from a stream to a list of lists of strings.static List<List<String>>
readCSV(Reader reader)
Read comma-separated values from a reader to a list of lists of strings.static List<List<String>>
readCSV(String path)
Read comma-separated values from a path to a list of lists of strings.static List<List<String>>
readTable(String path)
Read a table from a path to a list of lists of strings.static List<List<String>>
readTSV(InputStream stream)
Read tab-separated values from a stream to a list of lists of strings.static List<List<String>>
readTSV(Reader reader)
Read tab-separated values from a reader to a list of lists of strings.static List<List<String>>
readTSV(String path)
Read tab-separated values from a path to a list of lists of strings.void
saveContext(File file)
Write the current context as a JSON-LD file.void
saveContext(String path)
Write the current context as a JSON-LD file.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, File ontologyFile)
Save an ontology to a File.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, String ontologyPath)
Save an ontology to a String path.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI ontologyIRI)
Save an ontology to an IRI, using the file extension to determine the format.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, File ontologyFile)
Save an ontology in the given format to a file.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, File ontologyFile, boolean checkOBO)
Save an ontology in the given format to a file, with the option to ignore OBO document checks.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, String ontologyPath, boolean checkOBO)
Save an ontology in the given format to a path, with the option to ignore OBO document checks.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, org.semanticweb.owlapi.model.IRI ontologyIRI)
Save an ontology in the given format to an IRI.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, org.semanticweb.owlapi.model.IRI ontologyIRI, boolean checkOBO)
Save an ontology in the given format to an IRI, with the option to ignore OBO document checks.org.semanticweb.owlapi.model.OWLOntology
saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, org.semanticweb.owlapi.model.IRI ontologyIRI, Map<String,String> addPrefixes, boolean checkOBO)
Save an ontology in the given format to an IRI, with option to add prefixes and option to ignore OBO document checks.void
setContext()
Set an empty context.void
setContext(com.github.jsonldjava.core.Context context)
Set the current JSON-LD context to the given context.void
setContext(String jsonString)
Set the current JSON-LD context to the given context.void
setContext(Map<String,Object> map)
Set the current JSON-LD context to the given map.void
setPrefixes(Map<String,Object> map)
Set the current prefix map.void
setStrict(Boolean strict)
Set "strict" value.void
setXMLEntityFlag(Boolean entityFlag)
Set whether or not XML entities will be swapped into URIs in saveOntology XML output formats.static void
writeTable(List<String[]> table, File file, char separator)
Write a table from a list of arrays.static void
writeTable(List<String[]> table, Writer writer, char separator)
Write a table from a list of arrays.static void
writeTable(List<String[]> table, String path)
Write a table from a list of arrays.
-
-
-
Constructor Detail
-
IOHelper
public IOHelper() throws IOException
Create a new IOHelper with the default prefixes.- Throws:
IOException
- on problem getting default context
-
IOHelper
public IOHelper(boolean defaults) throws IOException
Create a new IOHelper with or without the default prefixes.- Parameters:
defaults
- false if defaults should not be used- Throws:
IOException
- on problem getting default context
-
IOHelper
public IOHelper(Map<String,Object> map) throws IOException
Create a new IOHelper with the specified prefixes.- Parameters:
map
- the prefixes to use- Throws:
IOException
- on issue parsing map
-
IOHelper
public IOHelper(String path) throws IOException
Create a new IOHelper with prefixes from a file path.- Parameters:
path
- to a JSON-LD file with a @context- Throws:
IOException
- on issue parsing JSON-LD file as context
-
IOHelper
public IOHelper(File file) throws IOException
Create a new IOHelper with prefixes from a file.- Parameters:
file
- a JSON-LD file with a @context- Throws:
IOException
- on issue reading file or setting context from file
-
-
Method Detail
-
setStrict
public void setStrict(Boolean strict)
Set "strict" value. If true, any loadOntology method will fail on unparsed triples or OWLAPI "strict" parsing issues.- Parameters:
strict
- boolean value
-
addPrefixesAndSave
@Deprecated public void addPrefixesAndSave(org.semanticweb.owlapi.model.OWLOntology ontology, File outputFile, List<String> addPrefixes) throws IOException
Deprecated.Given an ontology, a file, and a list of prefixes, save the ontology to the file and include the prefixes in the header.- Parameters:
ontology
- OWLOntology to saveoutputFile
- File to save ontology toaddPrefixes
- List of prefixes to add ("foo: http://foo.bar/")- Throws:
IOException
- On issue parsing list of prefixes or saving file
-
cleanTDB
protected static boolean cleanTDB(String tdbDir)
Given a directory containing TDB mappings, remove the files and directory. If successful, return true.- Parameters:
tdbDir
- directory to remove- Returns:
- boolean indicating success
-
guessCatalogFile
public File guessCatalogFile(File ontologyFile)
Try to guess the location of the catalog.xml file. Looks in the directory of the given ontology file for a catalog file.- Parameters:
ontologyFile
- the- Returns:
- the guessed catalog File; may not exist!
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(String ontologyPath) throws IOException
Load an ontology from a String path, using a catalog file if available.- Parameters:
ontologyPath
- the path to the ontology file- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(String ontologyPath, boolean useCatalog) throws IOException
Load an ontology from a String path, with option to use catalog file.- Parameters:
ontologyPath
- the path to the ontology fileuseCatalog
- when true, a catalog file will be used if one is found- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(String ontologyPath, String catalogPath) throws IOException
Load an ontology from a String path, with optional catalog file.- Parameters:
ontologyPath
- the path to the ontology filecatalogPath
- the path to the catalog file- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(File ontologyFile) throws IOException
Load an ontology from a File, using a catalog file if available.- Parameters:
ontologyFile
- the ontology file to load- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(File ontologyFile, boolean useCatalog) throws IOException
Load an ontology from a File, with option to use a catalog file.- Parameters:
ontologyFile
- the ontology file to loaduseCatalog
- when true, a catalog file will be used if one is found- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(File ontologyFile, File catalogFile) throws IOException
Load an ontology from a File, with optional catalog File.- Parameters:
ontologyFile
- the ontology file to loadcatalogFile
- the catalog file to use- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(InputStream ontologyStream) throws IOException
Load an ontology from an InputStream, without a catalog file.- Parameters:
ontologyStream
- the ontology stream to load- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(InputStream ontologyStream, String catalogPath) throws IOException
Load an ontology from an InputStream with a catalog file.- Parameters:
ontologyStream
- the ontology stream to loadcatalogPath
- the catalog file to use or null- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(org.semanticweb.owlapi.model.IRI ontologyIRI) throws IOException
Given an ontology IRI, load the ontology from the IRI.- Parameters:
ontologyIRI
- the ontology IRI to load- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(org.semanticweb.owlapi.model.IRI ontologyIRI, String catalogPath) throws IOException
Given an IRI and a path to a catalog file, load the ontology from the IRI with the catalog.- Parameters:
ontologyIRI
- the ontology IRI to loadcatalogPath
- the catalog file to use or null- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on any problem
-
loadOntology
public org.semanticweb.owlapi.model.OWLOntology loadOntology(org.semanticweb.owlapi.model.OWLOntologyManager manager, org.semanticweb.owlapi.io.OWLOntologyDocumentSource source) throws IOException, org.semanticweb.owlapi.model.OWLOntologyCreationException
Given an ontology manager and a document source, load the ontology from the source using the manager. Log unparsed triples, or throw exception if strict=true.- Parameters:
manager
- OWLOntologyManager with IRI mappers to usesource
- OWLOntologyDocumentSource to load from- Returns:
- a new ontology object, with a new OWLManager
- Throws:
IOException
- on problem with unparsed triples if strict=trueorg.semanticweb.owlapi.model.OWLOntologyCreationException
- on problem loading ontology document
-
loadToTDBDataset
public static org.apache.jena.query.Dataset loadToTDBDataset(String inputPath, String tdbDir) throws org.apache.jena.shared.JenaException
Given a path to an RDF/XML or TTL file and a RDF language, load the file as the default model of a TDB dataset backed by a directory to improve processing time. Return the new dataset.WARNING - this creates a directory at given tdbDir location!
- Parameters:
inputPath
- input path of RDF/XML or TTL filetdbDir
- location to put TDB mappings- Returns:
- Dataset instantiated with triples
- Throws:
org.apache.jena.shared.JenaException
- if TDB directory can't be written to
-
openTDBDataset
public static org.apache.jena.query.Dataset openTDBDataset(String tdbDir)
Given a path to a TDB directory, load the TDB as a Dataset.- Parameters:
tdbDir
- path to existing TDB directory- Returns:
- Dataset or null
-
getFormat
public static org.semanticweb.owlapi.model.OWLDocumentFormat getFormat(String formatName) throws IllegalArgumentException
Given the name of a file format, return an instance of it.Suported formats:
- OBO as 'obo'
- RDFXML as 'owl'
- Turtle as 'ttl'
- OWLXML as 'owx'
- Manchester as 'omn'
- OWL Functional as 'ofn'
- Parameters:
formatName
- the name of the format- Returns:
- an instance of the format
- Throws:
IllegalArgumentException
- if format name is not recognized
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, String ontologyPath) throws IOException
Save an ontology to a String path.- Parameters:
ontology
- the ontology to saveontologyPath
- the path to save the ontology to- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, File ontologyFile) throws IOException
Save an ontology to a File.- Parameters:
ontology
- the ontology to saveontologyFile
- the file to save the ontology to- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI ontologyIRI) throws IOException
Save an ontology to an IRI, using the file extension to determine the format.- Parameters:
ontology
- the ontology to saveontologyIRI
- the IRI to save the ontology to- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, File ontologyFile) throws IOException
Save an ontology in the given format to a file.- Parameters:
ontology
- the ontology to saveformat
- the ontology format to useontologyFile
- the file to save the ontology to- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, File ontologyFile, boolean checkOBO) throws IOException
Save an ontology in the given format to a file, with the option to ignore OBO document checks.- Parameters:
ontology
- the ontology to saveformat
- the ontology format to useontologyFile
- the file to save the ontology tocheckOBO
- if false, ignore OBO document checks- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, org.semanticweb.owlapi.model.IRI ontologyIRI) throws IOException
Save an ontology in the given format to an IRI.- Parameters:
ontology
- the ontology to saveformat
- the ontology format to useontologyIRI
- the IRI to save the ontology to- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, String ontologyPath, boolean checkOBO) throws IOException
Save an ontology in the given format to a path, with the option to ignore OBO document checks.- Parameters:
ontology
- the ontology to saveformat
- the ontology format to useontologyPath
- the path to save the ontology tocheckOBO
- if false, ignore OBO document checks- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, org.semanticweb.owlapi.model.IRI ontologyIRI, boolean checkOBO) throws IOException
Save an ontology in the given format to an IRI, with the option to ignore OBO document checks.- Parameters:
ontology
- the ontology to saveformat
- the ontology format to useontologyIRI
- the IRI to save the ontology tocheckOBO
- if false, ignore OBO document checks- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
saveOntology
public org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, org.semanticweb.owlapi.model.IRI ontologyIRI, Map<String,String> addPrefixes, boolean checkOBO) throws IOException
Save an ontology in the given format to an IRI, with option to add prefixes and option to ignore OBO document checks.- Parameters:
ontology
- the ontology to saveformat
- the ontology format to useontologyIRI
- the IRI to save the ontology toaddPrefixes
- map of prefixes to add to headercheckOBO
- if false, ignore OBO document checks- Returns:
- the saved ontology
- Throws:
IOException
- on any problem
-
extractTerms
public Set<String> extractTerms(String input)
Extract a set of term identifiers from an input string by removing comments, trimming lines, and removing empty lines. A comment is a space or newline followed by a '#', to the end of the line. This excludes '#' characters in IRIs.- Parameters:
input
- the String containing the term identifiers- Returns:
- a set of term identifier strings
-
cellToA1
public static String cellToA1(int rowNum, int colNum)
Convert a row index and column index for a cell to A1 notation.- Parameters:
rowNum
- row indexcolNum
- column index- Returns:
- A1 notation for cell location
-
createIRI
public org.semanticweb.owlapi.model.IRI createIRI(String term)
Given a term string, use the current prefixes to create an IRI.- Parameters:
term
- the term to convert to an IRI- Returns:
- the new IRI or null
-
createIRI
@Deprecated public org.semanticweb.owlapi.model.IRI createIRI(String term, boolean qName)
Deprecated.replaced bycreateIRI(String)
Given a term string, use the current prefixes to create an IRI.- Parameters:
term
- the term to convert to an IRIqName
- if true, validate that the IRI expands to a QName- Returns:
- the new IRI or null
-
createIRIs
public Set<org.semanticweb.owlapi.model.IRI> createIRIs(Set<String> terms) throws IllegalArgumentException
Given a set of term identifier strings, return a set of IRIs.- Parameters:
terms
- the set of term identifier strings- Returns:
- the set of IRIs
- Throws:
IllegalArgumentException
- if term identifier is not a valid IRI
-
createLiteral
public static org.semanticweb.owlapi.model.OWLLiteral createLiteral(String value)
Create an OWLLiteral.- Parameters:
value
- the lexical value- Returns:
- a literal
-
createTaggedLiteral
public static org.semanticweb.owlapi.model.OWLLiteral createTaggedLiteral(String value, String lang)
Create an OWLLiteral with a language tag.- Parameters:
value
- the lexical valuelang
- the language tag- Returns:
- a literal
-
createTypedLiteral
public org.semanticweb.owlapi.model.OWLLiteral createTypedLiteral(String value, String type)
Create a typed OWLLiteral.- Parameters:
value
- the lexical valuetype
- the type IRI string- Returns:
- a literal
-
createTypedLiteral
public org.semanticweb.owlapi.model.OWLLiteral createTypedLiteral(String value, org.semanticweb.owlapi.model.IRI type)
Create a typed OWLLiteral.- Parameters:
value
- the lexical valuetype
- the type IRI- Returns:
- a literal
-
parseTerms
public Set<org.semanticweb.owlapi.model.IRI> parseTerms(String input) throws IllegalArgumentException
Parse a set of IRIs from a space-separated string, ignoring '#' comments.- Parameters:
input
- the string containing the IRI strings- Returns:
- the set of IRIs
- Throws:
IllegalArgumentException
- if term identifier is not a valid IRI
-
parseContext
public static com.github.jsonldjava.core.Context parseContext(String jsonString) throws IOException
Load a map of prefixes from the "@context" of a JSON-LD string.- Parameters:
jsonString
- the JSON-LD string- Returns:
- a map from prefix name strings to prefix IRI strings
- Throws:
IOException
- on any problem
-
addBaseNamespace
public void addBaseNamespace(String baseNamespace)
Add a base namespace to the IOHelper.- Parameters:
baseNamespace
- namespace to add to bases.
-
addBaseNamespaces
public void addBaseNamespaces(String baseNamespacePath) throws IOException
Add a set of base namespaces to the IOHelper from file. Each base namespace should be on its own line.- Parameters:
baseNamespacePath
- path to base namespace file- Throws:
IOException
- if file does not exist
-
getBaseNamespaces
public Set<String> getBaseNamespaces()
Get the base namespaces.- Returns:
- set of base namespaces
-
getDefaultContext
public com.github.jsonldjava.core.Context getDefaultContext() throws IOException
Get a copy of the default context.- Returns:
- a copy of the current context
- Throws:
IOException
- if default context file cannot be read
-
getContext
public com.github.jsonldjava.core.Context getContext()
Get a copy of the current context.- Returns:
- a copy of the current context
-
setContext
public void setContext()
Set an empty context.
-
setContext
public void setContext(com.github.jsonldjava.core.Context context)
Set the current JSON-LD context to the given context.- Parameters:
context
- the new JSON-LD context
-
setContext
public void setContext(String jsonString) throws IOException
Set the current JSON-LD context to the given context.- Parameters:
jsonString
- the new JSON-LD context as a JSON string- Throws:
IOException
- on issue parsing JSON
-
setContext
public void setContext(Map<String,Object> map) throws IOException
Set the current JSON-LD context to the given map.- Parameters:
map
- a map of strings for the new JSON-LD context- Throws:
IOException
- on issue parsing JSON
-
setXMLEntityFlag
public void setXMLEntityFlag(Boolean entityFlag)
Set whether or not XML entities will be swapped into URIs in saveOntology XML output formats.- Parameters:
entityFlag
- value to set
-
getXMLEntityFlag
public Boolean getXMLEntityFlag()
Get the useXMLEntities flag.- Returns:
- boolean useXMLEntities flag
-
makePrefixManager
public static org.semanticweb.owlapi.util.DefaultPrefixManager makePrefixManager(Map<String,String> prefixes)
Make an OWLAPI DefaultPrefixManager from a map of prefixes.- Parameters:
prefixes
- a map from prefix name strings to prefix IRI strings- Returns:
- a new DefaultPrefixManager
-
getPrefixManager
public org.semanticweb.owlapi.util.DefaultPrefixManager getPrefixManager()
Get a prefix manager with the current prefixes.- Returns:
- a new DefaultPrefixManager
-
addPrefix
public void addPrefix(String combined) throws IllegalArgumentException, IOException
Add a prefix mapping as a single string "foo: http://example.com#".- Parameters:
combined
- both prefix and target- Throws:
IllegalArgumentException
- on malformed inputIOException
- if prefix cannot be parsed
-
addPrefix
public void addPrefix(String prefix, String target) throws IOException
Add a prefix mapping to the current JSON-LD context, as a prefix string and target string. Rebuilds the context.- Parameters:
prefix
- the short prefix to add; should not include ":"target
- the IRI string that is the target of the prefix- Throws:
IOException
- if prefix cannot be parsed
-
addPrefixes
public void addPrefixes(String prefixPath) throws IOException
Given a path to a JSON-LD prefix file, add the prefix mappings in the file to the current JSON-LD context.- Parameters:
prefixPath
- path to JSON-LD prefix file to add- Throws:
IOException
- if the file does not exist or cannot be read
-
addPrefixes
public void addPrefixes(com.github.jsonldjava.core.Context context1) throws IOException
Given a Context, add the prefix mappings to the current JSON-LD context.- Parameters:
context1
- Context to add- Throws:
IOException
- if the Context cannot be set
-
getPrefixes
public Map<String,String> getPrefixes()
Get a copy of the current prefix map.- Returns:
- a copy of the current prefix map
-
setPrefixes
public void setPrefixes(Map<String,Object> map) throws IOException
Set the current prefix map.- Parameters:
map
- the new map of prefixes to use- Throws:
IOException
- on issue parsing map to context
-
getContextString
public String getContextString() throws IOException
Return the current prefixes as a JSON-LD string.- Returns:
- the current prefixes as a JSON-LD string
- Throws:
IOException
- on any error
-
saveContext
public void saveContext(String path) throws IOException
Write the current context as a JSON-LD file.- Parameters:
path
- the path to write the context- Throws:
IOException
- on any error
-
saveContext
public void saveContext(File file) throws IOException
Write the current context as a JSON-LD file.- Parameters:
file
- the file to write the context- Throws:
IOException
- on any error
-
isValidCURIE
public static boolean isValidCURIE(CharSequence s)
Determine if a string is a CURIE. Note that a valid CURIE is not always a valid QName. Adapted from:- Parameters:
s
- Character sequence to check- Returns:
- true if valid CURIE
- See Also:
XMLUtils.isQName(CharSequence)
-
readCSV
public static List<List<String>> readCSV(String path) throws IOException
Read comma-separated values from a path to a list of lists of strings.- Parameters:
path
- file path to the CSV file- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
readCSV
public static List<List<String>> readCSV(InputStream stream) throws IOException
Read comma-separated values from a stream to a list of lists of strings.- Parameters:
stream
- the stream to read from- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
readCSV
public static List<List<String>> readCSV(Reader reader) throws IOException
Read comma-separated values from a reader to a list of lists of strings.- Parameters:
reader
- a reader to read data from- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
readTSV
public static List<List<String>> readTSV(String path) throws IOException
Read tab-separated values from a path to a list of lists of strings.- Parameters:
path
- file path to the CSV file- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
readTSV
public static List<List<String>> readTSV(InputStream stream) throws IOException
Read tab-separated values from a stream to a list of lists of strings.- Parameters:
stream
- the stream to read from- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
readTSV
public static List<List<String>> readTSV(Reader reader) throws IOException
Read tab-separated values from a reader to a list of lists of strings.- Parameters:
reader
- a reader to read data from- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
readTable
public static List<List<String>> readTable(String path) throws IOException
Read a table from a path to a list of lists of strings.- Parameters:
path
- file path to the CSV file- Returns:
- a list of lists of strings
- Throws:
IOException
- on file or reading problems
-
writeTable
public static void writeTable(List<String[]> table, String path) throws IOException
Write a table from a list of arrays.- Parameters:
table
- List of arrays to writepath
- path to write to- Throws:
IOException
- on file or writing problems
-
writeTable
public static void writeTable(List<String[]> table, File file, char separator) throws IOException
Write a table from a list of arrays.- Parameters:
file
- File to write totable
- List of arrays to writeseparator
- table separator- Throws:
IOException
- on problem making Writer object or auto-closing CSVWriter
-
writeTable
public static void writeTable(List<String[]> table, Writer writer, char separator) throws IOException
Write a table from a list of arrays.- Parameters:
writer
- Writer object to write totable
- List of arrays to writeseparator
- table separator- Throws:
IOException
- on problem auto-closing writer
-
-