How do rel and rev express relationships in RDFa?

The Citead team, updated

In short. RDFa rel creates subject to object relationships, while rev swaps those positions for the same predicate.

Definition: In RDFa, rel expresses a relationship from the current subject to a resource object. rev expresses the inverse relationship, using the resource object as subject and the current subject as object.

Key facts

  • An RDF triple has a subject, a predicate and an object, and its conventional order is subject, predicate, object, according to RDF 1.1 Concepts and Abstract Syntax.
  • RDFa Core defines rel as a whitespace separated list of terms, CURIEs or absolute IRIs for relationships between two resources.
  • RDFa Core defines rev as a whitespace separated list of terms, CURIEs or absolute IRIs for reverse relationships between two resources.
  • resource, href and src can provide the resource object used with rel or rev; a nested subject can provide it when those attributes are absent.
  • The RDFa 1.1 Primer shows that rel can be placed on a containing ul while its li elements supply the relationship targets.

How does rel create a forward relationship?

RDFa Core 1.1, a W3C Recommendation published 17 March 2015, treats rel as a predicate attribute. The current subject becomes the triple's subject, each value in rel becomes a predicate IRI, and the current object resource becomes the object. A value can be a term, a CURIE or an absolute IRI after RDFa processing.

The object resource usually comes from resource, href or src. If the element carries rel but no such attribute, RDFa processing can use the subject of a nested statement. This lets a containing element describe several targets.

<div about="http://example.com/alice" rel="foaf:knows" resource="http://example.com/bob">
</div>

This markup expresses the triple Alice foaf:knows Bob. The rel value names the predicate, while about and resource identify the two resources.

How does rev reverse the relationship?

The same specification describes rel and rev as inverses. With rev, the current object resource becomes the subject and the current subject becomes the object. The predicate IRI remains the value supplied by the attribute.

The specification also permits both attributes on one element. Its example uses rev="dc:creator" and rel="foaf:img" on an image. The result contains one triple saying that the image has that creator and another saying that the person has the image as a depiction.

<img about="http://www.blogger.com/profile/1109404"
    src="photo1.jpg" rev="dc:creator" rel="foaf:img"/>

The two attributes therefore describe two directed predicates between the same pair of resources. They do not turn one predicate into a symmetric relation.

What should you check in RDFa markup?

Start with the subject. RDFa uses the document IRI by default when processing begins, unless a host-language mechanism or an about value sets another current subject. Then identify the object resource and read the direction of every predicate attribute.

Use resource for a relationship target that is not intended to be a navigable link. Use href for a traditionally navigable IRI and src when the resource is embedded. RDFa Core says that rel and rev require an IRI object, and it resolves relative IRIs against the base IRI during processing.

When a predicate appears without an object resource, RDFa stores an incomplete triple until a later subject can complete it. This is the chaining behavior used by the Primer's ul and li example. The Primer also explains that rel takes relationship targets from the hierarchy rather than from an element's text content.

FAQ

Can rel and rev appear on the same element?

Yes. RDFa Core's image example places both on one element and produces two triples with opposite directions and different predicates.

Does rev change the predicate name?

No. It changes the subject and object positions. The value in rev remains the predicate IRI, while the resource object moves to the subject position.

The processor can look for a nested subject and use it as the resource object. If processing still has no object resource, the specification keeps an incomplete triple for completion when a later subject is found.

Sources

  1. W3C, "RDFa Core 1.1 - Third Edition", 17 March 2015
  2. W3C, "RDFa 1.1 Primer - Third Edition", 17 March 2015
  3. W3C, "RDF 1.1 Concepts and Abstract Syntax", 25 February 2014

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark