Class RdfHelper

java.lang.Object
org.hobbit.utils.rdf.RdfHelper

public class RdfHelper extends Object
Implements simple methods to get data from a given RDF Model.
Author:
Michael Röder (roeder@informatik.uni-leipzig.de)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Boolean
    getBooleanValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Boolean of all triples that have the given subject and predicate and that can be found in the given model.
    static Byte
    getByteValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Byte of all triples that have the given subject and predicate and that can be found in the given model.
    protected static Calendar
    getCalendarValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.datatypes.xsd.XSDDatatype dateType)
     
    static Character
    getCharValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Character of all triples that have the given subject and predicate and that can be found in the given model.
    static Calendar
    getDateTimeValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the object as Calendar of the first triple that has the given subject and predicate and that can be found in the given model.
    static Calendar
    getDateValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the object as Calendar of the first triple that has the given subject and predicate and that can be found in the given model.
    static String
    getDescription(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource resource)
    Returns the description, i.e., the value of rdfs:comment, of the given Resource if it is present in the given Model.
    static Double
    getDoubleValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Double of all triples that have the given subject and predicate and that can be found in the given model.
    static Duration
    getDurationValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the object as Duration of the first triple that has the given subject and predicate and that can be found in the given model.
    static Float
    getFloatValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Float of all triples that have the given subject and predicate and that can be found in the given model.
    static Integer
    getIntValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Integer of all triples that have the given subject and predicate and that can be found in the given model.
    static String
    getLabel(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource resource)
    Returns the label of the given Resource if it is present in the given Model.
    static org.apache.jena.rdf.model.Literal
    getLiteral(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the first triple literal that has the given subject and predicate and that can be found in the given model.
    static Long
    getLongValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Long of all triples that have the given subject and predicate and that can be found in the given model.
    static org.apache.jena.rdf.model.RDFNode
    getObjectNode(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the first object that has the given subject and predicate and that can be found in the given model.
    protected static <T> T
    getObjectNode(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, Predicate<org.apache.jena.rdf.model.RDFNode> filter, Function<org.apache.jena.rdf.model.RDFNode,T> transformation)
     
    static List<org.apache.jena.rdf.model.RDFNode>
    getObjectNodes(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns all RDFNode literals that have the given subject and predicate and that can be found in the given model.
    protected static <T> List<T>
    getObjectNodes(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, Predicate<org.apache.jena.rdf.model.RDFNode> filter, Function<org.apache.jena.rdf.model.RDFNode,T> transformation)
     
    static org.apache.jena.rdf.model.Resource
    getObjectResource(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the object as Resource of the first triple that has the given subject and predicate and that can be found in the given model.
    static List<org.apache.jena.rdf.model.Resource>
    getObjectResources(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Resources of all triples that have the given subject and predicate and that can be found in the given model.
    static Short
    getShortValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Short of all triples that have the given subject and predicate and that can be found in the given model.
    static String
    getStringValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the object as String of the first triple that has the given subject and predicate and that can be found in the given model.
    static List<String>
    getStringValues(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
    Returns the objects as Strings of all triples that have the given subject and predicate and that can be found in the given model.
    static org.apache.jena.rdf.model.Resource
    getSubjectResource(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource object)
    Returns the first subject that has the given object and predicate and that can be found in the given model.
    static List<org.apache.jena.rdf.model.Resource>
    getSubjectResources(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource object)
    Returns a list of subjects of triples that have the given object and predicate and that can be found in the given model.
    protected static <T> T
    getValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, Function<org.apache.jena.rdf.model.Literal,T> transformation)
    Returns the result of the given transformation function executed using the first object of the first triple that has the given subject and predicate and that can be found in the given model.

    Methods inherited from class java.lang.Object

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

    • LOGGER

      private static final org.slf4j.Logger LOGGER
  • Constructor Details

    • RdfHelper

      public RdfHelper()
  • Method Details

    • getBooleanValue

      public static Boolean getBooleanValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Boolean of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as a Boolean or null if such a triple couldn't be found.
    • getByteValue

      public static Byte getByteValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Byte of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Byte or null if such a triple couldn't be found
    • getCalendarValue

      protected static Calendar getCalendarValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, org.apache.jena.datatypes.xsd.XSDDatatype dateType)
    • getCharValue

      public static Character getCharValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Character of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as a Character or null if such a triple couldn't be found.
    • getDateValue

      public static Calendar getDateValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the object as Calendar of the first triple that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Calendar or null if such a triple couldn't be found or the value can not be read as XSDDate
    • getDateTimeValue

      public static Calendar getDateTimeValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the object as Calendar of the first triple that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Calendar or null if such a triple couldn't be found or the value can not be read as XSDDateTime
    • getDescription

      public static String getDescription(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource resource)
      Returns the description, i.e., the value of rdfs:comment, of the given Resource if it is present in the given Model.
      Parameters:
      model - the model that should contain the label
      resource - the resource for which the label is requested
      Returns:
      the description of the resource or null if such a label does not exist
    • getDoubleValue

      public static Double getDoubleValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Double of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as a Double or null if such a triple couldn't be found.
    • getDurationValue

      public static Duration getDurationValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the object as Duration of the first triple that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Duration or null if such a triple couldn't be found or the value can not be read as XSDDuration
    • getFloatValue

      public static Float getFloatValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Float of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as a Float or null if such a triple couldn't be found.
    • getIntValue

      public static Integer getIntValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Integer of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Integer or null if such a triple couldn't be found
    • getLabel

      public static String getLabel(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource resource)
      Returns the label of the given Resource if it is present in the given Model.
      Parameters:
      model - the model that should contain the label
      resource - the resource for which the label is requested
      Returns:
      the label of the resource or null if such a label does not exist
    • getLiteral

      public static org.apache.jena.rdf.model.Literal getLiteral(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the first triple literal that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      literal of the triple or null if such a literal couldn't be found
    • getLongValue

      public static Long getLongValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Long of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Long or null if such a triple couldn't be found
    • getObjectNode

      public static org.apache.jena.rdf.model.RDFNode getObjectNode(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the first object that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple or null if such an object couldn't be found
    • getObjectNode

      protected static <T> T getObjectNode(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, Predicate<org.apache.jena.rdf.model.RDFNode> filter, Function<org.apache.jena.rdf.model.RDFNode,T> transformation)
    • getObjectNodes

      public static List<org.apache.jena.rdf.model.RDFNode> getObjectNodes(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns all RDFNode literals that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triples
      subject - the subject of the triples. null works like a wildcard.
      predicate - the predicate of the triples. null works like a wildcard.
      Returns:
      objects of the triples
    • getObjectNodes

      protected static <T> List<T> getObjectNodes(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, Predicate<org.apache.jena.rdf.model.RDFNode> filter, Function<org.apache.jena.rdf.model.RDFNode,T> transformation)
    • getObjectResource

      public static org.apache.jena.rdf.model.Resource getObjectResource(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the object as Resource of the first triple that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple
      predicate - the predicate of the triple
      Returns:
      object of the triple as Resource or null if such a triple couldn't be found
    • getObjectResources

      public static List<org.apache.jena.rdf.model.Resource> getObjectResources(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Resources of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple
      predicate - the predicate of the triple
      Returns:
      List of object of the triples as Resource
    • getStringValue

      public static String getStringValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the object as String of the first triple that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple null works like a wildcard.
      predicate - the predicate of the triple null works like a wildcard.
      Returns:
      object of the triple as String or null if such a triple couldn't be found
    • getStringValues

      public static List<String> getStringValues(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Strings of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triples
      subject - the subject of the triples. null works like a wildcard.
      predicate - the predicate of the triples. null works like a wildcard.
      Returns:
      objects of the triples as Strings
    • getShortValue

      public static Short getShortValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)
      Returns the objects as Short of all triples that have the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      subject - the subject of the triple. null works like a wildcard.
      predicate - the predicate of the triple. null works like a wildcard.
      Returns:
      object of the triple as Short or null if such a triple couldn't be found
    • getSubjectResource

      public static org.apache.jena.rdf.model.Resource getSubjectResource(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource object)
      Returns the first subject that has the given object and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      predicate - the predicate of the triple
      object - the object of the triple
      Returns:
      The first subject found as Resource or null if such a subject couldn't be found.
    • getSubjectResources

      public static List<org.apache.jena.rdf.model.Resource> getSubjectResources(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Property predicate, org.apache.jena.rdf.model.Resource object)
      Returns a list of subjects of triples that have the given object and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the triple
      predicate - the predicate of the triple
      object - the object of the triple
      Returns:
      List of subject of the triples as Resource
    • getValue

      protected static <T> T getValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate, Function<org.apache.jena.rdf.model.Literal,T> transformation)
      Returns the result of the given transformation function executed using the first object of the first triple that has the given subject and predicate and that can be found in the given model.
      Parameters:
      model - the model that should contain the label
      subject - the subject of the triple null works like a wildcard.
      predicate - the predicate of the triple null works like a wildcard.
      transformation - the transformation that is executed on selected literal
      Returns:
      the label of the resource or null if such a label does not exist