Semantic Web for the Working Ontologist. Dean Allemang
Чтение книги онлайн.
Читать онлайн книгу Semantic Web for the Working Ontologist - Dean Allemang страница 25
Turtle provides some abbreviations to improve terseness and readability; in this book, we use just a few of these. One of the most widely used abbreviations is to use the word a to mean rdf:type. The motivation for this is that in common speech, we are likely to say, “Product1 is a Product” or “Shakespeare is a playwright” for the triples,
respectively. Thus we will usually write instead:
RDF/XML
While Turtle is convenient for human consumption and is more compact for the printed page, many Web infrastructures are accustomed to representing information in HTML or, more generally, XML. For this reason, the W3C historically started by recommending the use of an XML serialization of RDF called RDF/XML. The information about Product1
and Product2
just shown looks as follows in RDF/XML.
In this example, the subjects (Product1
and Product2
) are referenced using the XML attribute rdf:about
; the triples with each of these as subjects appear as subelements within these definitions. The complete details of the RDF/XML syntax are beyond the scope of this discussion and can be found in the W3C Recommendation [Schreiber and Gandon 2014].
The same information is contained in the RDF/XML form as in the Turtle, including the declarations of the CURIEs for mfg: and rdf:. RDF/XML includes a number of rules for determining the fully qualified URI of a resource mentioned in an RDF/XML document. These details are quite involved and will not be used for the examples in this book.
JSON-LD
A more modern way to pass data from one component to another in a Web application is using JSON, the Javascript Object Notation citebray2014javascript. In order to make linked data in RDF more available to applications that use JSON, the W3C has recommended JSON-LD, JSON for Linked Data [Kellogg et al. 2014]. There is a direct correspondence between JSON-LD and RDF triples, making JSON-LD another serialization format for RDF.
One of the motivations for having a JSON-based serialization for RDF is that developers who are accustomed to JSON but are not familiar with graph data or distributed data can build applications purely in JSON, which are nevertheless compatible with linked data.
The information about Product1
and Product2
looks as follows in JSON-LD:
The document is organized as a @graph
and a @context
; the context is like the prefix declarations in Turtle, in that it defines namespaces abbreviations and their expansions. The graph section describes the data, organizing it into object structures as much as possible. Each object has an @id
, which defines the URI of the resource (in triple terms, the subject of each triple). The rest of the object structure is in the same form as a JSON object, with the fields corresponding to predicates and the values corresponding to objects.
Optionally, each object can have a @type
declaration, which corresponds to the rdf:type
predicate in triples. In this case, the value is expected to be another resource, and is interpreted as such.
JSON-LD has a provision for referring to other objects as well, by using a JSON Object syntax, specifying the identity of a referred object with @id
. So, if we were to say that Product1
is a part of Product2
, we could say
JSON-LD provides a valuable way to exchange graph data from one application to another, while staying entirely in a conventional Javascript environment. Its consistency with RDF allows these applications to smoothly integrate into a web of distributed data.
3.9 Blank Nodes
So far, we have described how RDF can represent sets of triples, in which each subject, predicate, and object is either a source or (in the case of the object of a triple) a literal data value. Each resource is given an identity according to the Web standard for identity, the URI. RDF also allows for resources that do not have any Web identity at all. But why would we want to represent a resource that has no identity on the Web?
Sometimes we know that something exists, and we even know some things about it, but we don’t know its identity. For instance, suppose we want to represent the conjecture that Shakespeare had a mistress, whose identity remains unknown. But we know a few things about her; she was a woman, she lived in England, and she was the inspiration for Sonnet 78.
It is simple enough to express these statements in RDF, but we need an identifier for the mistress. In Turtle, we could express them as follows:
But if we don’t want to have an identifier for the mistress, how can we proceed? RDF allows for a blank node, or bnode for short, for such a situation. If we were to indicate a bnode with a ?, the triples would look as follows:
The use of the bnode in RDF can essentially be interpreted as a logical statement, “there exists.” That is, in these statements we assert “there exists a woman, who lived in England, who was the inspiration for ‘Sonnet78’.”
But this notation (which does not constitute a valid Turtle expression) has a problem: If there is more than one blank node, how do we know which ?
references which node? For this reason, Turtle instead includes a compact and unambiguous notation for describing blank nodes. A blank node is indicated by putting all the triples of which it is a subject between square brackets ([ and ]), so:
It is customary, though not required, to leave blank space after the opening bracket to indicate that we are acting as if there were a subject for these triples, even though none is specified.
We can refer to this blank node in other triples by including the entire bracketed sequence in place of the blank node. Furthermore, the abbreviation of a
for rdf:type
is particularly useful in this context. Thus, our entire statement about the mistress who inspired “Sonnet 78” looks as follows in Turtle:
This expression of RDF can be read almost directly as plain English: that is, “Sonnet78 has [as] inspiration a Woman [who] lived in England.” The identity of the woman is indeterminate. The use of the bracket notation for blank nodes will become particularly important when we come to describe OWL, the Web Ontology Language, since it makes very particular use of bnodes. While RDF allows for the use of blank nodes in many circumstances, other than the specific use of blank nodes in OWL, their use is discouraged in general.
Ordered