Difference between revisions of "WebSchemas/InverseProperties"

From W3C Wiki
Jump to: navigation, search
(A prefix mechanism)
(Proposed Action)
Line 60: Line 60:
 
The Microdata specification should be extended respectively. A fully fledged proposal is outside the scope of this Wiki entry, but below are a few possible solutions.
 
The Microdata specification should be extended respectively. A fully fledged proposal is outside the scope of this Wiki entry, but below are a few possible solutions.
  
A related discussion in the WHATWG mailing list from April 2014 is here: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2014-April/254092.html
+
A related discussion in the WHATWG mailing list from April 2014 is here: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2014-April/254092.html http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2014-March/254014.html
  
 
===A new keyword ===
 
===A new keyword ===

Revision as of 13:11, 14 April 2014

Inverse Properties in Web Schemas

It has been recently argued on the W3C public-vocabs mailing list that

  1. some properties are needed in both directions (e.g. the relationhip between Person and CreativeWork as both CreativeWork hasCreator Author and Author isCreatorOf CreativeWork), and
  2. that this should be addressed at the level of syntaxes for Web data, and not by defining inverse properties in the vocabularies.

Support in Relevant Syntaxes

In RDFa, JSON-LD, and Turtle (and likely other syntaxes in use for Web vocabularies), there are respective mechanisms for using the same property in both directions:

  • RDFa: @rev vs. @rel
  • JSON-LD: @reverse keyword, as defined in http://www.w3.org/TR/json-ld/#reverse-properties.
  • Turtle: Use of a separate statement <subject> <predicate> <object>. (Note using a property with the current node as the object of a statement is limited for BNodes - it is only possible for labeled blank nodes (_:node123), not for unlabeled blank nodes.

Unfortunately, Microdata does not support a similar mechanism. The only current pattern is to use itemref:

<!-- Example of using http://schema.org/creator from the position of the creator -->
 
<div itemscope itemtype="http://schema.org/CreativeWork" itemref="author">
    <!-- Freebase URI for Romeo and Juliet -->
    <link itemprop="sameAs" href="http://www.freebase.com/m/0yq9mqd" />
</div>
 
<div id="author" itemprop="creator" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">William Shakespeare</name>
</div>

This is cumbersome.

Now the following markup using itemid to create global identifiers, one of which is linked to, seems to work in Google's Structured data testing tool, but only indicates a one direction relation:

<div itemid="creative-work" itemscope itemtype="http://schema.org/CreativeWork">
    <link itemprop="author" href="person">
    <!-- Freebase URI for Romeo and Juliet -->
    <link itemprop="sameAs" href="http://www.freebase.com/m/0yq9mqd" />
</div>
 
<div itemid="person" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">William Shakespeare</name>
</div>

The RDFa equivalent would looks like this:

<div vocab="http://schema.org/" resource="creative-work" typeof="http://schema.org/CreativeWork">
    <link property="author" href="person">
    <!-- Freebase URI for Romeo and Juliet -->
    <link property="sameAs" href="http://www.freebase.com/m/0yq9mqd" />
</div>
 
<div vocab="http://schema.org/" resource="person" typeof="http://schema.org/Person">
    <span property="name">William Shakespeare</name>
</div>

Proposed Action

The Microdata specification should be extended respectively. A fully fledged proposal is outside the scope of this Wiki entry, but below are a few possible solutions.

A related discussion in the WHATWG mailing list from April 2014 is here: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2014-April/254092.html http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2014-March/254014.html

A new keyword

E.g. @itemreverseprop:

<div id="author" itemprop="creator" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">William Shakespeare</name>
    <link itemreverseprop="creator" href="http://www.freebase.com/m/0yq9mqd" />
</div>

A prefix mechanism

E.g. itemprop="reverse:creator":

<div id="creator" itemprop="creator" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">William Shakespeare</name>
    <link itemprop="reverse:creator" href="http://www.freebase.com/m/0yq9mqd" />
</div>

A new attribute

E.g. itemrole="rev":

<div itemid="author" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">William Shakespeare</name>
    <link itemrole="rev" itemprop="creator" href="http://www.freebase.com/m/0yq9mqd" />
</div>

Possible values would be [rel, rev] where [itemrole="rel"] is implied by default, even if not declared in the markup. This attribute could possibly also double as an attribute to specify accessibility features on items.

<div itemid="author" itemscope itemtype="http://schema.org/Person">
    <span itemrole="rel" itemprop="name">William Shakespeare</name>
    <span itemrole="rel" itemprop="child" itemscope itemtype="http://schema.org/Person">
        <span itemrole="rel" itemprop="name"> Susanna</span>
    </span>
    <link itemrole="rev" itemprop="creator" href="http://www.freebase.com/m/0yq9mqd" />
</div>

Proposal

It would be very desirable if the Microdata spec was enhanced by adding support for reverse properties.

Examples

TBD: In this section, we should list examples of relevant markup.