Class RDFConverter

java.lang.Object
org.incenp.obofoundry.sssom.rdf.RDFConverter

public class RDFConverter extends Object
A helper class to convert SSSOM objects to and from a RDF model in the Rdf4J API.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance with the default policy for converting non-standard metadata.
    Creates a new instance with an explicit policy for converting non-standard metadata.
    RDFConverter(ExtraMetadataPolicy policy, Version assumedVersion)
    Creates a new instance with an explicit policy for converting non-standard metadata and a default assumed version.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    When converting from SSSOM to RDF, do not convert the mapping slots in the provided list.
    fromRDF(org.eclipse.rdf4j.model.Model model)
    Converts a RDF model to a MappingSet object.
    mappingFromRDF(org.eclipse.rdf4j.model.Model model)
    Converts a RDF model to a Mapping object.
    mappingFromRDF(org.eclipse.rdf4j.model.Model model, Version targetVersion)
    Converts a RDF model to a Mapping object.
    org.eclipse.rdf4j.model.Model
    Converts a MappingSet to a Rdf4J model.
    org.eclipse.rdf4j.model.Model
    toRDF(MappingSet ms, boolean includeNamespaces)
    Converts a MappingSet to a Rdf4J model, optionally including namespace declarations for the prefixes found in the set’s prefix map.
    org.eclipse.rdf4j.model.Model
    toRDF(MappingSet ms, Map<String,String> prefixMap)
    Converts a MappingSet to a Rdf4J model, including namespace declarations for all prefixes in the specified prefix map.
    org.eclipse.rdf4j.model.Model
    toRDF(MappingSet ms, PrefixManager prefixManager)
    Converts a MappingSet to a Rdf4J model, optional including namespace declarations for all prefixes held in the specified PrefixManager.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RDFConverter

      public RDFConverter()
      Creates a new instance with the default policy for converting non-standard metadata.
    • RDFConverter

      public RDFConverter(ExtraMetadataPolicy policy)
      Creates a new instance with an explicit policy for converting non-standard metadata.
      Parameters:
      policy - The non-standard metadata policy.
    • RDFConverter

      public RDFConverter(ExtraMetadataPolicy policy, Version assumedVersion)
      Creates a new instance with an explicit policy for converting non-standard metadata and a default assumed version.
      Parameters:
      policy - The non-standard metadata policy.
      assumedVersion - The version of the SSSOM specification that a set should be assumed to be compliant with, in the absence of an explicit sssom_version slot.
  • Method Details

    • excludeMappingSlots

      public void excludeMappingSlots(Set<String> slots)
      When converting from SSSOM to RDF, do not convert the mapping slots in the provided list.

      This is mainly intended to avoid converting the slots that have been condensed to the set level.

      Parameters:
      slots - A list of slot names to exclude from the RDF conversion.
    • toRDF

      public org.eclipse.rdf4j.model.Model toRDF(MappingSet ms)
      Converts a MappingSet to a Rdf4J model.
      Parameters:
      ms - The mapping set to convert.
      Returns:
      The corresponding RDF model.
    • toRDF

      public org.eclipse.rdf4j.model.Model toRDF(MappingSet ms, boolean includeNamespaces)
      Converts a MappingSet to a Rdf4J model, optionally including namespace declarations for the prefixes found in the set’s prefix map.

      The default behaviour is not to include namespace declarations, which means that, if the model is later serialised to file, all identifiers would be rendered using their long form. Including namespace declarations for all the prefixes set forth in the set’s prefix map allows identifiers to be serialised in short form.

      Parameters:
      ms - The mapping set to convert.
      includeNamespaces - If true, add a namespace declaration for every prefix in the set’s prefix map, if that prefix is effectively used in the set.
      Returns:
      The corresponding RDF model.
    • toRDF

      public org.eclipse.rdf4j.model.Model toRDF(MappingSet ms, Map<String,String> prefixMap)
      Converts a MappingSet to a Rdf4J model, including namespace declarations for all prefixes in the specified prefix map.

      Note that “builtin prefixes” are automatically added to the given prefix map.

      Parameters:
      ms - The mapping set to convert.
      prefixMap - A map of prefix name to URI prefixes to add to the model as namespace declarations, for the prefixes that are effectively used in the set. The set’s own prefix map will be ignored.
      Returns:
      The corresponding RDF model.
    • toRDF

      public org.eclipse.rdf4j.model.Model toRDF(MappingSet ms, PrefixManager prefixManager)
      Converts a MappingSet to a Rdf4J model, optional including namespace declarations for all prefixes held in the specified PrefixManager.
      Parameters:
      ms - The mapping set to convert.
      prefixManager - A prefix manager holding the prefixes to add to the model if they are effectively used in the set. The set’s own prefix map will be ignored. May be null, in which case no namespaces will be added to the model.
      Returns:
      The corresponding RDF model.
    • fromRDF

      public MappingSet fromRDF(org.eclipse.rdf4j.model.Model model) throws SSSOMFormatException
      Converts a RDF model to a MappingSet object.
      Parameters:
      model - The Rdf4J model to convert.
      Returns:
      The corresponding mapping set.
      Throws:
      SSSOMFormatException - If the contents of the model does not match what is expected for a SSSOM MappingSet object.
    • mappingFromRDF

      public Mapping mappingFromRDF(org.eclipse.rdf4j.model.Model model) throws SSSOMFormatException
      Converts a RDF model to a Mapping object.

      This method assumes the mapping is compliant with the highest supported version of the specification.

      Parameters:
      model - The Rdf4J model to convert.
      Returns:
      The corresponding mapping.
      Throws:
      SSSOMFormatException - If the contents of the model does not match what is expected for a SSSOM Mapping object.
    • mappingFromRDF

      public Mapping mappingFromRDF(org.eclipse.rdf4j.model.Model model, Version targetVersion) throws SSSOMFormatException
      Converts a RDF model to a Mapping object.
      Parameters:
      model - The Rdf4J model to convert.
      targetVersion - The version of the SSSOM specification the mapping is compliant with.
      Returns:
      The corresponding mapping.
      Throws:
      SSSOMFormatException - If the contents of the model does not match what is expected for a SSSOM Mapping object.