timetoshare.catalogue#

The catalogue of identifier systems, verbs and types, which tools read.

A manifest holds statements as property–value pairs; the words a person reads (“performed by”, “is a recording of”) are not in it. The catalogue, one data file catalogue/catalogue.yaml shipped with this package and with the JavaScript package, holds them:

  • prefixes, the namespaces of the vocabularies its patterns use, and aliases, namespaces read as equal (https://schema.org/ as http://schema.org/);

  • systems, each an identifier system with the vocabulary prefixes its own linked data uses, how its things are looked up (lookup) and its things: the kinds of thing it identifies, each with the template of their IRIs (iri, holding {value}, or null), the URLs it recognises (patterns, regular expressions each capturing the value in its one group), whether its values are written in lower case and the LRMoo class of its things;

  • verbs, each with a label and, per system, the alternative patterns that express it there: a fragment of a statements container with slots ({"id": "?"} a thing, "?" a literal or type IRI, "?name" a named literal), optionally only when the subject or value is of given types or things, and marked inverse where it reads the verb backwards (inverse_label); is_a comes first;

  • types, profiles of the things an element may stand for: their “is a” patterns, the verbs usually stated of them and the systems to look in.

The validators never consult it. The patterns of things use only the syntax Python’s re and JavaScript’s RegExp read alike: no named group, no lookbehind, no inline flag. A URL holding white space or a control character is never recognised.

class timetoshare.catalogue.Catalogue(prefixes, aliases, systems, verbs, types)[source]#

Bases: object

A catalogue as read: its prefixes, aliases, systems, verbs and types.

prefixes#

Prefix name to namespace IRI.

Type:

dict[str, str]

aliases#

Namespace to the namespace it is read as.

Type:

dict[str, str]

systems#

The identifier systems, as the file writes them.

Type:

tuple[dict[str, Any], …]

verbs#

The verbs, is_a first, as the file writes them.

Type:

tuple[dict[str, Any], …]

types#

The types, as the file writes them.

Type:

tuple[dict[str, Any], …]

class timetoshare.catalogue.Recognition(system, thing, value, iri)[source]#

Bases: NamedTuple

What the catalogue recognises in a URL.

system#

The ID of the system holding the thing.

Type:

str

thing#

The ID of the thing whose pattern matched.

Type:

str

value#

The captured value, written as the thing writes its values.

Type:

str

iri#

The thing’s IRI, or None where it has no IRI template.

Type:

str | None

class timetoshare.catalogue.Rectangle(verb, inverse, pairs, things, label)[source]#

Bases: NamedTuple

One verb about one thing, stated in one or more vocabularies.

verb#

The verb’s ID, or None for a pair no verb reads.

Type:

str | None

inverse#

Whether the pairs read the verb backwards.

Type:

bool

pairs#

The pairs (property, value), in file order.

Type:

tuple[tuple[str, Any], …]

things#

The IRIs of the things the pairs name, in first-seen order.

Type:

tuple[str, …]

label#

The first label of a node among the pairs, or None.

Type:

str | None

timetoshare.catalogue.instantiate(catalogue, verb, system, value, *, alternative=0, label=None, slots=None)[source]#

Return the pairs that state verb of value in system’s pattern.

The alternative’s pairs, keys in code-point order: {"id": "?"} becomes {"id": value} (with label where given), "?" becomes value and "?name" becomes slots[name].

Raises:

ValueError – If the catalogue has no such verb, the verb has no pattern in the system or not the alternative asked for, or a named slot has no value.

timetoshare.catalogue.load_catalogue()[source]#

Return the catalogue of the shipped file catalogue/catalogue.yaml.

It is read once; treat it as read-only.

timetoshare.catalogue.read_catalogue(document)[source]#

Read a catalogue document after checking its cross-references.

The shape is not checked here (the test suites check the shipped file against catalogue/catalogue.schema.json); the references are, and the first problem raised, in this order: an ID held twice (systems, things, verbs, types); a prefix used without being declared (a system’s prefixes, a thing’s prefix and lrmoo_class, the keys, type items and node ids of every pattern); a system, thing, verb or type named but not held; a thing pattern that is no regular expression of the shared subset with exactly one capturing group.

Raises:

ValueError – With the first problem.

timetoshare.catalogue.recognize(catalogue, url)[source]#

Return what the catalogue recognises in url, or None.

The things of every system are tried in order, and the first whose pattern matches the whole URL recognises it. A thing with an IRI template gives the captured value as written and its IRI; one without gives the value percent-decoded as UTF-8 with underscores for spaces, as a wiki writes a page name, and no IRI. Where the thing’s lowercase is true, the letters A to Z of the value are then lowered. A URL that is no absolute IRI is never recognised, and neither is one whose value is not percent-encoded UTF-8.

timetoshare.catalogue.rectangles(catalogue, manifest, subject)[source]#

Return a subject’s pairs gathered into rectangles: one verb about one thing.

Pairs of the same verb read the same way fall into one rectangle when both state is_a, they name a common thing, or both value nodes carry a string label and the labels are equal (transitively): the thing of a node is its id and the ids under its schema:sameAs and owl:sameAs, the thing of a type pair its class. A pair no verb reads is a rectangle of its own. The is_a rectangle comes first, empty where nothing is stated; then the others by their first pair. Pairs keep file order, things first-seen order, and the label is the first label of a node among the pairs.

Raises:

ValueError – If the path addresses no element and no value node.

timetoshare.catalogue.verb_of(catalogue, context, property, value)[source]#

Return the verb a pair states and whether it reads it backwards, or None.

The pair’s property is expanded by the manifest’s context, each pattern key by the catalogue’s prefixes, both with the catalogue’s aliases applied; an alternative fits where a key expands to the property’s IRI and its template matches the value: a slot any value of its kind, a constant by expanded IRI or JSON equality, a template node’s keys among the value’s and its type items among the value’s. Of several, the one with most constants wins, ties in catalogue order.