Semantic Web for the Working Ontologist. Dean Allemang

Читать онлайн книгу.

Semantic Web for the Working Ontologist - Dean  Allemang


Скачать книгу
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].

Image

      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:

Image

      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

Image

      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.

      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:

Image

      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:

Image

      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:

Image

      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:

Image

      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 information in RDF

      The children of Shakespeare appear in a certain order on the printed page, but from the point of view of RDF, they are in no order at all; there are just three triples, one describing the relationship between Shakespeare and each of his children. What if we do want to specify an ordering. How would we do it in RDF?

      RDF provides a facility for ordering elements in a list format. An ordered list can be expressed quite easily in Turtle as follows:

Image

      This translates into the following triples, where _:a, _:b, and _:c are bnodes, and the order is indicated using two reserved properties in RDF called rdf:first and rdf:rest. The list is terminated with a reference to the resource rdf:nil:

Image Image

      This rendition preserves the ordering of the objects but at a cost of considerable complexity of representation. Fortunately, the Turtle representation is quite compact, so it is not usually necessary to remember the details of the RDF triples behind it.

       N-Quads

      So far, we have talked about how to serialize triples. But what if we want to serialize triples in the context of one or more named graphs? The W3C provides simple extensions


Скачать книгу