Flylib.com

Books Software

 
 
 

3.4 Representing Structured Data with rdf:value


3.4 Representing Structured Data with rdf:value

Not all data relations in RDF represent straight binary connections between resource and object value. Some data values, such as measurement, have both a value and additional information that determines how you treat that value. In the following RDF/XML:

<pstcn:lastEdited>18</pstcn:lastEdited>

the statement is ambiguous because we don't know exactly what 18 means. Is it 18 days? Months? Hours? Did a person identified by the number 18 edit it?

To represent more structured data, you can include the additional information directly in the value:

<pstcn:lastEdited>18 days</pstcn:lastEdit>

However, this type of intelligent data then requires that systems know enough to split the value from its qualifier, and this goes beyond what should be required of RDF parsers and processors. Instead, you could define a second vocabulary element to capture the qualifier, such as:

<pstcn:lastEdited>18</pstcn:lastEdited>
<pstcn:lastEditedUnit>day</pstcn:lastEditedUnit>

This works, but unfortunately , there is a disconnect between the value and the unit because the two are only indirectly related based on their relationship with the resource. So the syntax is then refined, which is where rdf:value enters the picture. When dealing with structured data, the rdf:value predicate includes the actual value of the structure ”it provides a signal to the processor that the data itself is included in this field, and all other members of the structure are qualifiers and additional information about the structure.

Redefining the data would then result in:

<pstcn:lastEdited rdf:parseType="Resource">
    <rdf:value>18</rdf:value>
   <pstcn:lastEditedUnit>day</pstcn:lastEditedUnit>
</pstcn:lastEdited>

Now, not only do we know that we're dealing with structured data, we know what the actual value, the kernel of the data so to speak, is by the use of rdf:value . You could use your own predicate, but rdf:value is global in scope ”it crosses all RDF vocabularies ”making its use much more attractive if you're concerned about combining your vocabulary data with other data.


3.5 The rdf:type Property

One general piece of information that is consistent about an RDF resource ”outside of the URI to uniquely identify it ”is the resource or class type. In the examples shown thus far, this value could implicitly be "Web Resource" to refer to all of the resources, or could be explicitly set to "article" for articles. All these would be correct, depending on how generically you want to define the resource and the other properties associated with the resource. To explicitly define the resource type, you would use the RDF rdf:type property.

Usually the rdf:type property is associated at the same level of granularity as the other properties. As the resources defined using RDF in this chapter all have properties associated more specifically with an article than a web resource, the RDF type property would be "article" or something similar.

In the next section, covering RDF containers, we will learn that the resource type for an RDF container would be the type of container rather than the type of the contained property or resource. Again, the type is equivalent to the granularity of the resource being described, and with containers, the resource is a canister (or group ) of resources or properties rather than a specific resource or property.

The value of the RDF rdf:type property is a URI identifying an rdfs:Class -typed resource ( rdfs:Class is described in detail in Chapter 5). To demonstrate how to attach an explicit type to a resource, Example 3-13 shows the resource defined in the RDF/XML for Example 3-1, but this time explicitly defining an RDF Schema element for the resource.

Example 3-13. Demonstrating the explicit resource property type
<?xml version="1.0"?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:pstcn="http://burningbird.net/postcon/elements/1.0/">
  <rdf:Description rdf:about="http://burningbird.net/articles/monsters3.htm">
    <pstcn:Author>Shelley Powers</pstcn:Author>
    <pstcn:Title>Architeuthis Dux</pstcn:Title>

<rdf:type rdf:resource="http://burningbird.net/postcon/elements/1.0/Article" />

</rdf:Description>
</rdf:RDF>

The type property includes a resource reference for the schema element, in this case for the Article class.

Rather than formally list out an rdf:Description and then attach the rdf:type predicate to it, you can cut through all of that using an RDF/XML shortcut. Incorporating the formal syntax of the type property directly into XML, as before, the type property is treated as an embedded element of the outer resource.

Within the shortcut, the type property is created directly as the element type rather than as a generic RDF Description element. This new syntax, demonstrated in Example 3-14, leads to correct interpretation of the RDF within an XML parser.

Example 3-14. Abbreviated syntax version of type property
<?xml version="1.0"?>
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:pstcn="http://burningbird.net/postcon/elements/1.0/">

<pstcn:Article rdf:about="http://burningbird.net/articles/monsters3.htm">

<pstcn:Author>Shelley Powers</pstcn:Author>
    <pstcn:Title>Architeuthis Dux</pstcn:Title>

</pstcn:Article>

</rdf:RDF>

Notice the capitalization of the first letter for Article . This provides a hint that the element is a resource, rather than a predicate type.

This shortcut approach is particularly effective in ensuring that there is no doubt as to the nature of the resource being described, especially since formally listing an rdf:type predicate isn't a requirement of the RDF/XML. As you'll see later, in Chapter 6, the PostCon vocabulary uses this shortcut technique to identify the major resource as a web document.

Other RDF/XML shortcuts that can help cut through some of the rather stylized RDF/XML formalisms and make the underlying model a little more opaque are described in the next section.

An RDF resource can have more than one rdf:type associated with it.