Class 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
      static String HASH_SELF_URI
      Replacement URI for the resource.
      private static org.slf4j.Logger LOGGER  
    • Constructor Summary

      Constructors 
      Constructor Description
      RdfHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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 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 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 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 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 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 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.
      static String hashProperties​(org.apache.jena.rdf.model.StmtIterator statements)
      Computes a SHA1 hash of sorted and serialized resource properties.
      private static String serializeStatement​(org.apache.jena.rdf.model.Statement stmt)  
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • HASH_SELF_URI

        public static String HASH_SELF_URI
        Replacement URI for the resource. Currently has no effect on actual hash computation.
    • Constructor Detail

      • RdfHelper

        public RdfHelper()
    • Method Detail

      • 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
      • 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
      • 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
      • 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
      • 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)
      • 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
      • 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
      • 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
      • 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
      • hashProperties

        public static String hashProperties​(org.apache.jena.rdf.model.StmtIterator statements)
        Computes a SHA1 hash of sorted and serialized resource properties.
        Parameters:
        resource - the resource object for which this method computes the hash.
        Returns:
        the computed hash.
      • serializeStatement

        private static String serializeStatement​(org.apache.jena.rdf.model.Statement stmt)