Modeling an RDF Resource
The following content highlights the key modifications to a Java class to convert it into an RDF resource class. As a starting point, consider a non-RDF class Expense. Such a class may be implemented similarly to the following sample code:
// Non-RDF Class
public class Expense {
private UUID _id;
private Date date;
private String description;
// ... Additional fields
public Expense() {
}
public Expense(date, description, //...) {
this.date = date;
this.description = descriptions;
//...
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
// ... Additional getters/setters and other content
}1. Extend the SolidRDFSource
The SolidRDFSource class maps to an RDF resource. A summary of parameters to the SolidRDFSource class constructors are as follows:
dataset
The RDF dataset (i.e., the sets of triples) contained in the resource.
To model the Expense class as an RDF resource, the class:
Extends the SolidRDFSource and
Adds constructors for the SolidRDFSource fields (
identifier,dataset,headers).
The SolidRDFSource constructor that accepts Metadata as a parameter (instead of Headers) has been deprecated.
2. Inner Class that Extends WrapperIRI
A sample RDF file that for a sample Expense data is shown below in Turtle format:
where:
subject
URL
<https://pod.example.com/container/expenses/202303/teamlunch>
predicates
URL
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type><https://schema.org/purchaseDate><https://schema.org/provider>etc.
objects
Literals or URLS
"2023-03-07T00:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>"Example Restaurant",<https://pod.example.com/expenses/receipt1.jpg>etc.
To handle the mapping of the expense data (date, provider, description, category, priceCurrency, total) to RDF triples (<subject> <predicate> <object>):
The
Expenseclass defines the predicate IRIs. That is, instead of having a Class field nameddate, for the RDF Resource, the value of the field is mapped to the IRI"https://schema.org/purchaseDate".The
Expenseclass defines an inner classNodethat extends the WrapperIRI class.
Add the Inner Class Field to the RDF Resource Class
To use the defined mappings in the inner class:
Update
Expense.javato include a new fieldsubjectset to the inner classNode.Update the
Expense.javagetters and setters to use thesubject‘s getters and setters.
Last updated