All Implemented Interfaces:
Filter, IMatcher<org.apache.jena.ontology.OntModel,Alignment,Properties>, eu.sealsproject.platform.res.domain.omt.IOntologyMatchingToolBridge, eu.sealsproject.platform.res.tool.api.IPlugin, eu.sealsproject.platform.res.tool.api.IToolBridge

public class RelationTypePredictor extends TransformersFilter
This matcher predicts the relation type given a transformer model. This component do not create new correspondences but refine the relation of given class correspondences.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • NEWLINE

      private static final String NEWLINE
    • allowFiltering

      protected boolean allowFiltering
  • Constructor Details

  • Method Details

    • match

      public Alignment match(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment inputAlignment, Properties properties) throws Exception
      Description copied from class: MatcherYAAAJena
      Aligns two ontologies specified via a Jena OntModel, with an input alignment as Alignment object, and returns the mapping of the resulting alignment. Note: This method might be called multiple times in a row when using the evaluation framework. Make sure to return a mapping which is specific to the given inputs.
      Specified by:
      match in interface IMatcher<org.apache.jena.ontology.OntModel,Alignment,Properties>
      Overrides:
      match in class TransformersFilter
      Parameters:
      source - This OntModel represents the source ontology.
      target - This OntModel represents the target ontology.
      inputAlignment - This mapping represents the input alignment.
      properties - Additional properties.
      Returns:
      The resulting alignment of the matching process.
      Throws:
      Exception - Any exception which occurs during matching.
    • createPredictionFile

      public Map<Correspondence,List<Integer>> createPredictionFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment predictionAlignment, File outputFile, boolean append) throws IOException
      Description copied from class: TransformersFilter
      Create the prediction file which is a CSV file with two columns.The first column is the text from the left resource and the second column is the text from the right resource.
      Overrides:
      createPredictionFile in class TransformersFilter
      Parameters:
      source - The source model
      target - The target model
      predictionAlignment - the alignment to process. All correspondences which have enough text are used.
      outputFile - the csv file to which the output should be written to.
      append - if true, then the training alignment is append to the given file.
      Returns:
      the map which maps the the correspondence to (possibly multiple) row numbers. In case of multipleTextsToMultipleExamples is set to true, multiple rows can correspond to one correspondence, because each text (e.g. label, comment etc) of the two resources is used as an example.
      Throws:
      IOException - in case the writing fails.
    • createPredictionFile

      public Map<Correspondence,List<Integer>> createPredictionFile(org.apache.jena.ontology.OntModel source, org.apache.jena.ontology.OntModel target, Alignment predictionAlignment, File outputFile, boolean append, boolean requiresSwitchExmaples) throws IOException
      Throws:
      IOException
    • setChangeClass

      public void setChangeClass(boolean changeClass)
      Description copied from class: TransformersFilter
      If set to true, the class is changed in the classification. This is useful if a pretrained model predict exactly the opposite class.
      Overrides:
      setChangeClass in class TransformersFilter
      Parameters:
      changeClass - true if the class should be changed in the classification.
    • predictConfidences

      public List<Double> predictConfidences(File predictionFilePath) throws Exception
      Description copied from class: TransformersFilter
      Run huggingface transformers library.
      Overrides:
      predictConfidences in class TransformersFilter
      Parameters:
      predictionFilePath - path to csv file with two columns (text left and text right).
      Returns:
      a list of confidences
      Throws:
      Exception - in case something goes wrong.
    • predictConfidencesMultiClass

      public List<List<Double>> predictConfidencesMultiClass(File predictionFilePath) throws Exception
      Throws:
      Exception
    • getSortedResults

      private Map<Correspondence,List<RelationTypePredictionResult>> getSortedResults(List<List<Double>> predictions, Map<Correspondence,List<Integer>> map)
    • getFinalBestPrediction

      private RelationTypePredictionResult getFinalBestPrediction(List<RelationTypePredictionResult> predictions, int negativeClass)
    • isAllowFiltering

      public boolean isAllowFiltering()
    • setAllowFiltering

      public void setAllowFiltering(boolean allowFiltering)