public class IOHelper extends Object
Constructor and 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(Map<String,Object> map)
Create a new IOHelper with the specified prefixes.
|
IOHelper(String path)
Create a new IOHelper with prefixes from a file path.
|
Modifier and Type | Method and 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)
Given a term string, use the current prefixes to create an IRI.
|
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,
org.semanticweb.owlapi.model.IRI type)
Create a typed OWLLiteral.
|
org.semanticweb.owlapi.model.OWLLiteral |
createTypedLiteral(String value,
String 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.
|
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(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(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.
|
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 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,
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,
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.
|
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,
String ontologyPath)
Save an ontology to a String path.
|
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(Map<String,Object> map)
Set the current JSON-LD context to the given map.
|
void |
setContext(String jsonString)
Set the current JSON-LD context to the given context.
|
void |
setPrefixes(Map<String,Object> map)
Set the current prefix map.
|
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,
String path)
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.
|
public IOHelper() throws IOException
IOException
- on problem getting default contextpublic IOHelper(boolean defaults) throws IOException
defaults
- false if defaults should not be usedIOException
- on problem getting default contextpublic IOHelper(Map<String,Object> map) throws IOException
map
- the prefixes to useIOException
- on issue parsing mappublic IOHelper(String path) throws IOException
path
- to a JSON-LD file with a @contextIOException
- on issue parsing JSON-LD file as contextpublic IOHelper(File file) throws IOException
file
- a JSON-LD file with a @contextIOException
- on issue reading file or setting context from file@Deprecated public void addPrefixesAndSave(org.semanticweb.owlapi.model.OWLOntology ontology, File outputFile, List<String> addPrefixes) throws IOException
saveOntology(OWLOntology, OWLDocumentFormat, IRI, Map,
boolean)
ontology
- OWLOntology to saveoutputFile
- File to save ontology toaddPrefixes
- List of prefixes to add ("foo: http://foo.bar/")IOException
- On issue parsing list of prefixes or saving fileprotected static boolean cleanTDB(String tdbDir)
tdbDir
- directory to removepublic File guessCatalogFile(File ontologyFile)
ontologyFile
- thepublic org.semanticweb.owlapi.model.OWLOntology loadOntology(String ontologyPath) throws IOException
ontologyPath
- the path to the ontology fileIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(String ontologyPath, boolean useCatalog) throws IOException
ontologyPath
- the path to the ontology fileuseCatalog
- when true, a catalog file will be used if one is foundIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(String ontologyPath, String catalogPath) throws IOException
ontologyPath
- the path to the ontology filecatalogPath
- the path to the catalog fileIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(File ontologyFile) throws IOException
ontologyFile
- the ontology file to loadIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(File ontologyFile, boolean useCatalog) throws IOException
ontologyFile
- the ontology file to loaduseCatalog
- when true, a catalog file will be used if one is foundIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(File ontologyFile, File catalogFile) throws IOException
ontologyFile
- the ontology file to loadcatalogFile
- the catalog file to useIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(InputStream ontologyStream) throws IOException
ontologyStream
- the ontology stream to loadIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(InputStream ontologyStream, String catalogPath) throws IOException
ontologyStream
- the ontology stream to loadcatalogPath
- the catalog file to use or nullIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(org.semanticweb.owlapi.model.IRI ontologyIRI) throws IOException
ontologyIRI
- the ontology IRI to loadIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology loadOntology(org.semanticweb.owlapi.model.IRI ontologyIRI, String catalogPath) throws IOException
ontologyIRI
- the ontology IRI to loadcatalogPath
- the catalog file to use or nullIOException
- on any problempublic static org.apache.jena.query.Dataset loadToTDBDataset(String inputPath, String tdbDir) throws org.apache.jena.shared.JenaException
WARNING - this creates a directory at given tdbDir location!
inputPath
- input path of RDF/XML or TTL filetdbDir
- location to put TDB mappingsorg.apache.jena.shared.JenaException
- if TDB directory can't be written topublic static org.semanticweb.owlapi.model.OWLDocumentFormat getFormat(String formatName) throws IllegalArgumentException
Suported formats:
formatName
- the name of the formatIllegalArgumentException
- if format name is not recognizedpublic org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, String ontologyPath) throws IOException
ontology
- the ontology to saveontologyPath
- the path to save the ontology toIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, File ontologyFile) throws IOException
ontology
- the ontology to saveontologyFile
- the file to save the ontology toIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.IRI ontologyIRI) throws IOException
ontology
- the ontology to saveontologyIRI
- the IRI to save the ontology toIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, File ontologyFile) throws IOException
ontology
- the ontology to saveformat
- the ontology format to useontologyFile
- the file to save the ontology toIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, File ontologyFile, boolean checkOBO) throws IOException
ontology
- the ontology to saveformat
- the ontology format to useontologyFile
- the file to save the ontology tocheckOBO
- if false, ignore OBO document checksIOException
- on any problempublic 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
ontology
- the ontology to saveformat
- the ontology format to useontologyIRI
- the IRI to save the ontology toIOException
- on any problempublic org.semanticweb.owlapi.model.OWLOntology saveOntology(org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.model.OWLDocumentFormat format, String ontologyPath, boolean checkOBO) throws IOException
ontology
- the ontology to saveformat
- the ontology format to useontologyPath
- the path to save the ontology tocheckOBO
- if false, ignore OBO document checksIOException
- on any problempublic 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
ontology
- the ontology to saveformat
- the ontology format to useontologyIRI
- the IRI to save the ontology tocheckOBO
- if false, ignore OBO document checksIOException
- on any problempublic 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
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 checksIOException
- on any problempublic Set<String> extractTerms(String input)
input
- the String containing the term identifierspublic static String cellToA1(int rowNum, int colNum)
rowNum
- row indexcolNum
- column indexpublic org.semanticweb.owlapi.model.IRI createIRI(String term)
term
- the term to convert to an IRIpublic org.semanticweb.owlapi.model.IRI createIRI(String term, boolean qName)
term
- the term to convert to an IRIqName
- if true, check that the expanded IRI is a valid QName (if not, return null)public Set<org.semanticweb.owlapi.model.IRI> createIRIs(Set<String> terms) throws IllegalArgumentException
terms
- the set of term identifier stringsIllegalArgumentException
- if term identifier is not a valid IRIpublic static org.semanticweb.owlapi.model.OWLLiteral createLiteral(String value)
value
- the lexical valuepublic static org.semanticweb.owlapi.model.OWLLiteral createTaggedLiteral(String value, String lang)
value
- the lexical valuelang
- the language tagpublic org.semanticweb.owlapi.model.OWLLiteral createTypedLiteral(String value, String type)
value
- the lexical valuetype
- the type IRI stringpublic org.semanticweb.owlapi.model.OWLLiteral createTypedLiteral(String value, org.semanticweb.owlapi.model.IRI type)
value
- the lexical valuetype
- the type IRIpublic Set<org.semanticweb.owlapi.model.IRI> parseTerms(String input) throws IllegalArgumentException
input
- the string containing the IRI stringsIllegalArgumentException
- if term identifier is not a valid IRIpublic static com.github.jsonldjava.core.Context parseContext(String jsonString) throws IOException
jsonString
- the JSON-LD stringIOException
- on any problempublic void addBaseNamespace(String baseNamespace)
baseNamespace
- namespace to add to bases.public void addBaseNamespaces(String baseNamespacePath) throws IOException
baseNamespacePath
- path to base namespace fileIOException
- if file does not existpublic Set<String> getBaseNamespaces()
public com.github.jsonldjava.core.Context getDefaultContext() throws IOException
IOException
- if default context file cannot be readpublic com.github.jsonldjava.core.Context getContext()
public void setContext()
public void setContext(com.github.jsonldjava.core.Context context)
context
- the new JSON-LD contextpublic void setContext(String jsonString) throws IOException
jsonString
- the new JSON-LD context as a JSON stringIOException
- on issue parsing JSONpublic void setContext(Map<String,Object> map) throws IOException
map
- a map of strings for the new JSON-LD contextIOException
- on issue parsing JSONpublic void setXMLEntityFlag(Boolean entityFlag)
entityFlag
- value to setpublic Boolean getXMLEntityFlag()
public static org.semanticweb.owlapi.util.DefaultPrefixManager makePrefixManager(Map<String,String> prefixes)
prefixes
- a map from prefix name strings to prefix IRI stringspublic org.semanticweb.owlapi.util.DefaultPrefixManager getPrefixManager()
public void addPrefix(String combined) throws IllegalArgumentException, IOException
combined
- both prefix and targetIllegalArgumentException
- on malformed inputIOException
- if prefix cannot be parsedpublic void addPrefix(String prefix, String target) throws IOException
prefix
- the short prefix to add; should not include ":"target
- the IRI string that is the target of the prefixIOException
- if prefix cannot be parsedpublic void addPrefixes(String prefixPath) throws IOException
prefixPath
- path to JSON-LD prefix file to addIOException
- if the file does not exist or cannot be readpublic void addPrefixes(com.github.jsonldjava.core.Context context1) throws IOException
context1
- Context to addIOException
- if the Context cannot be setpublic Map<String,String> getPrefixes()
public void setPrefixes(Map<String,Object> map) throws IOException
map
- the new map of prefixes to useIOException
- on issue parsing map to contextpublic String getContextString() throws IOException
IOException
- on any errorpublic void saveContext(String path) throws IOException
path
- the path to write the contextIOException
- on any errorpublic void saveContext(File file) throws IOException
file
- the file to write the contextIOException
- on any errorpublic static List<List<String>> readCSV(String path) throws IOException
path
- file path to the CSV fileIOException
- on file or reading problemspublic static List<List<String>> readCSV(InputStream stream) throws IOException
stream
- the stream to read fromIOException
- on file or reading problemspublic static List<List<String>> readCSV(Reader reader) throws IOException
reader
- a reader to read data fromIOException
- on file or reading problemspublic static List<List<String>> readTSV(String path) throws IOException
path
- file path to the CSV fileIOException
- on file or reading problemspublic static List<List<String>> readTSV(InputStream stream) throws IOException
stream
- the stream to read fromIOException
- on file or reading problemspublic static List<List<String>> readTSV(Reader reader) throws IOException
reader
- a reader to read data fromIOException
- on file or reading problemspublic static List<List<String>> readTable(String path) throws IOException
path
- file path to the CSV fileIOException
- on file or reading problemspublic static void writeTable(List<String[]> table, String path) throws IOException
table
- List of arrays to writepath
- path to write toIOException
- on file or writing problemspublic static void writeTable(List<String[]> table, File file, char separator) throws IOException
file
- File to write totable
- List of arrays to writeseparator
- table separatorIOException
- on problem making Writer object or auto-closing CSVWriterpublic static void writeTable(List<String[]> table, Writer writer, char separator) throws IOException
writer
- Writer object to write totable
- List of arrays to writeseparator
- table separatorIOException
- on problem auto-closing writerCopyright © 2015–2020. All rights reserved.