user3352632
user3352632

Reputation: 667

How do I add a start and end time to a RDF triple?

Supposing we have the following triple in Turtle syntax:

<http:/example.com/Paul> <http:/example.com/running> <http:/example.com/10miles> .

How do I add a start and end time? For example if I want to say he started at 10 am and finished his 10miles run at 12 am. I want to use xsd:dateTime.

Upvotes: 6

Views: 2155

Answers (3)

jschnasse
jschnasse

Reputation: 9498

Just as an idea.

1. The modelling part (not much RDF involved)

{
    "runs": [
        {
            "id": "runs:0000001",
            "distance": {
                "length": 10.0,
                "unit": "mile"
            },
            "time": {
                "start": "2018-04-09T10:00:00",
                "end": "2018-04-09T12:00:00"
            },
            "runner": {
                "id": "runner:0000002",
                "name": "Paul"
            }
        }
    ]
}

2. The RDF part: define a proper context for your document.

   "@context": {
        "ical": "http://www.w3.org/2002/12/cal/ical#",
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "runs": {
            "@id": "info:stack/49726990/runs/",
            "@container": "@list"
        },
        "distance": {
            "@id": "info:stack/49726990/distance"
        },
        "length": {
            "@id": "info:stack/49726990/length",
            "@type": "xsd:double"
        },
        "unit": {
            "@id": "info:stack/49726990/unit"
        },
        "runner": {
            "@id": "info:stack/49726990/runner/"
        },
        "name": {
            "@id": "info:stack/49726990/name"
        },
        "time": {
            "@id": "info:stack/49726990/time"
        },
        "start": {
            "@id":"ical:dtstart",
            "@type": "xsd:dateTime"
        },
        "end": {
            "@id":"ical:dtend",
            "@type": "xsd:dateTime"
        },
        "id": "@id"
    }

3. The fun part: Throw it to an RDF converter of your choice

This is how it looks in JSON-Playground

Upvotes: 0

unor
unor

Reputation: 96587

Give each of Paul’s runs its own URI:

@prefix ex: <http://example.com/> .

ex:Paul ex:running ex:PaulsRun1, ex:PaulsRun2, ex:PaulsRun3 .

This allows you (and others) to make statements about each run:

@prefix ex: <http://example.com/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:PaulsRun3 
  ex:lengthInMiles 10.0 ;
  ex:startTime "2018-04-09T10:00:00"^^xsd:dateTime ;
  ex:endTime "2018-04-09T12:00:00"^^xsd:dateTime .

Instead of listing all these runs as objects of ex:Paul ex:running, you could specify the runner for each run:

@prefix ex: <http://example.com/> .

ex:PaulsRun1
  ex:runner ex:Paul .
  # ex:lengthInMiles, ex:startTime, ex:endTime, etc.

ex:PaulsRun2
  ex:runner ex:Paul .
  # ex:lengthInMiles, ex:startTime, ex:endTime, etc.

ex:PaulsRun3 
  ex:runner ex:Paul .
  # ex:lengthInMiles, ex:startTime, ex:endTime, etc.

If you don’t want to create a URI for each runner’s run, you could use (unlabeled) blank nodes instead. But this makes it hard/impossible for others to refer to these runs.

Upvotes: 2

Ivo Velitchkov
Ivo Velitchkov

Reputation: 2431

One way of doing this is through reification - making statements about the statement. Here, you have a choice of giving the statement a URI, so that it's externally dereferenceable, or using a blank node. That would mean, in your case, that you need to identify the statement by making statements about it subject, object and predicate, and tell more things about it, in your case - about start and end of a period it represents. This is how it would look with a blank node:

[
  rdf:type rdf:Statement ;   #this anonymous resource is a Statement... 
  rdf:subject ex:Paul ;      #...with subject Paul
  rdf:predicate ex:running ; #...predicate running
  rdf:object "10miles" ;     #...and object "10miles"
  ex:hasPeriodStart "2018-04-09T10:00:00"^^xsd:dateTime ;
  ex:hasPeriodEnd "2018-04-09T12:00:00"^^xsd:dateTime ;
].

When defining ex:hasPeriodStart and ex:hasPeriodEnd you might want to declare their type and range:

ex:hasPeriodStart
  rdf:type owl:DatatypeProperty ;
  rdfs:range xsd:dateTime ;

Or you might prefer to assure the quality of your data with SHACL, where you'll define your constraints with shape expressions.

I'd recommend not to define your time-related properties but to reuse those from the time ontology.

Upvotes: 5

Related Questions