A page has a welcome label in Arabic and in English. RDF 1.2 can record not only the language of a string but also its base direction. EyeProlog derives display labels and carries that direction through untouched.
Run it in the playground · Source
Which display labels does the welcome page have, and in which writing direction?
This is one of a family of RDF 1.2 examples. RDF data arrives as
rdf(Subject, Predicate, Object, Graph) facts, as produced by
rdf-prolog-interchange,
and results are printed in the same shape.
rdf(iri('https://example.org/welcome'), iri('https://example.org/label'), literal('مرحبا', lang('ar', rtl)), default_graph).
rdf(iri('https://example.org/welcome'), iri('https://example.org/label'), literal('Welcome', lang('en', ltr)), default_graph).
A directional language tag pairs a language with a base direction:
rtl (right to left) for Arabic, ltr (left to right) for English. Without
it, an application must guess how to lay out mixed-direction text.
result_rdf(S, iri('https://example.org/displayLabel'), Label, G) :-
rdf(S, iri('https://example.org/label'), Label, G).
The rule copies the whole literal term, text and tag together. Because the direction is part of the term, it cannot be dropped by accident.
eyeprolog examples/rdf12-directional-language.pl
result_rdf(iri('https://example.org/welcome'), iri('https://example.org/displayLabel'), literal('مرحبا', lang(ar, rtl)), default_graph).
result_rdf(iri('https://example.org/welcome'), iri('https://example.org/displayLabel'), literal('Welcome', lang(en, ltr)), default_graph).
Both labels keep their direction.
step(result_rdf(iri('https://example.org/welcome'), iri('https://example.org/displayLabel'), literal('مرحبا', lang(ar, rtl)), default_graph),
rule(3),
['S' = iri('https://example.org/welcome'),
'Label' = literal('مرحبا', lang(ar, rtl)),
'G' = default_graph],
[rdf(iri('https://example.org/welcome'), iri('https://example.org/label'), literal('مرحبا', lang(ar, rtl)), default_graph)]).
The binding for Label shows the Arabic text and its rtl direction moving
from the source triple into the result.
condition('C1', resolution, ok, 4).
condition('C4', coverage, ok, 4).
condition('C7', relevance, ok, 6).
trusted(0).
verdict(checked).
literal(Text, lang(_, rtl)).Learn more in The Art of EyeProlog, Chapter 9.