Class PrefixHelper
java.lang.Object
org.geneontology.obographs.owlapi.PrefixHelper
Provides convenience methods for working with JSON LD contexts and prefixes
Taken from ROBOT
- Author:
- James A. Overton
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new IOHelper with the default prefixes.PrefixHelper(boolean defaults) Create a new IOHelper with or without the default prefixes.PrefixHelper(File file) Create a new IOHelper with prefixes from a file.PrefixHelper(String path) Create a new IOHelper with prefixes from a file path.PrefixHelper(Map<String, Object> map) Create a new IOHelper with the specified prefixes. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a prefix mapping as a single string "foo: http://example.com#".voidAdd a prefix mapping to the current JSON-LD context, as a prefix string and target string.org.semanticweb.owlapi.model.IRIGiven a term string, use the current prefixes to create an IRI.com.github.jsonldjava.core.ContextGet a copy of the current context.Return the current prefixes as a JSON-LD string.com.github.jsonldjava.core.ContextGet a copy of the default context.Get a copy of the current prefix map.org.semanticweb.owlapi.util.DefaultPrefixManagerGet a prefix manager with the current prefixes.guessCatalogFile(File ontologyFile) Try to guess the location of the catalog.xml file.static org.semanticweb.owlapi.util.DefaultPrefixManagermakePrefixManager(Map<String, String> prefixes) Make an OWLAPI DefaultPrefixManager from a map of prefixes.static com.github.jsonldjava.core.ContextparseContext(String jsonString) Load a map of prefixes from the "@context" of a JSON-LD string.voidsaveContext(File file) Write the current context as a JSON-LD file.voidsaveContext(String path) Write the current context as a JSON-LD file.voidSet an empty context.voidsetContext(com.github.jsonldjava.core.Context context) Set the current JSON-LD context to the given context.voidsetContext(String jsonString) Set the current JSON-LD context to the given context.voidsetContext(Map<String, Object> map) Set the current JSON-LD context to the given map.voidsetPrefixes(Map<String, Object> map) Set the current prefix map.
-
Constructor Details
-
PrefixHelper
public PrefixHelper()Create a new IOHelper with the default prefixes. -
PrefixHelper
public PrefixHelper(boolean defaults) Create a new IOHelper with or without the default prefixes.- Parameters:
defaults- false if defaults should not be used
-
PrefixHelper
Create a new IOHelper with the specified prefixes.- Parameters:
map- the prefixes to use
-
PrefixHelper
Create a new IOHelper with prefixes from a file path.- Parameters:
path- to a JSON-LD file with a @context
-
PrefixHelper
Create a new IOHelper with prefixes from a file.- Parameters:
file- a JSON-LD file with a @context
-
-
Method Details
-
guessCatalogFile
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!
-
createIRI
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
-
parseContext
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
-
getDefaultContext
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
Set the current JSON-LD context to the given context.- Parameters:
jsonString- the new JSON-LD context as a JSON string
-
setContext
Set the current JSON-LD context to the given map.- Parameters:
map- a map of strings for the new JSON-LD context
-
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
Add a prefix mapping as a single string "foo: http://example.com#".- Parameters:
combined- both prefix and target- Throws:
IllegalArgumentException- on malformed input
-
addPrefix
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
-
getPrefixes
Get a copy of the current prefix map.- Returns:
- a copy of the current prefix map
-
setPrefixes
Set the current prefix map.- Parameters:
map- the new map of prefixes to use
-
getContextString
Return the current prefixes as a JSON-LD string.- Returns:
- the current prefixes as a JSON-LD string
- Throws:
IOException- on any error
-
saveContext
Write the current context as a JSON-LD file.- Parameters:
path- the path to write the context- Throws:
IOException- on any error
-
saveContext
Write the current context as a JSON-LD file.- Parameters:
file- the file to write the context- Throws:
IOException- on any error
-