Skip to content

Instantly share code, notes, and snippets.

@tomasklapka
Last active August 29, 2015 14:09
Show Gist options
  • Save tomasklapka/d3bb098946efe7f3e67a to your computer and use it in GitHub Desktop.
Save tomasklapka/d3bb098946efe7f3e67a to your computer and use it in GitHub Desktop.
GAPI RDF ORM example
rdf = require('../..')
ORM = rdf.ORM
ORM.waitForLoad () ->
person = ORM.newResource('http://example.com/john#me', 'foaf', 'Person')
person.foaf.name = 'John Doe'
person.foaf.homepage = 'http://example.com/john/blog'
person.rdfs.label = 'john\'s label'
otherone = ORM.newResource('http://example.com/jane#me', 'foaf', 'Person')
otherone.foaf.name = 'Jane Doe'
otherone.foaf.homepage = 'http://example.com/jane/blog'
otherone.rdfs.label = 'jane\'s label'
anotherone = ORM.newResource('http://example.com/jack#me', 'foaf', 'Person')
person.foaf.knows = otherone
otherone.foaf.knows = person
person.foaf.knows = anotherone
console.log person.toString()
console.log otherone.toString()
console.log anotherone.toString()
console.log "John knows "+person.foaf.knows
console.log "Jane knows "+otherone.foaf.knows
console.log "Jack knows "+(anotherone.foaf.knows || 'no one')
###
Outputs:
<http://example.com/john#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "http://xmlns.com/foaf/0.1/Person" .
<http://example.com/john#me> <http://xmlns.com/foaf/0.1/name> "John Doe" .
<http://example.com/john#me> <http://xmlns.com/foaf/0.1/homepage> "http://example.com/john/blog" .
<http://example.com/john#me> <http://www.w3.org/2000/01/rdf-schema#label> "john's label" .
<http://example.com/john#me> <http://xmlns.com/foaf/0.1/knows> <http://example.com/jane#me> .
<http://example.com/john#me> <http://xmlns.com/foaf/0.1/knows> <http://example.com/jack#me> .
<http://example.com/jane#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "http://xmlns.com/foaf/0.1/Person" .
<http://example.com/jane#me> <http://xmlns.com/foaf/0.1/name> "Jane Doe" .
<http://example.com/jane#me> <http://xmlns.com/foaf/0.1/homepage> "http://example.com/jane/blog" .
<http://example.com/jane#me> <http://www.w3.org/2000/01/rdf-schema#label> "jane's label" .
<http://example.com/jane#me> <http://xmlns.com/foaf/0.1/knows> <http://example.com/john#me> .
<http://example.com/jack#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "http://xmlns.com/foaf/0.1/Person" .
John knows http://example.com/jane#me,http://example.com/jack#me
Jane knows http://example.com/john#me
Jack knows no one
###
@tomasklapka
Copy link
Author

TODO:

  • better assignment typing (currently works only assigning of other resource. otherwise it assigns literal of object's toString())
  • domain/range, cardinality and type constraining
  • binding resource to a store with auto-storing when the resource is updated
  • blank nodes
  • allow colon notation for namespace_alias:name (foaf:name, rdf:type)
  • instantiate Resource from provided graph
  • resource lazy loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment