Table of Contents
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.
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.
The base URI for this vocabulary is http://www.w3.org/2004/12/q/rules#.
The class rule:Ruleset is a specialization of rdf:List which allows only rule:Rule instances as list members.
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.
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.
An instance of the class rule:PropertySet acts as a "placeholder" resource for any resource which matches a given rule:Rule.
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.
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.
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.
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.
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.
For each resource of type rule:Ruleset in I:
For each rule:hostRestriction property DR of RS, if the host of U is the same as or a subdomain of the host specified as the value of DR, go to step 3.
The host of U does not match any of the specified host restrictions. Return an empty output graph.
For each rule R which is the value of a rule:rules property of RS, if the resource U matches R, then for each rule:PropertySet resource, PS which is the value of a rule:confers property of R:
Copy every property of PS except the rdf:type property to O, replacing the resource PS with the resource U.
For each resource in O add all statements from I that have a resource in O as a subject or object except for statements where the property is in the namespace http://www.w3.org/2004/12/q/rules#, replacing the resource PS with the resource U.
Repeat this step until no new statements are added to O.
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.
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.
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:
The host of the URL, www.example.com, is a valid subdomain of the host restriction for this rule set, so processing may continue.
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:
The host of the URL, adult.example.com, is a valid subdomain of the domain restriction for this rule set, so processing may continue.
The URL does not match the first uri:Matches rule.
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:
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.