PropertyAndTypeof

From RDFa Working Group Wiki
Revision as of 08:57, 9 November 2011 by Ivan (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

Recent communications on the Vocabs mailing list [1], as well as contacts with current or potential users, e.g., schema.org, indicate that the use of both @rel and @property is still confusing, and there’s a real need to simplify RDFa further and minimize the use of @rel.

This proposal seeks to provide a change on the RDFa Core behavior to achieve this simplification. This proposal does include some backward incompatible changes to RDFa 1.0, and the effects of these changes have to be carefully examined and community feedbacks should be gathered.

The RDFWA Working Group has identified two areas where changes might be necessary. One is the core behavior of @property and its relationship to @rel, the other is the exact behavior of @typeof. The proposed changes are described separately below.

This still just a proposal. There is no Working Group resolution yet as for the acceptance (or not) of all or part of these proposed changes.

Editorial Preliminaries

In what follows, we refer to the @rel attribute only, though it should always say @rel or @rev. This is just to simplify the text; @rev behaves exactly the same way as @rel, except that it reverses the RDF subject and object when creating triples.

Again for the sake of brevity, the term resource attributes will be used for the presence of @resource, @href, or @src; these attributes provide IRI references that will be referred as a defined resource. Note that some Host Languages, like HTML5, may add an attribute to the list with the lowest priority (e.g., @data).

Prefixes are used in the examples without declaring them...

Basic behavior of @property and @rel

Both attributes provide (one or more) predicates for triples. Their behavior is very similar and in many cases they can be used interchangingly.

The following rules govern the behavior of @property and of @rel, in case they are the only one appearing in the element. See below the additional rules if both attributes appear in the same element. Also, the presence of @typeof may modify the behavior of the attributes further, see below for more details.

  1. if the element contains the @property attribute but no @rel attribute
    1. if the element does not contain the @datatype or the @content attributes, and it contains a resource attribute, then the object of the triple generated by @property is the defined resource. The defined resource will not chain, i.e., it does not become the subject for statements in the sub-tree of the current element.
    2. otherwise, a Literal object is generated (the rules are defined in the latest RDF 1.1 Core Draft)
  2. otherwise if the element contains the @rel attribute and no @property attribute
    1. if the element contains a resource attribute, then the object of the triple generated by @rel is the defined resource. The defined resource will chain, i.e., it does become the subject for statements in the sub-tree of the current element.
    2. otherwise, the values of @rel provide the hanging rel mechanism, i.e., the objects for the relevant triples are defined by the subject of the subtree.
  3. otherwise, i.e., the element contains both @rel and @property
    1. @rel has the priority, i.e., rule 1.1 for @property falls and a Literal object is generated.

Examples

<a vocab="http://schema.org" property="url" href="http://example.com">
  <span property="title">NBA Eastern Conference ...</span>
</a>

results in

<> schema:url <http://example.com>;
   schema:title "NBA Eastern Conference".

Because the a element has both @property and @href, the @href value is used as an object as an IRI reference. There is no chaining in this case, so the span element creates a title with a literal value bound to the top element. Using the same example, but replacing the @property="url" with @rel="url" does cause chaining to take effect, so that the title property becomes a property of the @href. I.e.,

<a vocab="http://schema.org"  rel="url" href="http://example.com">
  <span property="title">NBA Eastern Conference ...</span>
</a>

results in

<> schema:url <http://example.com> .
<http://example.com> schema:title "NBA Eastern Conference ..." .

As a results of the rules above, there is also a difference in behavior if @property or @rel stands alone in an element. For example:

<div property="ex:prop">
  This is about <span about="ex:Subject" property="dc:title">my interesting subject</span>
</div>

yields:

<> ex:prop "This is about my interesting subject" .
ex:Subject dc:title "my interesting subject" .

whereas the @rel variant:

<div rel="ex:prop">
  This is about <span about="ex:Subject" property="dc:title">my interesting subject</span>
</div>

yields:

<> ex:prop ex:Subject .
ex:Subject dc:title "my interesting subject" .

This is because a standalone @rel creates hanging rels that will be resolved by the explicit subject in the sub-tree, whereas @property simply takes the textual content of the sub-tree as a (literal) object.

Regular expressions

The following regular expressions can be used when analyzing HTML data to match relevant RDFa patterns. Make sure to use these in multiline matching mode.

Tags containing both @property and @rel:

<[^>]*property=[^>]*rel=[^>]*>|<[^>]*rel=[^>]*property=[^>]*>

Behavior of @typeof

In RDFa, @typeof has two roles: on the one hand it provides a shorthand for rdf:type statements; on the other hand, in some circumstances, it also creates a fresh blank node that will serve both as a subject for the typing statements and for other triples either in the element or in the subtree.

Here are the rules governing the behavior of @typeof:

  1. if neither @rel nor @property is present
    1. if the element contains an @about attribute or a resource setting attribute, the corresponding IRI resource becomes the subject for the typing statements, the object for the possible inherited hanging triples (“hanging rels”), and also the subject for the the statements in the subtree (e.g., chaining occurs)
    2. otherwise, a new blank node is created, which will play the role of a subject for the typing triples, for the statements in the subtree, and will also close the hanging rels.
  2. otherwise if @rel or @property is present as well as @about
    1. The typing statements are added to the IRI resource defined by @about; the behavior of @rel and @property follows the pattern as if @typeof was not present at all.
  3. otherwise
    1. @property but without a @rel
      1. if condition for the 1st behavioral rules for @property are fulfilled (i.e., there is a resource setting attribute, but no @datatype or @content), then that rule is executed, with the addition of type setting triples on the defined resource and an additional chaining behavior, i.e., the defined resource does become the subject for the subtree.
      2. otherwise if there is no @datatype or @content attribute, then a new blank node is created, which will be the subject of the typing statements, and will also become the subject for the subtree, i.e., a chaining will occur relative to the subtree
      3. otherwise a literal subject will be generated, and the @typeof is ignored.
    2. @rel but without a @property
      1. if the conditions for the 1st behavioral rules for @rel are fulfilled (i.e., there is a resource setting attribute), then that rule is executed, with the addition of type setting triples on the defined resource.
      2. otherwise a new blank node is created, which will be the subject of the typing statements, and will also become the subject for the subtree, i.e., a chaining will occur relative to the subtree
    3. both a @rel and @property are present
      1. @rel has the priority, i.e., the 3.1 rule for @property falls.

(Note that the 1st and 2nd rules are unchanged v.a.v. the current RDFa 1.1 Core draft).

Examples

<div typeof="foaf:Person" about="http://greggkellogg.net/foaf#me">
  <p property="name">Gregg Kellogg</span>
  <a property="knows" typeof="foaf:Person" href="http://manu.sporny.org/#this">
    <span property="name">Manu Sporny</span>
  </a>
</div>

results in

<http://greggkellogg.net/foaf#me> a foaf:Person;
  foaf:name "Gregg Kellogg";
  foaf:knows <http://manu.sporny.org/#this> .
<http://manu.sporny.org/#this> a foaf:Person;
  foaf:name "Manu Sporny" .

Note that if the explicit @href is not present, i.e.,

<div typeof="foaf:Person" about="http://greggkellogg.net/foaf#me">
  <p property="name">Gregg Kellogg</span>
  <a property="knows" typeof="foaf:Person">
    <span property="name">Manu Sporny</span>
  </a>
</div>

this results in

<http://greggkellogg.net/foaf#me> a foaf:Person;
  foaf:name "Gregg Kellogg";
  foaf:knows [ 
        a foaf:Person;
        foaf:name "Manu Sporny" 
  ].

Note that, according to these rules,

<span about="ex:subj" property="ex:pred" typeof="ex:t">...</span>

would lead to:

ex:subj ex:pred [ a ex:t ] .

and not to

<> ex:pred ex:subj .
ex:subj a ex:t.

Because the role about is strictly to define the subject and not relate it to the inherited structures. To achieve the triples above, one would have to use

<span property="ex:pred" resource="ex:subj" typeof="ex:t">...</span>

Issues to Discuss

Inconsistencies in the @property chaining rules

At the moment, there is an inconsistency in the rules on chaining v.a.v. @property. Indeed:

<a property="ex:prop" href="http://example.org"><span property="dc:title">something</span></a>

Generates:

<> ex:prop <http://www.example.org>; dc:title "something" .

whereas

<a property="ex:prop" href="http://example.org" typeof="ex:t"><span property="dc:title">something</span></a>

Generates:

<> ex:prop <http://www.example.org> .
<http://www.example.org> a ex:t ;
  dc:title "something".

This is because @typeof creates chaining for @property.

If we do not want to keep this inconsistency, a possibility would be to introduce chaining for @property no matter what. Ie, @property would always induce chaining, just like @rel does (reducing the difference between @rel and @property further). The downside is that the following pattern:

<span about="http://www.ivan-herman.net/foaf#me" property="foaf:homepage" resource="http://www.ivan-herman.net">
  <span property="foaf:name">Ivan Herman</span>
</span>

would not generate

<http://www.ivan-herman.net/foaf#me> 
   foaf:homepage <http://www.ivan-herman.net> ;
   foaf:name "Ivan Herman" .

although the fact that chaining can be avoided in this case is really useful.

Another possibility would be to restrict the chaining when @typeof is present without a resource setting attribute. But some of the schema.org examples may not work any more...

Behavior of @typeof and @about, and its relation to @rel and @property

The rules above say that, if an @about property is around, @typeof will be used for that resources, ignoring a possible @rel or @property. What this means, in practice, is that:

<div about="http://www.example.org" property="ex:prop" typeof="ex:t"><span property="ex:pro2">Bla</span></div>

yields

<http://www.example.org> a ex:t ;
   ex:prop "Bla" ;
   ex:prop2 "Bla" .

Which may not be what one would expect (the property falls back to a literal generating mode, generating "Bla"), then recursion would add the additional triple for ex:prop2. Note that if one uses:

<div href="http://www.example.org" property="ex:prop" typeof="ex:t"><span property="ex:pro2">Bla</span></div>

one gets

<http://www.example.org> ex:prop [ a ex:t; ex:prop2 "Bla" ] .

because @href does not have that "attraction" to @typeof.

We could change that rule, requiring @typeof to ignore the presence of @about in case there is a @property or @rel. The inconsistency at that point is that when there is no @rel or @property around, then @typeof does apply to the value of @about.

A more detailed example

These examples have been inspired by some schema.org use cases. Note that some of the alternatives in the issues listed above would change these examples; they are based on the current rules.

With this caveat: schema:Event might be marked up as follows:

<div>
  <div vocab="http://schema.org/" typeof="Event">
    <a property="url" href="nba-miami-philidelphia-game3.html">
    NBA Eastern Conference First Round Playoff Tickets:
    Miami Heat at Philadelphia 76ers - Game 3 (Home Game 1)
    </a>

    <span property="startDate">2011-04-21T20:00</span>

    <div property="location" typeof="Place">
      <a property="url" href="wells-fargo-center.html">
      Wells Fargo Center
      </a>
      <div property="address" typeof="PostalAddress">
        <span property="addressLocality">Philadelphia</span>,
        <span property="addressRegion">PA</span>
      </div>
    </div>

    <div property="offers" typeof="AggregateOffer">
      Priced from: <span property="lowPrice">$35</span>
      <span property="offerCount">1,938</span> tickets left
    </div>
  </div>
</div>

In this example, note that the anchor use of @property="url" creates an IRI ref, and not a literal. To create a literal for the content of the a tag, would involve using span elements with their own properties. As @property in itself does not create a new subject, the content of the a tag shares the same subject.

For example:

<div>
  <div vocab="http://schema.org/" typeof="Event">
    <a property="url" href="nba-miami-philidelphia-game3.html">
      <span property="description">
        NBA Eastern Conference First Round Playoff Tickets:
        Miami Heat at Philadelphia 76ers - Game 3 (Home Game 1)
      </span>
    </a>
  </div>
</div>

would create the following Turtle:

[ a schema:Event;
  schema:url <nba-miami-philidelphia-game3.html>;
  schema:description """
        NBA Eastern Conference First Round Playoff Tickets:
        Miami Heat at Philadelphia 76ers - Game 3 (Home Game 1)
      """ ] .

Also, the Event is related to a AggregateOffer using a schema:offers predicate.

<div>
  <div vocab="http://schema.org/" typeof="Event">
    <div property="offers" typeof="AggregateOffer">
      Priced from: <span property="lowPrice">$35</span>
      <span property="offerCount">1,938</span> tickets left
    </div>
  </div>
</div>

would create the following Turtle:

[ a schema:Event;
  schema:offers [
    a schema:AggregateOffer;
    schema:lowPrice "$35";
    schema:offerCount "1,938"
  ]
] .

The Schema.org datamodel example

The schema.org datamodel page was an early example to show some canonical schema.org use cases in terms of RDFa 1.1. It was encoding (an earlier version of) the example given in the schema.org product type. Here is how the product type would look like in RDFa 1.1 and with the changes proposed here:

<div vocab="http://schema.org/" typeof="Product">
  <img property="image" src="dell-30in-lcd.jpg" />
  <span property="name">Dell UltraSharp 30" LCD Monitor</span>

  <div property="aggregateRating" typeof="AggregateRating">
    <span property="ratingValue">87</span>
    out of <span property="bestRating">100</span>
    based on <span property="ratingCount">24</span> user ratings
 </div>

  <div property="offers" typeof="AggregateOffer">
	<span property="lowPrice">$1250</span>
	to <span property="highPrice">$1495</span>
	from <span property="offerCount">8</span> sellers
 </div>


  Sellers:
  <div rel="offers" typeof="Offer" >
    <a property="url" href="save-a-lot-monitors.com/dell-30.html">
     Save A Lot Monitors - $1250</a>
 </div>
  ...
</div>

yielding, for completeness, the following RDF triples:

[ a schema:Product ;
  schema:image <dell-30in-lcd.jpg> ;
  schema:name "Dell UltraSharp 30" LCD Monitor ;
  schema:aggregateRating [
    a schema:AggregateRating ;
    schema:ratingValue "87" ;
    schema:bestRating "100" ;
    schema:ratingCount "24" 
  ] ;
  schema:offers [
    a schema:AggregateOffer ;
    schema:lowPrice "$1250" ;
    schema:highPrice "$1495" ;
    schema:offerCount "8" 
  ] ;
  schema:offers [
    a schema:Offer ;
    schema:url <save-a-lot-monitors.com/dell-30.html> 
  ] ;
  ...
]

Some Test Cases

@about and @property

Element with @about, @typeof and @property generates a literal on subject

<span about="foo" property="dc:title">Title</span>
@prefix dc: <http://purl.org/dc/terms/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<foo> a dc:title "Title" .

@about, @typeof and @property

Element with @about and @property generates a literal and type, both on subject

<span about="foo" property="dc:title" typeof="rdfs:Resource">Title</span>
@prefix dc: <http://purl.org/dc/terms/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<foo> a rdfs:Resource; dc:title "Title" .

@resource and @typeof

Element with @resource, @typeof places type on object

<div about="foo">
  <link resource="bar" rel="rdf:value" typeof="rdfs:Resource"/>
</div>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<foo> rdf:value <bar> .
<bar> a rdfs:Resource .

@property and @href

Element with @property and @href creates an IRI ref to @href value

<div about="">
  <a property="rdf:value" href="#foo">Bar</a>
</div>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<> rdf:value <#foo> .

@property and @src

Element with @property and @src creates an IRI ref to @href value

<div about="">
  <image property="rdf:value" src="#foo"/>
</div>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<> rdf:value <#foo> .

@property and @resource

Element with @property and @resource creates an IRI ref to @href value

<div about="">
  <div property="rdf:value" resource="#foo">Bar</div>
</div>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<> rdf:value <#foo> .

@href and @property no-chaining

Element with @href and @property does not chain

<div about="">
  <a property="rdf:value" href="#foo">
    <span property="rdf:value">Bar</span>
  </a>
</div>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<> rdf:value <#foo>, "Bar" .

@href, @typeof and @property chaining

Element with @href and @property, but without @typeof does not chain

<div typeof="foaf:Person" about="http://greggkellogg.net/foaf#me">
  <p property="foaf:name">Gregg Kellogg</p>
  <p property="foaf:knows" typeof="foaf:Person" href="http://manu.sporny.org/#this">
    <span property="foaf:name">Manu Sporny</span>
  </p>
</div>
<http://greggkellogg.net/foaf#me> a foaf:Person;
  foaf:name "Gregg Kellogg";
  foaf:knows <http://manu.sporny.org/#this> .
<http://manu.sporny.org/#this> a foaf:Person;
  foaf:name "Manu Sporny" .

@property with @href in a list

The features in this proposal are orthogonal to the listing properties

   <div about="http://www.example.org">
      <a inlist property="rdf:value" href="http://www.example.org#foo"></a>
      <a inlist property="rdf:value" href="http://www.example.org#bar"></a>
    </div>
<http://www.example.org> rdf:value ( <http://www.example.org#foo> <http://www.example.org#bar> ).

@property and @rel with @href in a list

The features in this proposal are orthogonal to the listing properties

   <div about="http://www.example.org">
      <a inlist property="rdf:value" href="http://www.example.org#foo"></a>
      <a inlist rel="rdf:value" href="http://www.example.org#bar"></a>
    </div>
<http://www.example.org> rdf:value ( <http://www.example.org#foo> <http://www.example.org#bar> ).

Processing

The RDFa 1.1 Core‘s processing rules section should be updated as follows (text in red should be added essentially verbatim to the text, the rest is an explanation of the changed to be done):

  • A new processing variable, called typed resource, is introduced with an initial empty value.
  • For a better readability, the old term of current object literal is exchanged against the term current property value
  • Step 5 (ie, when the current element contains no @rel/@rev attribute) is updated as follows. For a better readability, this step is cut into two “sub” steps.
    • If the current element contains the @property attribute, but does not contain the @content or the @datatype attribute
      • new subject is set to the IRI obtained from the first match from the following rules:
        • by using the IRI from @about, if present, obtained according to the section on CURIE and IRI Processing; if the @typeof attribute is present, set typed resource to new subject
      • If no IRI is provided by a resource attribute, then the first match from the following rules will apply:
        • if the element is the root element of the document, then act as if there is an empty @about present, and process it according to the rule for @about, above;
        • otherwise, if parent object is present, new subject is set to the value of parent object.
        • if @typeof is present:
          • the value of typed resource is set as a URI reference by resolving the first value of the element's @href, @src, @resource attributes if any are present; if none of these are present, the value of typed resource is set to a newly defined bnode.
          • The value of the current object resource is set to the value of typed resource.
    • otherwise (ie, the @property element is not present), add at the very end of the processing:
      • if @typeof is present, set the typed resource to the value of new subject
  • Step 6 (ie, when the element contains @rel or @rev):
    • add to the first bullet item (referring to @about): if the @typeof attribute is present, set typed resource to new subject
    • remove the rule "if @typeof present, then new subject is set to a newly created bnode"
    • at the and of the second bulleted item pair, after the reference to @src, add:
      • otherwise, if @typeof is present and @about is not, use a newly created bnode
    • otherwise, if @typeof is present and @about is not
      • Set the value typed resource to this bnode
  • Step 7 (setting the typing triples) should be modified by:
    • If in any of the previous steps a typed resource was set to a non-null value, it is now used to provide a subject for type values;
    • Modify the rule description by exchaning new subject to typed resource.
  • Step 11 is updated as follows:
    • Predicates for the current property value can be set by using @property. If present, one or more IRIs are obtained according to the section on CURIE and IRI Processing, and then the actual current property value is obtained as follows:</code>
      • As a typed literal if @datatype is present ...
      • otherwise, as an XML literal if @datatype is present ...
      • otherwise, as a plain literal using the value of @content if @content is present
      • otherwise, as a plain literal without language component, using the value of @value if @value is present (HTML+RDFa only)
      • otherwise, as a URI reference by resolving the first value of the element's @href, @src, @resource attributes if any are present,
      • otherwise, if the @typeof is present and @about is not, the value of typed resource
      • otherwise, as a plain literal ...

Note that the current editor's draft of Core contains part of these changes.

The HTML5+RDFa may modify these rules by adding @data to the list of attributes like @href, @src, etc, as well as adding additional rules on the literal generation concerning the data and time elements.