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, andaliases, namespaces read as equal (https://schema.org/ashttp://schema.org/);systems, each an identifier system with the vocabulary prefixes its own linked data uses, how its things are looked up (lookup) and itsthings: 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 alternativepatterns 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 onlywhenthe subject or value is of given types or things, and markedinversewhere it reads the verb backwards (inverse_label);is_acomes 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:
objectA catalogue as read: its prefixes, aliases, systems, verbs and types.
- class timetoshare.catalogue.Recognition(system, thing, value, iri)[source]#
Bases:
NamedTupleWhat the catalogue recognises in a URL.
- class timetoshare.catalogue.Rectangle(verb, inverse, pairs, things, label)[source]#
Bases:
NamedTupleOne verb about one thing, stated in one or more vocabularies.
- timetoshare.catalogue.instantiate(catalogue, verb, system, value, *, alternative=0, label=None, slots=None)[source]#
Return the pairs that state
verbofvalueinsystem’s pattern.The alternative’s pairs, keys in code-point order:
{"id": "?"}becomes{"id": value}(withlabelwhere given),"?"becomesvalueand"?name"becomesslots[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’sprefixes, a thing’sprefixandlrmoo_class, the keys,typeitems and nodeids 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, orNone.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
lowercaseis true, the lettersAtoZof 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 stringlabeland the labels are equal (transitively): the thing of a node is itsidand theids under itsschema:sameAsandowl:sameAs, the thing of atypepair its class. A pair no verb reads is a rectangle of its own. Theis_arectangle 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 itstypeitems among the value’s. Of several, the one with most constants wins, ties in catalogue order.