![]() |
rdf: back-end architecture$Id: back-end-architecture.html,v 1.9 1999/08/14 00:22:54 waterson%netscape.com Exp $ This document provides an overview of the RDF "core" implementation, that is, the implementation of the RDF model within Mozilla. It assumes some familiarity with the RDF model as described in the RDF Model and Syntax Specification. See also the Datasource HOWTO for details on writing a datasource. Model and Terminology
The Mozilla implementation of the RDF model is based on the RDF Model and Syntax Specification. This section attempts to provide a pseudo-mathematical overview of that model [1]. Although there are slight differences between the Mozilla RDF model and the model presented in the RDF Model and Syntax Specification, the belief is that, for all practical purposes, these differences should not affect the use of the RDF model. Any differences that lead to behavior that is functionally incorrect with respect to the Model and Syntax Specification should be logged as a bug (select RDF as the "Component"). The Mozilla RDF "universe" consists of: Resources. Because the function that maps a resource to a URI is one-to-one, it is possible to identify each resource using its URI. That is, given a URI, it is possible to find a unique resource in R. [2] Informally, a resource is some sort of "Internet object" that is uniquely identifiable; for example, a web page, an email account, or a USENET news article. We realize that the one-to-one mapping of a resource to a URI does not adhere to the spirit of RFC2396. Specifically, RFC2396 states that a resource might have many different names; e.g., a web page that can be reached by redirection. We've chosen to enforce the one-to-one mapping in our model for efficiency's sake. (It would clearly be inefficient to contact a web server to resolve each HTTP URI for fear that it might be redirected!) That said, we do perform simple canoncialization for some URIs; for example "." and ".." resolution in HTTP and filesystem URIs. The RDF Model and Syntax specification explicitly allows for anonymous resources. An anonymous resource is a resource without URI-addressable identity. The Mozilla implementation allows for such resources (e.g., in serialized RDF/XML), but will automatically assign a uniquely generated URI to such a resource. Literals. As with resources, the function that maps a literal to a string value is one-to-one. Hence, it is possible to identify each literal using its string value. The RDF Model and Syntax Specification explicitly states that the mapping from literal to string value need not be one-to-one; we've chosen to make the mapping one-to-one to allow for efficient comparison of literals. Informally, a literal is a primitive value that has no "first-class identity"; for example, a string, a date, or a number. Statements. A statement consists of a subject, a predicate, and an object. The subject must be a resource. The predicate must be a resource (strictly speaking, the predicate must be a resource that is a property; however, we do not differentiate between a resource that is a property and a resource that is not a property in the Mozilla implementation). The object may be either a resource or a literal. The terms statement and assertion are interchangeable. The Mozilla RDF implementation factors the set of statements S into subsets. Each subset of statements is called a datasource. For example, there is a datasource that contains statements about mail messages and news articles; there is a datasource that contains statements about the current user's browsing history; there is a datasource that contains statements about the current user's bookmarks. Each datasource may be addressed individually. It is possible to query a datasource to determine whether a statement is present. Statements may be added to, removed from, or altered in a datasource. The implementation allows datasources to be addressed collectively. That is, the statements from several different datasources may be combined into a composite datasource, in which they may be queried or altered "in the aggregate". A set of statements may be visualized as a directed, labelled graph, and much of the Mozilla RDF API is crafted with this visualization in mind. Specifically, the subject of each statement is a node (the source), the object of the statement is a node (the target), and the predicate is a directed arc from the subject node to the object node. In this parlance, a datasource -- which is simply a colletion of statements -- is a (possibly unconnected) graph. A composite datasource is the graph that is constructed by overlaying the subgraphs of several individual datasources. Reification. The RDF Model and Syntax Specification discusses how a statement may itself be "reified", and referred to as a resource. As of this writing, the Mozilla RDF model does not support automatic derivation of "meta statements" that arise from such reification. InterfacesBelow are the primary interfaces that are used to interact with RDF.
Example
This section provides some sample code that uses JavaScript and XPConnect to interact with the RDF engine, including: The code below illustrates this process. You can click here to run the code in an M9 or later build.
Acquire the RDF service. To acquire the RDF service, use the
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService(); RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
Create a datasource. Using the
var ds = Components.
classes['component://netscape/rdf/datasource?name=in-memory-datasource'].
createInstance();
ds = ds.QueryInterface(Components.interfaces.nsIRDFDataSource);
Acquire RDF nodes. Using the RDF service, you can acquire individual RDF resource and literal objects. These are what you use to perform a query on the RDF database.
var homepage = RDF.GetResource('http://people.netscape.com/waterson');
var FV_quality = RDF.GetResource('urn:my-web-vocabulary:quality');
var value = RDF.GetLiteral('tres cool');
Use the RDF nodes to add statements to the datasource. And
finally, we "do the deed" using the ds.Assert(homepage, FV_quality, value, true); Query the datasource. Now that we've added a statement to the datasource, we can query it to see if it's really there:
if (ds.HasAssertion(homepage, FV_quality, value, true)) {
alert('yep, it sure worked.');
}
We can pull a "target" value out given the source and a property:
var target = ds.GetTarget(homepage, FV_quality, true);
target = target.QueryInterface(Components.classes.nsIRDFLiteral);
// expect 'tres cool'
alert('target is ' + target.Value + '!');
Or the "source", given a property and a target:
var source = ds.GetSource(FV_quality, value, true);
sourcen = source.QueryInterface(Components.classes.nsIRDFResource);
// expect 'http://people.netscape.com/waterson'
alert('source is ' + source.Value + '!');
AcknowledgementsDan Brickley (daniel.brickley@bristol.ac.uk) and David McCusker (davidmc@netscape.com) both provided valuable inspiration and feedback. Notes
|
|
|
Copyright © 1998-1999 The Mozilla Organization.
Last modified August 14, 1999. |
|