RdfDataStructures

From W3C Wiki

Rationale

The idea is to use RDF to describe arbritrary data structures as used by common programming languages like Perl, Python, Ruby, PHP, etc. If we can serialize those data structures (or arbitrary objects) as RDF, then all the power of RDF is available for searching those data structures. For example, a little pseudocode:


alice   = new Person("Alice")
bob     = new Person("Robert")
charlie = new Person("Charles")

team = new Group()
team.has_member(alice)
team.has_member(bob)
team.has_member(charlie)

store_as_rdf(alice, bob, charlie, team)


Then later on, after those objects/data-structures have been destroyed, one could do something like


people_on_team_with_alice = retrieve_from_rdf( ... fancy SPARQL ... )


to fill people_on_team_with_alice with objects representing Bob and Charlie. Such a system would eliminate the Object-Relational mapping done in so many object-oriented programs. It would be nice if the RDF vocabularly were designed so that data structure could be used by several programming languages. I could persist a hash in Perl and restore it as a dictionary in Python. In that sense it's similar to cross-language serialization formats like YAML and JSON.

Example: Representing Objects

Here's a sample based on the pseudocode above. The RDF serialization might be something like this


# Nothing here yet
@prefix dt: <http://www.dajobe.org/2006/01/rdf-dt/schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

_:b0 a dt:Object ;
   dt:perlClassName "Group" ;
   dt:attr [ dt:name "members"; dt:value _:b1 ] .

_:b1 a dt:Array ;
   a rdf:Seq    ;
   rdf:_1 _:b2  ;
   rdf:_2 _:b3  ;
   rdf:_3 _:b4  .

_:b2 a dt:Object ;
  dt:perlClassName "Person" ;
  dt:attr [ dt:name "name"; dt:value "Alice" ] .

_:b3 a dt:Object ;
  dt:perlClassName "Person" ;
  dt:attr [ dt:name "name"; dt:value "Robert" ] .

_:b4 a dt:Object ;
  dt:perlClassName "Person" ;
  dt:attr [ dt:name "name"; dt:value "Charles" ] .


To get the objects representing people on a team with Alice, one could feed the following SPARQL to the mythical retrieve_from_rdf function


PREFIX dt: <http://www.dajobe.org/2006/01/rdf-dt/schema#>

SELECT ?associate
WHERE {
  # Find Alice
  ?alice dt:perlClassName "Person" ;
         dt:attr          [ dt:name "name"; dt:value "Alice" ] .

  # Find a list of team members containing Alice
  ?team ?li_prop1 ?alice ;
        ?li_prop2 ?associate .

  # we don't want Alice to be her own associate
  FILTER ( ?associate != ?alice ) .

  # Check we just get the ?associate that are Persons
  ?associate a                dt:Object ;
             dt:perlClassName "Person"
}


Representing Hash Tables as a Collection of Tuples

From dajobe's example:



@prefix dt: <http://www.dajobe.org/2006/01/rdf-dt/schema#> .
@prefix : <http://www.dajobe.org/2006/01/rdf-dt/example#> .

:team a dt:Hash ;
   dt:hasMember [ dt:key "Alice";   dt:value :alice ] ;
   dt:hasMember [ dt:key "Robert";  dt:value :bob ] ;
   dt:hasMember [ dt:key "Charles"; dt:value :charlie ] .

:alice a dt:Object ;
  dt:perlClassName "Person" .

:bob a dt:Object ;
  dt:perlClassName "Person" .

:charlie a dt:Object ;
  dt:perlClassName "Person" .


Example SPARQL query:


PREFIX dt: <http://www.dajobe.org/2006/01/rdf-dt/schema#>
PREFIX : <http://www.dajobe.org/2006/01/rdf-dt/example#>

SELECT ?team
WHERE {
  ?team dt:hasMember [ dt:key "Alice";   dt:value :alice ] .
}


Comments

See also Sparta, a similar approach in Python -- MarkNottingham

Sparta seems to do the inverse of this (very cool by the way). Namely, if you have some RDF, Sparta lets you manipulate it in Python. The idea here is that you already have Python (Perl, Ruby) objects and want to use RDF to store, search and retrieve them. -- MichaelHendricks

Java Properties in RDF

Long time ago in a distant galaxy I did an RDF-based (Jena) replacement for Java Properties (grouped key/value pairs, backed by file persistence), to which I'd added hierarchical nesting. Called them "feature sets". Worked acceptably. Basic structure like this:

  <ftrs:FeatureSet rdf:about="http://ideagraph.org/xmlns/ideagraph/default/windows">
    <ftrs:subSet>
      <ftrs:FeatureSet rdf:about="http://ideagraph.org/xmlns/ideagraph/default/windows/treeWindow">
        <rdf:li
           rdf:type="http://ideagraph.org/xmlns/idea/features#Feature"
           ftrs:value="no"
           ftrs:type="Boolean"
           ftrs:key="isVisible"/>
        <rdf:li
 	   ...

I think there were outstanding bugs for nesting, but straight properties worked ok. Appears to be some GUI code there for a properties editor there too - can't remember that at all... sample data, source (may be missing dependencies, I want to de-cruft before bulk-uploading, ping me if wanted). -- DannyAyers

You may find somewhat helpful things in linq - ChoiHeeChul