rdfturtle-rdf

Text Representation of RDF with turtle


I want to make a textual representations of an RDF graph with Turtle. As an example the relation between Spiderman and the Green Goblin. See the reference here https://www.w3.org/TR/turtle/

@base <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rel: <http://www.perceive.net/schemas/relationship/> 

<#green-goblin>
    rel:enemyOf <#spiderman> ;
    a foaf:Person ;    # in the context of the Marvel universe
    foaf:name "Green Goblin" .
<#spiderman>
    rel:enemyOf <#green-goblin> ;
    a foaf:Person ;
    foaf:name "Spiderman", "Человек-паук"@ru .

What does the comma (,) mean between "Spiderman" and the Russian word?

Another more important question is: how can I do that with a city and a country over time? For example: Leipzig belonged to the DDR until 1990. Today Leipzig is a city in Germany.


Solution

  • Seems like two very separate questions here. One on syntax and one on modeling.

    For the syntax problem I'd suggest looking at Turtle - Terse RDF Triple Language. Turtle specifies triples, which requires three entities in the specification of a triple. The . specifies the end of a triple. As a shortcut, a ; means the current subject is carried over to the next triple specification - hence only the predicate and object need to be specified. A , means the subject and predicate are carried over to the next triple. Therefore,

    <#spiderman> foaf:name "Spiderman", "Человек-паук"@ru .
    

    Specifies two triples:

    <#spiderman> foaf:name "Spiderman" .
    <#spiderman> foaf:name "Человек-паук"@ru .
    

    One the modeling question, to specify the different nationalizations of Leipzig at different epochs of time, specify a property, such as isMemberOfCountry that has properties of fromDate and toDate. Each instance of country membership would then be populated:

    @prefix ex: <http://example.org/geoex/> 
    ex:Leipzig
      ex:isMemberOfCountry [
          ex:country ex:DDR ;
          ex:fromDate 1945 ;
          ex:toDate 1990 ;
        ] ;
      ex:isMemberOfCountry [
          ex:country ex:Germany ;
          ex:fromDate 1990 ;
        ] .
    

    Bnodes are used ensure unique names across the dataset for an object whose name may not matter (if it does, then specify an object a use in place of the bnode). Then to query the current country, use:

    SELECT ?country
    WHERE {
       ex:Leipzig ex:isMemberOfCountry ?member .
       ?member ex:country ?country .
       FILTER NOT EXISTS {
          ?member ex:toDate ?d
       }
    }
    

    And to find the membership during a specific year, use the following:

    SELECT ?country
    WHERE {
     BIND("1991"^^xsd:integer AS ?date) #placeholder - ?date should be passed into the query
        ex:Leipzig ex:isMemberOfCountry ?member .
        ?member ex:country ?country .
        ?member ex:fromDate ?fdate .
        OPTIONAL {?member ex:toDate ?td}
        BIND(IF(bound(?td), ?td, year(now())) AS ?edate)
        FILTER (?date >= ?fdate && ?date <= ?edate)
    }
    

    Note that binding ?date to 1990 will result in two results, which is correct given that years are used instead of dates in this example model.