2008-06-18
| Table of Contents: |
| Rate This Article: | Add This Article To: |
( Page 2 of 2 )
Developing a Data Model
RDF begins with a data model that looks remarkably similar to the schema used by databases. As with many modern technologies, RDF doesn’t break entirely new ground, but uses the technology that has come before to build something new. An RDF data model consists of three parts: the description of resources used to create the model, a class, and the elements that make up that class. You can see a relatively simple data model in Listing 1.
Listing 1: Defining an RDF Data Model
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix daml: <http://www.daml.org/2001/03/daml+oil#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsdt: <http://www.w3.org/2001/
@prefix : <http://aabs.purl.org/ontologies/2007/04/Contacts#> .
:Person a owl:Class.
:title rdfs:domain :Person; rdfs:range xsdt:string.
:name rdfs:domain :Person; rdfs:range xsdt:string.
:address1 rdfs:domain :Person; rdfs:range xsdt:string.
:address2 rdfs:domain :Person; rdfs:range xsdt:string.
:city rdfs:domain :Person; rdfs:range xsdt:string.
:state rdfs:domain :Person; rdfs:range xsdt:string.
:zip rdfs:domain :Person; rdfs:range xsdt:string.
:telephone rdfs:domain :Person; rdfs:range xsdt:string.
In some respects, this code looks like a human readable form of an
The last namespace entry is special. It defines the namespace used for the data model. The name of this data model is Contacts because it defines the entries for a contacts database. Make sure you pay close attention to formatting when you create your own data model. For example, every entry must end with a period or else RDF won’t know that the entry has ended.
The data model itself begins with a Web Ontology Language (OWL) class. Yes, I know that the acronym doesn’t match the order of the words, but that’s how the standard has things arranged. OWL provides a vocabulary for RDF—the technique you use to create the structure of an RDF file. You can learn more about OWL at http://www.w3.org/TR/owl-ref/. For this example, every record in the Contacts database is a Person class.
The Person class contains a number of data fields. A data field begins with the name of the field. For example, every record has a title field. This is the predicate of the triple. Notice that there’s an rdfs:domain :Person entry that comes next. This is the subject of the triple. Finally, there’s the rdfs:range xsdt:string entry, which is the object of the triple. If you were to read this as plain English, it would say, “A person has a title of type string.” Of course, you replace the string type with some value such as Dr. Consequently, the true English statement is, “A person has a title which is Dr.” The example also has data fields for name, address1, address2, city, state, zip, and telephone.
Creating Data Based on the Model
At this point, you have a data model, but no data. Listing 2 remedies that problem. This database contains only two records. A real database would contain far more, but two records are sufficient for the example program I’ll present in the next article.
Listing 2: Creating a Data Source Based on the RDF Data Model
@prefix ns1: <http://aabs.purl.org/ontologies/2007/04/Contacts#> .
ns1:Person_001 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ns1:Person ;
ns1:title "Mr." ;
ns1:name "George Smith" ;
ns1:address1 "1313 Mockingbird Lane" ;
ns1:address2 "Suite 22B" ;
ns1:city "Somewhere" ;
ns1:state "CA" ;
ns1:zip "99999-1234" ;
ns1:telephone "(999)555-1212" .
ns1:Person_002 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ns1:Person ;
ns1:title "Ms." ;
ns1:name "Anna McPherson" ;
ns1:address1 "921 Donnelly Road" ;
ns1:address2 "" ;
ns1:city "Somewhere" ;
ns1:state "CA" ;
ns1:zip "99999-2212" ;
ns1:telephone "(999)555-1234" .
The code begins with the namespace used for the data. In this case, there’s only one and it points to the Contacts namespace. Data files usually have only one namespace because they always rely on a data model that defines all of the other required namespaces.
The next entry is a record, which begins with the namespace definition, ns1. Every entry begins with a unique designator. In this case, we have Person_001 and Person_002. The rest of that first line says that the record is of the type Person. That’s the class defined in the data model.
After you define the unique designator and the class type, you begin adding fields to the record. You see one entry for each field. Notice how each of these entries ends with a semicolon (;), rather than a period. Only at the end of the record do you see a period. Consider each of the field entries as a clause that defines an entire record. Each clause in a human readable sentence ends with a semicolon, and so does an RDF file.
Bottom Line
RDF isn’t for every kind of data and it won’t be easy for every developer to learn. The difference in the way that RDF models data will be difficult for some developers to grasp immediately because most developers are used to working with objects. However, RDF does give you an incredibly valuable tool in modeling data using a different approach. It helps solve some problems that don’t work well with objects. If you find RDF interesting and want to learn more about it, one of the best places to look is the RDF primer at http://www.w3.org/TR/REC-rdf-syntax/. If this first tutorial doesn’t meet your needs, check out the W3C Schools tutorial at http://www.w3schools.com/rdf/default.asp.
BIO
John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 80 books and over 300 articles to date. The topics range from networking to artificial intelligence and from database management to heads down programming. His current project is LINQ for Dummies (scheduled for publication in August 2008), which you can preorder at http://www.amazon.com/exec/obidos/ASIN/0470277947/datacservip0f-20/. His technical editing skills have helped over 56 authors refine the content of their manuscripts. You can reach John on the Internet at JMueller@mwt.net and his Web site at: http://www.mwt.net/~jmueller/.
![]() |
|


