- From: Peter Frederick Patel-Schneider <pfps@research.bell-labs.com>
- Date: Fri, 25 Mar 2011 12:30:42 -0400
- To: <david.wood@talis.com>
- CC: <public-rdf-wg@w3.org>
From: David Wood <david.wood@talis.com> Subject: Re: What *is* RDF? Date: Fri, 25 Mar 2011 10:00:27 -0500 [...] > It would be helpful to focus this discussion on whether we can create a > subject-oriented nested dictionary with simple keys that represents (a > useful subset of) RDF. > > Regards, > Dave How about the following? Serializing RDF into JSON - inputs - G - an RDF graph, to be serialized - B - an IRI, to be treated as the base IRI - requirements - all blank nodes have universally unique nodeIDs - not handled - ill-formed (i.e., non tree-like) RDF collections - RDF collection nodes with extra outgoing edges - not covered - details of serializing IRIs Create a JSON array A with values as given below For each node N in G that is the subject of some triple in G and is not a structural collection node create a JSON object N''' as follows The first member of N''' is "sameAs" : N' Let NS be the triples in G that have N as their subject For each node P in G that is a predicate in NS Let NSP be the triples in NS with predicate P For each triple in NSP (with the most important last, if desired) Let O be the object of the triple The next member of N''' is "S'" : O'' Make N''' the next value of A For each orphan RDF collection (i.e., one with no-incoming edges) with elements E1,...,En Make [ E1'', ..., En'' ] the next member of A Turning an IRI or nodeID I into its JSON form I' NB: This is missing any fixes needed for character encoding issues, etc. - if I is a nodeID then I' is I - if I is rdf:type then I' is type - if I is owl:sameAs then I' is sameAs - otherwise if I can be (easily?) made relative to B then I' is that relative IRI - otherwise I' is I Turning an RDF node N into N'' - if N is a structural collection node with elements E1,...,En [ E1'', ..., En'' ] - if N is an IRI { "sameAs" : "N'" } - if N is a blank node with B as its nodeID { "sameAs" : "B" } - if N is a plain literal, with or without a langauge tag "N" - if N is a typed literal "V"^^T that is one of the other JSON values V - if N is some other typed literal "V"^^T "V" Shorthand forms are possible by rolling up non-collection nodes into the object for another node, i.e., instead of using O'' use O'''. This is done already for collections (even at the expense of duplicating them). Parsing JSON into RDF - inputs - J - a JSON text, as in RFC 4627 - B - a base IRI - output - G - an RDF graph First parse the JSON text as described in RFC 4627 If it is a JSON object process it as below If it is a JSON array then process each of its values as below The processing of a JSON value V returns a node V' and may add triples to G If V is false then V' is "false"^^xsd:boolean If V is true then V' is "true"^^xsd:boolean If V is null then V' is "null"^^xsd:string If V is a number then V' is V^^xsd:decimal If V is a string then V' is V^^xsd:string If V is an array containing values V1,...,Vn then - process each of the Vi - emit triples for a collection whose structural nodes are all fresh blank nodes and that has elements V1',...,Vn' - V' is the head node of this collection If V is an object with members "S1":V1, ..., "Sn":Vn then - V' is a fresh blank node - process each Vi - emit a triple for each "Si":Vi with subject V', predicate Si'', and object Vi'' if Vi is a string and Si is either type or sameAs, Vi' otherwise Turning a JSON string "S" into an IRI S'' is done as follows NB: This is missing any fixes needed for character encoding issues, etc. NB: This is missing a firm definition of "looks like" - if S is type then S'' is rdf:type - if S is sameAs then S'' owl:sameAs - otherwise if S looks like a relative IRI then S'' is S resolved against B - otherwise S'' is Si fixed up to be an IRI Exercises for the Reader - Where does this break? - What prejudices are embodied herein? - How can a base URI be correctly folded into the JSON serialization?
Received on Friday, 25 March 2011 16:31:23 UTC