Package org.hobbit.utils.rdf
Class RdfHelper
java.lang.Object
org.hobbit.utils.rdf.RdfHelper
Implements simple methods to get data from a given RDF Model.
- Author:
- Michael Röder (roeder@informatik.uni-leipzig.de)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleangetBooleanValue(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 BytegetByteValue(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 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 CharactergetCharValue(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 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 DoublegetDoubleValue(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 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 FloatgetFloatValue(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 IntegergetIntValue(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 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 LonggetLongValue(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.RDFNodegetObjectNode(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> TgetObjectNode(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.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 ShortgetShortValue(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 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.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.ResourcegetSubjectResource(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> TgetValue(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.
-
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 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 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 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 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 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 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 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
-
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
-
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 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 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 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
-
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 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 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 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 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 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
-
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
-
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 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 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 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 or
nullif such an object couldn't be found
-
getObjectNode
-
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 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
-
getObjectNodes
-
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
-
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
-
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 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 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 triplepredicate- the predicate of the tripleobject- the object of the triple- Returns:
- The first subject found as
Resourceornullif 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 triplepredicate- the predicate of the tripleobject- 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 labelsubject- the subject of the triplenullworks like a wildcard.predicate- the predicate of the triplenullworks like a wildcard.transformation- the transformation that is executed on selected literal- Returns:
- the label of the resource or
nullif such a label does not exist
-