Class KGCLHelper

java.lang.Object
org.incenp.obofoundry.kgcl.KGCLHelper

public class KGCLHelper extends Object
A class providing static helper methods to work with KGCL.
  • Constructor Details

    • KGCLHelper

      public KGCLHelper()
  • Method Details

    • parse

      public static List<Change> parse(String kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager)
      Parses KGCL from a string.
      Parameters:
      kgcl - The KGCL instructions to parse.
      prefixManager - A prefix manager to expand CURIEs into IRIs. May be null.
      Returns:
      A KGCL changeset.
    • parse

      public static List<Change> parse(String kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors)
      Parses KGCL from a string and collects syntax errors.
      Parameters:
      kgcl - The KGCL instructions to parse.
      prefixManager - A prefix manager to expand CURIEs into IRIs. May be null.
      errors - A list that will collect any syntax error encountered when parsing. If null, errors will be ignored.
      Returns:
      A KGCL changeset.
    • parse

      public static List<Change> parse(String kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors, ILabelResolver labelResolver)
      Parses KGCL from a string and collects syntax errors. This method allows the use of labels in place of identifiers.
      Parameters:
      kgcl - The KGCL instructions to parse.
      prefixManager - A prefix manager to expand CURIEs into IRIS. May be null.
      errors - A list that will collect any syntax error encountered when parsing. If null, errors will be ignored.
      labelResolver - A helper object to resolve labels into identifiers. May be null, in which case any use of a label where an identifier is normally expected would result in a syntax error.
      Returns:
      A KGCL changeset.
    • parse

      public static List<Change> parse(String kgcl, Map<String,String> prefixMap, List<KGCLSyntaxError> errors, ILabelResolver labelResolver)
      Parses KGCL from a string and collects syntax errors.
      Parameters:
      kgcl - The KGCL instructions to parse.
      prefixMap - A map of prefix names to prefix IRIs.
      errors - A list that will collect any syntax error encountered when parsing. If null, errors will be ignored.
      labelResolver - A helper object to resolve labels into identifiers. May be null, in which case any use of a label where an identifier is normally expected would result in an error.
      Returns:
      A KGCL changeset.
    • parse

      public static List<Change> parse(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager) throws IOException
      Parses KGCL from a file.
      Parameters:
      kgcl - The file to parse.
      prefixManager - A prefix manager to expand CURIEs into IRIs. May be null.
      Returns:
      A KGCL changeset.
      Throws:
      IOException - If any non-KGCL I/O error occurs.
    • parse

      public static List<Change> parse(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors) throws IOException
      Parses KGCL from a file and collects syntax errors.
      Parameters:
      kgcl - The file to parse.
      prefixManager - A prefix manager to expand CURIEs into IRIs. May be null.
      errors - A list that will collect any syntax error encountered when parsing. If null, errors will be ignored.
      Returns:
      A KGCL changeset.
      Throws:
      IOException - If any non-KGCL I/O error occurs.
    • parse

      public static List<Change> parse(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors, ILabelResolver labelResolver) throws IOException
      Parses KGCL from a file and collects syntax errors. This method allows the use of labels in place of identifiers.
      Parameters:
      kgcl - The file to parse.
      prefixManager - A prefix manager to expand CURIEs into IRIs. May be null.
      errors - A list that will collect any syntax error encountered when parsing. If null, errors will be ignored.
      labelResolver - A helper object to resolve labels into identifiers. May be null, in which case any use of a label where an identifier is normally expected would result in a syntax error.
      Returns:
      A KGCL changeset.
      Throws:
      IOException - If any non-KGCL I/O error occurs.
    • parse

      public static List<Change> parse(File kgcl, Map<String,String> prefixMap, List<KGCLSyntaxError> errors, ILabelResolver labelResolver) throws IOException
      Parses KGCL from a file and collects syntax errors.
      Parameters:
      kgcl - The file to parse.
      prefixMap - A map of prefix names to prefix IRIs.
      errors - A list that will collect any syntax error encountered when parsing. If null, errors will be ignored
      labelResolver - A helper object to resolve labels into identifiers. May be null, in which case any use of a label where an identifier is normally expected would result in a syntax error.
      Returns:
      A KGCL changeset.
      Throws:
      IOException - If any non-KGCL I/O error occurs.
    • extractPendingChanges

      public static List<Change> extractPendingChanges(org.semanticweb.owlapi.model.OWLOntology ontology, ZonedDateTime before)
      Gets the "pending" (provisional) changes that are stored as KGCL annotations in the ontology,

      Note that the annotations are removed during the process.

      Parameters:
      ontology - The ontology to extract pending changes from.
      before - If not null, only changes older than the specified date are extracted.
      Returns:
      The list of pending changes.
    • apply

      public static void apply(List<Change> changeset, org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasoner reasoner, boolean noPartialApply)
      Applies a KGCL changeset to an ontology.
      Parameters:
      changeset - The changeset to apply.
      ontology - The ontology to apply it to.
      reasoner - The reasoner to use.
      noPartialApply - If true, changes will only be applied if they all can be applied.
    • apply

      public static void apply(List<Change> changeset, org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasoner reasoner, boolean noPartialApply, List<RejectedChange> rejects)
      Applies a KGCL changeset to an ontology.
      Parameters:
      changeset - The changeset to apply.
      ontology - The ontology to apply it to.
      reasoner - The reasoner to use.
      noPartialApply - If true, changes will only be applied if they can all be applied.
      rejects - A list that will collect the changes that cannot be applied. May be null.
    • apply

      public static void apply(List<Change> changeset, org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasoner reasoner, boolean noPartialApply, List<RejectedChange> rejects, boolean provisional)
      Applies a KGCL changeset to an ontology.
      Parameters:
      changeset - The changeset to apply.
      ontology - The ontology to apply it to.
      reasoner - The reasoner to use,
      noPartialApply - If true, changes will only be applied if they can all be applied.
      rejects - A list that will collect the changes that cannot be applied. May be null.
      provisional - If true, changes will be recorded in the ontology for later application, rather than applied directly.
    • apply

      public static void apply(List<Change> changeset, IPatcher patcher, boolean noPartialApply, List<RejectedChange> rejects)
      Applies a KGCL changeset using the provided patcher object.
      Parameters:
      changeset - The changeset to apply.
      patcher - The patcher for the knowledge graph to modify.
      noPartialApply - If true, changes will only be applied if they can all be applied.
      rejects - A list that will collect the changes that cannot be applied. May be null.