Last active
August 29, 2015 14:09
-
-
Save tomasklapka/d3bb098946efe7f3e67a to your computer and use it in GitHub Desktop.
GAPI RDF ORM example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: