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:

Field
Type
Description

identifier

The URI (Uniform Resource Identifier) of the resource.

dataset

The RDF dataset (i.e., the sets of triples) contained in the resource.

headers

Collection of HTTP headers.

To model the Expense class as an RDF resource, the class:

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 Expense class defines the predicate IRIs. That is, instead of having a Class field named date, for the RDF Resource, the value of the field is mapped to the IRI "https://schema.org/purchaseDate".

  • The Expense class defines an inner class Node that 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.java to include a new field subject set to the inner class Node.

  • Update the Expense.java getters and setters to use the subject‘s getters and setters.

Last updated