Class PrefixHelper

java.lang.Object
org.geneontology.obographs.owlapi.PrefixHelper

public class PrefixHelper extends Object
Provides convenience methods for working with JSON LD contexts and prefixes Taken from ROBOT
Author:
James A. Overton
  • 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

      public PrefixHelper(Map<String,Object> map)
      Create a new IOHelper with the specified prefixes.
      Parameters:
      map - the prefixes to use
    • PrefixHelper

      public PrefixHelper(String path)
      Create a new IOHelper with prefixes from a file path.
      Parameters:
      path - to a JSON-LD file with a @context
    • PrefixHelper

      public PrefixHelper(File file)
      Create a new IOHelper with prefixes from a file.
      Parameters:
      file - a JSON-LD file with a @context
  • Method Details

    • 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!
    • 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
    • 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
    • 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)
      Set the current JSON-LD context to the given context.
      Parameters:
      jsonString - the new JSON-LD context as a JSON string
    • setContext

      public void setContext(Map<String,Object> map)
      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

      public void addPrefix(String combined) throws IllegalArgumentException
      Add a prefix mapping as a single string "foo: http://example.com#".
      Parameters:
      combined - both prefix and target
      Throws:
      IllegalArgumentException - on malformed input
    • addPrefix

      public void addPrefix(String prefix, String target)
      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

      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)
      Set the current prefix map.
      Parameters:
      map - the new map of prefixes to use
    • 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