Forester 4.2 › New query language › Relational queries [00WW]
- June 20, 2024
- Jon Sterling
The most significant user-facing change to the query language is the ability to form basic relational queries along several built-in relation-symbols; in fact, the built-in query constructors \query/taxon, \query/tag, and \query/author are all expressible in these terms.
Built-in relation symbols [00WX]
- June 20, 2024
- Jon Sterling
Forester includes several built-in relation symbols, maintained as graphs that are accumulated during evaluation:
\rel/transclusioncontains an edge fromxtoywhenxdirectly transcludesy, i.e. contains\transclude{y}.\rel/linkscontains an edge fromxtoywhenxlinks toy, i.e. contains something like[...](y)or[[y]].\rel/taxacontains an edge fromxtoywhenxhas taxony, i.e. contains\taxon{Y}.\rel/tagscontains an edge fromxtoywhenxhas tagy, i.e. contains\tag{y}.\rel/authorscontains an edge fromxtoywhenxhas authory, i.e. contains\author{y}.\rel/contributorscontains an edge fromxtoywhenxis a tree with contributory, i.e. contains\contributor{y}.
The implementation supports arbitrarily many relation symbols; this is not yet exposed to the user, but could in the future be employed by advanced users of Forester to support the development of sophisticated ontologies.
Query modes and polarities [00WZ]
- June 20, 2024
- Jon Sterling
Given an address x and a relation symbol r, there are several useful queries that we might wish to make:
- We might wish to find all incoming edges to
xinr, or we may wish to find all outgoing edges fromxinr. We shall refer to the differenec between incoming and outgoing edges is referred to as a polarity. - Rather than searching for edges, we may wish to search for paths — which corresponds to passing from a relation to its preorder reflection. We will refer to this distinction as a mode.
Forester supports both polarities and modes for relational queries via the following built-in constants:
\query/incomingand\query/outgoingdenote the two polarities.\query/edgesand\query/pathsrepresent the two modes.
The syntax of a relational query [00WY]
- June 20, 2024
- Jon Sterling
Example Expressing built-in queries [00X0]
- June 20, 2024
- Jon Sterling
The built-in basic queries can be expressed in terms of \query/rel in the following way:
\def\my-query/author[x]{
\open\query
\rel{\edges}{\incoming}{\rel/authors}{\x}
}
\def\my-query/taxon[x]{
\open\query
\rel{\edges}{\incoming}{\rel/taxa}{\x}
}
\def\my-query/tag[x]{
\open\query
\rel{\edges}{\incoming}{\rel/tags}{\x}
}Example Querying the (back)links and context a given tree [00X2]
- June 20, 2024
- Jon Sterling
Both the backlinks and (forward) links of a given tree can be computed using a query to the \rel/links relation, and the context (immediate parents) of a given tree can be obatined from the \query/transclusion relation:
\def\query/backlinks[x]{
\open\query
\rel{\edges}{\incoming}{\rel/links}{\x}
}
\def\query/links[x]{
\open\query
\rel{\edges}{\outgoing}{\rel/links}{\x}
}
\def\query/context[x]{
\open\query
\rel{\edges}{\incoming}{\rel/transclusion}{\x}
}Example Querying a coslice of the transclusion preorder [00X4]
- June 20, 2024
- Jon Sterling
We can also write a query to compute the set of trees underneath a given tree in the transclusion preorder (including the original tree) — in other words, the coslice.
\def\query/transclusion-coslice[x]{
\open\query
\rel{\paths}{\outgoing}{\rel/transclusion}{\x}
}