Package org.hobbit.utils.rdf
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 static StringHASH_SELF_URIReplacement URI for the resource.private static org.slf4j.LoggerLOGGER
-
Constructor Summary
Constructors Constructor Description RdfHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static CalendargetCalendarValue(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 CalendargetDateTimeValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)Returns the object asCalendarof the first triple that has the given subject and predicate and that can be found in the given model.static CalendargetDateValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)Returns the object asCalendarof the first triple that has the given subject and predicate and that can be found in the given model.static StringgetDescription(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 givenResourceif it is present in the givenModel.static DurationgetDurationValue(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)Returns the object asDurationof the first triple that has the given subject and predicate and that can be found in the given model.static StringgetLabel(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource resource)Returns the label of the givenResourceif it is present in the givenModel.static org.apache.jena.rdf.model.LiteralgetLiteral(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.ResourcegetObjectResource(org.apache.jena.rdf.model.Model model, org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property predicate)Returns the object asResourceof 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 asResources of all triples that have the given subject and predicate and that can be found in the given model.static StringgetStringValue(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 StringhashProperties(org.apache.jena.rdf.model.StmtIterator statements)Computes a SHA1 hash of sorted and serialized resource properties.private static StringserializeStatement(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.
-
-
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 givenResourceif it is present in the givenModel.- Parameters:
model- the model that should contain the labelresource- the resource for which the label is requested- Returns:
- the label of the resource or
nullif 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 givenResourceif it is present in the givenModel.- Parameters:
model- the model that should contain the labelresource- the resource for which the label is requested- Returns:
- the description of the resource or
nullif 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 triplesubject- the subject of the triplenullworks like a wildcard.predicate- the predicate of the triplenullworks like a wildcard.- Returns:
- object of the triple as String or
nullif 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 triplessubject- the subject of the triples.nullworks like a wildcard.predicate- the predicate of the triples.nullworks 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 asCalendarof 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 triplesubject- the subject of the triple.nullworks like a wildcard.predicate- the predicate of the triple.nullworks like a wildcard.- Returns:
- object of the triple as
Calendarornullif 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 asCalendarof 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 triplesubject- the subject of the triple.nullworks like a wildcard.predicate- the predicate of the triple.nullworks like a wildcard.- Returns:
- object of the triple as
Calendarornullif 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 asDurationof 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 triplesubject- the subject of the triple.nullworks like a wildcard.predicate- the predicate of the triple.nullworks like a wildcard.- Returns:
- object of the triple as
Durationornullif 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 triplesubject- the subject of the triple.nullworks like a wildcard.predicate- the predicate of the triple.nullworks like a wildcard.- Returns:
- literal of the triple or
nullif 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 asResourceof 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 triplesubject- the subject of the triplepredicate- the predicate of the triple- Returns:
- object of the triple as
Resourceornullif 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 asResources 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 triplesubject- the subject of the triplepredicate- 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 triplepredicate- the predicate of the tripleobject- 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)
-
-