Class SSSOMTransformApplication<T>

java.lang.Object
org.incenp.obofoundry.sssom.transform.SSSOMTransformApplication<T>
Type Parameters:
T - The type of object that this application produces when the SSSOM/Transform ruleset is applied to mappings.
All Implemented Interfaces:
ISSSOMTransformApplication<T>
Direct Known Subclasses:
SSSOMTOwlApplication

public class SSSOMTransformApplication<T> extends Object implements ISSSOMTransformApplication<T>
Represents a SSSOM/Transform application, that is, a specialisation of the SSSOM/Transform language (also called a “SSSOM/Transform dialect”) with its own functions and that produces its own type of mapping-derived objects.
  • Constructor Details

    • SSSOMTransformApplication

      public SSSOMTransformApplication()
  • Method Details

    • getPrefixManager

      public PrefixManager getPrefixManager()
      Gets the prefix manager used by this application. It will have been provided by the SSSOM/Transform parser and will know of all the prefixes declared in the header of the ruleset.
      Returns:
      The prefix manager.
    • getVariableManager

      public VariableManager getVariableManager()
      Gets the variable manager used by this application. Functions may use this object to declare mapping-dependent variables and get their value for a given mapping.
      Returns:
      The variable manager.
    • getFormatter

      public MappingFormatter getFormatter()
      Gets the mapping formatter used by this application. Functions may use this object to expand placeholders found in their arguments. It may also be used to define more substitutions.

      The formatter is already configured to recognise placeholders corresponding to the standard SSSOM metadata fields. For example, %{subject_id} will be recognised and replaced by the subject ID of the current mapping.

      The formatter is also pre-configured with a short modifier to substitute IRI fields into CURIEs. For example, %{subject_id|short} will be replaced by the short form of the mapping’s subject ID.

      Returns:
      The mapping formatter.
    • registerFilter

      public void registerFilter(ISSSOMTFunction<IMappingFilter> function)
      Registers a new SSSOM/T filter function.

      The function will be called when its name is found in the filter part of a SSSOM/T rule. It should return a mapping filter.

      Parameters:
      function - The function to register.
    • registerDirective

      public void registerDirective(ISSSOMTFunction<Void> function)
      Registers a new SSSOM/T directive function.

      The function will be called when its name is found as the sole element of a SSSOM/T rule (no filters).

      Parameters:
      function - The function to register.
    • registerCallback

      public void registerCallback(ISSSOMTFunction<IMappingProcessorCallback> function)
      Registers a new SSSOM/T callback function.

      The function will be called when its name is found in the action part of a SSSOM/T rule, before looking up for a preprocessor or generator function. It should return a processor callback.

      Parameters:
      function - The function to register.
    • registerPreprocessor

      public void registerPreprocessor(ISSSOMTFunction<IMappingTransformer<Mapping>> function)
      Registers a new SSSOM/T preprocessor function.

      The function will be called when its name is found in the action part of a SSSOM/T rule, if no callback function with that name exists, before looking up for a generator function. It should return a preprocessor, that is, a transformer that produces mappings out of mappings.

      Parameters:
      function - The function to register.
    • registerGenerator

      public void registerGenerator(ISSSOMTFunction<IMappingTransformer<T>> function)
      Registers a new SSSOM/T generator function.

      The function will be called when its name is found in the action part of a SSSOM/T rule, if no callback function and no preprocessor function with that name exist. It should return a transformer that produces the desired type of objects from mappings.

      Parameters:
      function - The function to register.
    • onInit

      public void onInit(PrefixManager prefixManager)
      Description copied from interface: ISSSOMTransformApplication
      Initialises the application. This method is called by the SSSOM/Transform parser when all rules have been syntaxically parsed, before the parser attempts to process the action part of each rule.
      Specified by:
      onInit in interface ISSSOMTransformApplication<T>
      Parameters:
      prefixManager - A prefix manager initialised with all the prefix declarations found in the SSSOM/Transform file.
    • onFilter

      public IMappingFilter onFilter(String name, List<String> arguments, Map<String,String> keyedArguments) throws SSSOMTransformError
      Description copied from interface: ISSSOMTransformApplication
      Processes an application-specific filter. This method is called when the parser finds a function call within the filter part of a rule. If the application recognises the function, it must return a mapping filter; otherwise, it must return null or throw a SSSOMTransformError.
      Specified by:
      onFilter in interface ISSSOMTransformApplication<T>
      Parameters:
      name - The name of the function.
      arguments - The list of arguments passed to the function.
      keyedArguments - The map of keyed arguments (/key=...) passed to the function.
      Returns:
      A mapping filter that filters mappings according to the application’s needs, or null if the name is not a valid filter name for this application.
      Throws:
      SSSOMTransformError - If the application cannot process the filer (e.g., the arguments are invalid).
    • onDirectiveAction

      public boolean onDirectiveAction(String name, List<String> arguments, Map<String,String> keyedArguments) throws SSSOMTransformError
      Description copied from interface: ISSSOMTransformApplication
      Processes a directive action. This method is called when the parser finds a function call that is not associated with any filter. Such calls (which can only happen at the beginning of a SSSOM/T file, after the prefix declarations but before any other rule) cannot produce mapping processing rules but may otherwise influence the behaviour of the application. They are executed as soon as they are encountered when parsing the abstract tree.
      Specified by:
      onDirectiveAction in interface ISSSOMTransformApplication<T>
      Parameters:
      name - The name of the function.
      arguments - The list of arguments passed to the function.
      keyedArguments - The map of keyed arguments (/key=...) passed to the function.
      Returns:
      true if the name is a valid directive for this application, otherwise false/
      Throws:
      SSSOMTransformError - If the application cannot process the action (e.g. the arguments are invalid).
    • onCallback

      public IMappingProcessorCallback onCallback(String name, List<String> arguments, Map<String,String> keyedArguments) throws SSSOMTransformError
      Description copied from interface: ISSSOMTransformApplication
      Processes a callback action. This method is the first one called when the parser finds a normal action (any action associated with a filter). If the application recognises the function as a callback function, it must return the corresponding callback object; otherwise, it must return null.
      Specified by:
      onCallback in interface ISSSOMTransformApplication<T>
      Parameters:
      name - The name of the function.
      arguments - The list of arguments passed to the function.
      keyedArguments - The map of keyed arguments (/key=...) passed to the function.
      Returns:
      A callback object implementing the action according to the application’s needs, or null if the name is not a valid callback function name for this application.
      Throws:
      SSSOMTransformError - If the application cannot process the action (e.g., the arguments are invalid).
    • onPreprocessingAction

      public IMappingTransformer<Mapping> onPreprocessingAction(String name, List<String> arguments, Map<String,String> keyedArguments) throws SSSOMTransformError
      Description copied from interface: ISSSOMTransformApplication
      Processes a preprocessing action. This method is called when the parser finds a normal action that is not recognised as a callback action (i.e. ISSSOMTransformApplication.onCallback(String, List, Map) returned null). It the application recognises the function, it must return a mapping preprocessor; otherwise, it must return null.
      Specified by:
      onPreprocessingAction in interface ISSSOMTransformApplication<T>
      Parameters:
      name - The name of the function.
      arguments - The list of arguments passed to the function.
      keyedArguments - The map of keyed arguments (/key=...) passed to the function.
      Returns:
      A mapping preprocessor implementing the action according to the application’s needs, or null if the name is not a valid preprocessing function name for this application.
      Throws:
      SSSOMTransformError - If the application cannot process the action (e.g., the arguments are invalid).
    • onGeneratingAction

      public IMappingTransformer<T> onGeneratingAction(String name, List<String> arguments, Map<String,String> keyedArguments) throws SSSOMTransformError
      Description copied from interface: ISSSOMTransformApplication
      Processes a generating action. This method is called when the parser finds a normal action that is not recognised as a callback action nor as a preprocessing action (i.e. both ISSSOMTransformApplication.onCallback(String, List, Map) and ISSSOMTransformApplication.onPreprocessingAction(String, List, Map) returned null). If the application recognises the function, it must return a mapping transformer that produces the kind of objects desired by the application.
      Specified by:
      onGeneratingAction in interface ISSSOMTransformApplication<T>
      Parameters:
      name - The name of the function.
      arguments - The list of arguments passed to the function.
      keyedArguments - The map of keyed arguments (/key=...) passed to the function.
      Returns:
      A mapping transformer implementing the action according to the application’s needs.
      Throws:
      SSSOMTransformError - If the application cannot process the action (e.g. the name is not recognised or the arguments are invalid).