Class KGCLHelper


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

      Constructors 
      Constructor Description
      KGCLHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void apply​(List<org.incenp.obofoundry.kgcl.model.Change> changeset, IPatcher patcher, boolean noPartialApply, List<RejectedChange> rejects)
      Applies a KGCL changeset using the provided patcher object.
      static void apply​(List<org.incenp.obofoundry.kgcl.model.Change> changeset, org.semanticweb.owlapi.model.OWLOntology ontology, org.semanticweb.owlapi.reasoner.OWLReasoner reasoner, boolean noPartialApply)
      Applies a KGCL changeset to an ontology.
      static void apply​(List<org.incenp.obofoundry.kgcl.model.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.
      static void apply​(List<org.incenp.obofoundry.kgcl.model.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.
      static List<org.incenp.obofoundry.kgcl.model.Change> extractPendingChanges​(org.semanticweb.owlapi.model.OWLOntology ontology, ZonedDateTime before)
      Gets the "pending" (provisional) changes that are stored as KGCL annotations in the ontology,
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(File kgcl, Map<String,​String> prefixMap, List<KGCLSyntaxError> errors, ILabelResolver labelResolver)
      Parses KGCL from a file and collects syntax errors.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager)
      Parses KGCL from a file.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors)
      Parses KGCL from a file and collects syntax errors.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors, ILabelResolver labelResolver)
      Parses KGCL from a file and collects syntax errors.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(String kgcl, Map<String,​String> prefixMap, List<KGCLSyntaxError> errors, ILabelResolver labelResolver)
      Parses KGCL from a string and collects syntax errors.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(String kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager)
      Parses KGCL from a string.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(String kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors)
      Parses KGCL from a string and collects syntax errors.
      static List<org.incenp.obofoundry.kgcl.model.Change> parse​(String kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager, List<KGCLSyntaxError> errors, ILabelResolver labelResolver)
      Parses KGCL from a string and collects syntax errors.
      static List<org.incenp.obofoundry.kgcl.model.Change> parseYAML​(File kgcl, Map<String,​String> prefixMap)
      Parses a changeset serialised in YAML form.
      static List<org.incenp.obofoundry.kgcl.model.Change> parseYAML​(File kgcl, org.semanticweb.owlapi.model.PrefixManager prefixManager)
      Parses a changeset serialised in YAML form.
    • Constructor Detail

      • KGCLHelper

        public KGCLHelper()
    • Method Detail

      • parse

        public static List<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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.
      • parseYAML

        public static List<org.incenp.obofoundry.kgcl.model.Change> parseYAML​(File kgcl,
                                                                              Map<String,​String> prefixMap)
                                                                       throws IOException
        Parses a changeset serialised in YAML form.
        Parameters:
        kgcl - The YAML file from which to read the changeset. That file is expected to contain a list of KGCL change objects.
        prefixMap - A map of prefix names to prefix IRIs. May be null.
        Returns:
        A KGCL changeset.
        Throws:
        IOException - If any error occurs. Note that, contrary to the methods that read from the KGCL controlled natural language, here this includes post-I/O errors caused by invalid KGCL contents within the source file.
      • parseYAML

        public static List<org.incenp.obofoundry.kgcl.model.Change> parseYAML​(File kgcl,
                                                                              org.semanticweb.owlapi.model.PrefixManager prefixManager)
                                                                       throws IOException
        Parses a changeset serialised in YAML form.
        Parameters:
        kgcl - The YAML file from which to read the changeset. That file is expected to contain a list of KGCL change objects.
        prefixManager - A prefix manager to expand CURIEs into IRIs. May be null.
        Returns:
        A KGCL changeset.
        Throws:
        IOException - If any error occurs. Note that, contrary to the methods that read from the KGCL controlled natural language, here this includes post-I/O errors caused by invalid KGCL contents within the source file.
      • extractPendingChanges

        public static List<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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<org.incenp.obofoundry.kgcl.model.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.