Rules-based Resource Property Sets in RDF


Table of Contents

Introduction
Namespace Prefixes
Rule and Property Set Vocabulary
Class: Ruleset
Class: rule:Rule
Class: rule:AllOf
Class: rule:OneOf
Class: rule:PropertySet
Property: rule:hostRestriction
Property: rule:rules
Property: rule:confers
Processing a Ruleset
URI String Matching Rules
Class: uri:Matches
Property: uri:value
Examples

Introduction

This document describes a method for creating and processing an RDF graph which defines collections of properties to be assigned to resources where the resources are identified by pattern matching rules rather than being directly specified.

The first part of this document describes the vocabulary for defining pattern matching rules and associating a collection of properties with a pattern matching rule. The second part of the document describes the processing algorithm by which a URI is matched against one of a set of rules and the property set associated with that rule is conferred on the resource identified by the matching URI. The third part presents rules for matching a resource based on the resource URI string. The final part presents some worked examples.

Namespace Prefixes

In the rest of this document the namespaces for various RDF vocabularies are referred to using standard namespace prefixes. The table below shows the mapping of prefixes to namespace URIs.

Table 1. Namespace Prefixes Used In This Document

PrefixNamespace URI
rdf 
rulehttp://www.w3.org/2004/12/q/rules#
urihttp://www.w3.org/2004/12/q/uri-rules#
xsdhttp://www.w3.org/2001/XMLSchema

Rule and Property Set Vocabulary

The base URI for this vocabulary is http://www.w3.org/2004/12/q/rules#.

Class: Ruleset

The class rule:Ruleset is a specialization of rdf:List which allows only rule:Rule instances as list members.

Class: rule:Rule

The class rule:Rule is the base class for resource matching rules.

Class: rule:AllOf

The class rule:AllOf is derived from both rdf:Bag and rule:Rule. This rule matches a resource if all of the rdf:Rule instances contained in the rdf:Bag match the resource.

When processing the contained rules for matching purposes, any rule:confers property on contained rule:Rule instances must be ignored.

Class: rule:OneOf

The class rule:OneOf is derived from both rdf:Bag and rule:Rule. This rule matches a resource if at least one of the rdf:Rule instances contained in the rdf:Bag match the resource.

When processing the contained rules for matching purposes, any rule:confers property on contained rule:Rule instances must be ignored.

Class: rule:PropertySet

An instance of the class rule:PropertySet acts as a "placeholder" resource for any resource which matches a given rule:Rule.

Property: rule:hostRestriction

This property has a domain of rule:Ruleset and a range of rdf:Literal. The value of this property specifies the host to which the contained rules are restricted. The host of an input URI must match at least one of the values of the rule:hostRestriction properties of a rule:Ruleset. Subdomains are included, so, for example, of the hostRestriction is example.org then the Ruleset is also valid for subdomain.example.org.

Property: rule:rules

This property has a domain of rule:Ruleset and a range of rule:Rule. An absolute ordering for rules may be specified using either the rdf:first and rdf:rest properties or by using the rdf:parseType="Collection" attribute.

Property: rule:confers

This property has a domain of rule:Rule and a range of rule:PropertySet. It specifies that when a URI matches the rule:Rule instance, then all of the properties of the rule:PropertySet instance must be conferred on the matching URI.

Note

The rule:AllOf and rule:OneOf allow rule:Rule instances to be nested within one another. However, for the purposes of conferring properties, only the rule:confers property of the outermost rule:Rule instance will be considered in the property conference algorithm.

Processing a Ruleset

This section describes the algorithm for processing a given URI against a rule:RuleSet to confer properties on the resource identified by the URI.

Let the input to the algorithm consist of an RDF graph I, and an input URI U. The goal is to produce an output graph O which contains a set of RDF statements about the resource U.

URI String Matching Rules

This section presents a set of basic rules for matching a resource based on the URI string of the resource. All of the classes presented in this section are subclasses of rule:Rule.

Class: uri:Matches

This rule matches a resource if the resource URI string matches the Perl5 regular expression that is the value of the uri:value property of the rule.

Property: uri:value

This property has a domain of uri:Matches and a range of xsd:string. The value of the property provides the argument for the uri:Matches rule that is the property subject.

Examples

Example 1. A Simple Domain Match

Given the rule set:

	<rule:Ruleset rdf:parseType="rdf:List" 
		      xmlns:rule="http://www.w3.org/2004/12/q/rules#"
		      xmlns:uri="http://www.w3.org/2004/12/q/uri-rules#"
		      xmlns:label="http://www.w3.org/2004/12/q/contentlabel#"
		      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	  <rule:hostRestriction>example.com</rule:hostRestriction>
	  <rule:rules>
	    <uri:Matches>
	      <uri:value>http://www.example.com/.*</uri:value>
	      <rule:confers>
	        <rule:PropertySet>
		  <label:hasContentLabel rdf:resource="http://www.example.com/labels.rdf#all-ages">
                </rule:PropertySet>
	      </rule:confers>
	    </uri:Matches>
	    <uri:Matches>
	      <uri:value>.*</uri:value>
	      <rule:confers>
                <rule:PropertySet>
  	          <label:hasContentLabel>
		    <label:ContentLabel rdf:about="http://www.example.com/labels.rdf#default"/>
		  </label:hasContentLabel>
                </rule:PropertySet>
	      </rule:confers>
	    </uri:Matches>
	  </rule:rules>
	</rule:Ruleset>
      

The input URI "http://www.example.com/foo.html" would be processed as follows:

  1. The host of the URL, www.example.com, is a valid subdomain of the host restriction for this rule set, so processing may continue.

  2. The URL matches the first uri:Matches rule by matching the regular expression http://www.example.com/.*, so a subgraph is extracted from the value of the rule:confers property. In the extracted graph, the rule:PropertySet resource is replaced by the resource URL passed in to the evaluation process, giving the result graph:

    <rdf:Description rdf:about="http://www.example.com/foo.html">
      <label:hasContentLabel rdf:resource="http://www.example.com/labels.rdf#all-ages"/>
     </rdf:Description>
    	  

The input URI "http://adult.example.com/" would be processed as follows:

  1. The host of the URL, adult.example.com, is a valid subdomain of the domain restriction for this rule set, so processing may continue.

  2. The URL does not match the first uri:Matches rule.

  3. The URL matches the second uri:Matches rule by matching the regular expression ".*", so the following result graph is generated:

    <rdf:Description rdf:about="http://adult.example.com/">
      <label:hasContentLabel rdf:resource="http://www.example.com/labels.rdf#default"/>
     </rdf:Description>
    	  

The input URI "http://www.anotherdomain.com" would be processed as follows:

  1. The domain of the URL, www.anotherdomain.com, is not a valid subdomain of the host restriction for this rule set, so an empty results graph is returned.