timetoshare.statements#

Property–value statements about the things a manifest’s elements stand for.

The bundle (the manifest), every timeline at any depth and every region may carry statements: an object whose keys are type (“is a”) or property IRIs, written compactly with a prefix of the manifest’s @context or in full, and whose values are the non-empty lists of that property’s values. A value is a literal (a string, an integer or a boolean), a value object (@value with @language or @type), a node (a thing: its id where it has one, type, a label kept as a cache, its own pairs as property-IRI keys and its own provenance) or {"list": [...]} for values in order. A string is never read as an IRI: a thing is {"id": ...}.

Beside the container, provenance holds an entry per pair (the entry of the provenance schema, provenance.schema.json): it repeats a pair’s property and value and says who stated it (stated_by), when (date), how (method, service, basis, match), with a note, and who believes it (beliefs: per actor one of the strings "true", "false" and "unlikely"). An entry whose pair is stated annotates it; an entry whose pair is not stated is a candidate, which an actor believing it "false" is not offered again. Nothing derives a truth value from the beliefs. The manifest’s inline JSON-LD context @context holds the format’s terms (FORMAT_CONTEXT) and the prefixes the statements use, which makes the manifest a YAML-LD document whose statements read as plain triples and whose annotations read as RDF reification of those triples.

A subject is addressed by its path in the manifest: () the bundle, a path ending in ("timelines" | "children" | "regions", i) an element, a path passing on through statements to an item of a list of values a value node. Every function is pure: it returns a new value and leaves its argument as it is. IRIs inside statements and provenance, the references to elements ({"id": "#clt_1"}) included, are identical in a manifest file and in memory, so every function reads either ID form. The JavaScript package offers the same functions (withPair, samePair, …) with the same values and the same messages.

timetoshare.statements.ATOMIC_SECTION = 'https://timetoalign.github.io/timetoshare/ns#AtomicSection'#

The class of an atomic section of a timeline’s flow: the type a region states that is one, written as a compact IRI under a prefix the manifest’s context declares for NAMESPACE (tts:AtomicSection).

timetoshare.statements.BELIEFS = ('true', 'false', 'unlikely')#

The beliefs an actor may hold in an item, strings in the schema’s order.

timetoshare.statements.BELIEF_STATES: tuple[Literal['true', 'undecided', 'unlikely', 'false'], ...] = ('true', 'undecided', 'unlikely', 'false')#

The four states of the belief filter, in that order.

timetoshare.statements.BLANK = '[\\u0000-\\u0020\\u007f-\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]'#

White space and control characters, which no IRI holds.

The class the schema’s Iri, IriReference and PrefixIri refuse, written out because Python’s \s and JavaScript’s \s differ.

timetoshare.statements.DEFAULT_BELIEFS: tuple[Literal['true', 'undecided', 'unlikely', 'false'], ...] = ('true', 'undecided', 'unlikely')#

The states the belief filter keeps by default: every state but "false".

timetoshare.statements.FORMAT_CONTEXT: dict[str, Any] = {'@version': 1.1, 'actor': {'@id': 'https://timetoalign.github.io/timetoshare/ns#actor', '@type': '@id'}, 'basis': {'@id': 'http://www.w3.org/ns/prov#hadPrimarySource', '@type': '@id'}, 'belief': {'@id': 'https://timetoalign.github.io/timetoshare/ns#belief', '@type': '@vocab'}, 'beliefs': 'https://timetoalign.github.io/timetoshare/ns#beliefs', 'broad': 'http://www.w3.org/2004/02/skos/core#broadMatch', 'children': '@included', 'close': 'http://www.w3.org/2004/02/skos/core#closeMatch', 'date': {'@id': 'http://purl.org/dc/terms/date', '@type': 'http://www.w3.org/2001/XMLSchema#date'}, 'exact': 'http://www.w3.org/2004/02/skos/core#exactMatch', 'false': 'https://timetoalign.github.io/timetoshare/ns#False', 'groups': '@included', 'id': '@id', 'imported': 'https://timetoalign.github.io/timetoshare/ns#Imported', 'inferred': 'https://timetoalign.github.io/timetoshare/ns#Inferred', 'label': 'http://www.w3.org/2000/01/rdf-schema#label', 'list': '@list', 'manual': 'https://timetoalign.github.io/timetoshare/ns#Manual', 'match': {'@id': 'https://timetoalign.github.io/timetoshare/ns#match', '@type': '@vocab'}, 'method': {'@id': 'https://timetoalign.github.io/timetoshare/ns#method', '@type': '@vocab'}, 'narrow': 'http://www.w3.org/2004/02/skos/core#narrowMatch', 'note': 'http://www.w3.org/2000/01/rdf-schema#comment', 'property': {'@id': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate', '@type': '@vocab'}, 'provenance': {'@reverse': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'}, 'reconciled': 'https://timetoalign.github.io/timetoshare/ns#Reconciled', 'regions': '@included', 'related': 'http://www.w3.org/2004/02/skos/core#relatedMatch', 'service': {'@id': 'https://timetoalign.github.io/timetoshare/ns#service', '@type': '@id'}, 'stated_by': {'@id': 'http://www.w3.org/ns/prov#wasAttributedTo', '@type': '@id'}, 'statements': '@nest', 'timelines': '@included', 'true': 'https://timetoalign.github.io/timetoshare/ns#True', 'type': '@type', 'unlikely': 'https://timetoalign.github.io/timetoshare/ns#Unlikely', 'value': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#object'}#

The format’s terms of @context, each exactly as the schema fixes it.

The 35 terms and no prefix; treat it as read-only. with_context adds the prefixes a manifest uses.

timetoshare.statements.MATCHES = ('exact', 'close', 'broad', 'narrow', 'related')#

The words of a provenance entry’s match, the SKOS mapping properties.

timetoshare.statements.METHODS = ('manual', 'reconciled', 'imported', 'inferred')#

The words of a provenance entry’s method; any other method is an IRI.

timetoshare.statements.NAMESPACE = 'https://timetoalign.github.io/timetoshare/ns#'#

The namespace of the format’s own provenance properties and their words.

timetoshare.statements.BeliefState#

An item’s state for one actor: the actor’s belief in it, or "undecided" where the actor holds none.

alias of Literal[‘true’, ‘undecided’, ‘unlikely’, ‘false’]

timetoshare.statements.candidates(manifest, subject, actor=None)[source]#

Return a subject’s candidates: the entries of pairs the subject does not state.

With actor, a candidate the actor believes "false" is left out: it is not offered to that actor again. Actors compare as their IRIs.

Raises:

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

timetoshare.statements.check_belief_filter(beliefs)[source]#

Return the states a belief filter keeps, checked.

Parameters:

beliefs (object) – A collection of BELIEF_STATES, in any order; empty keeps none.

Raises:

ValueError – If beliefs is a single string or no collection (a mapping included), or names a word that is none of BELIEF_STATES. The first unknown member by code point of its spelling is named: a string quoted, any other member spelled as spell() spells it, without quotes.

timetoshare.statements.compact_iri(prefixes, iri, *, aliases=None)[source]#

Return iri written name:rest with one of prefixes, or as given.

Where a namespace of aliases (the first in its order) begins iri, it is first replaced by the namespace it is read as. Among the prefixes whose namespace begins the IRI so read and leaves a rest of letters, digits, _, . and - that does not begin with . or -, the longest namespace wins, a tie going to the code-point-smaller name. Without such a prefix the IRI is returned as given, no alias applied. The JavaScript package’s compactIri gives the same texts.

Parameters:
  • prefixes (Mapping[str, str]) – Prefix name to namespace, as a catalogue or a context declares them.

  • iri (str) – An absolute IRI.

  • aliases (Mapping[str, str] | None) – Namespace to the namespace it is read as.

timetoshare.statements.entries(manifest, subject)[source]#

Return a subject’s provenance entries, in their order.

Raises:

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

timetoshare.statements.expand_iri(context, text)[source]#

Return the absolute IRI text stands for under context, or None.

type is rdf:type; another format term mapping to an IRI is that IRI; p:rest is text itself when rest begins with // or p is one of the URI schemes info, mailto, tag and urn, and the namespace of p followed by rest when context declares the prefix p. Anything else expands to nothing.

timetoshare.statements.pairs(manifest, subject)[source]#

Return a subject’s pairs (property, value).

Keys in code-point order, values in list order; each type item is a pair ("type", iri). A node’s pairs are its property-IRI keys and type.

Raises:

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

timetoshare.statements.same_pair(context, a, b)[source]#

Whether two pairs (property, value) are the same pair under context.

The properties are equal after expansion (type is rdf:type, which an entry writes rdf:type whether or not the context declares rdf). Of the values, literals are equal with the same JSON type (true is not 1); value objects after expanding @type; a node with an id is equal to any node with the same expanded id, whatever else either holds, a type item T counting as {"id": T}; nodes without id are equal as JSON after dropping their own provenance; ordered values item by item. A relative reference compares as written.

timetoshare.statements.subject_path(manifest, element_id)[source]#

Return the path of the subject an element ID names.

None names the bundle, (); an ID names the timeline (at any depth) or region whose id is element_id as written in this manifest, the first in document order.

Raises:

ValueError – If no timeline or region has that ID.

timetoshare.statements.subjects(manifest)[source]#

Yield the elements that may carry statements, in subject order.

The manifest, then root by root the timeline, its regions in array order and its children, depth first; each with its path and its kind (manifest, timeline, region). An entry that is no object is passed over, so the walk reads any value.

timetoshare.statements.used_prefixes(manifest)[source]#

Return the sorted names of the prefixes the statements of a manifest use.

Every p of a p:rest (rest not beginning with //, p none of the URI schemes info, mailto, tag and urn) at every IRI position of every subject’s statements and provenance and of the provenance of every flow-control element and FlowMap.

timetoshare.statements.with_belief(manifest, subject, property, value, *, actor, belief, date, note=None)[source]#

Return the manifest with an actor’s belief in a pair of a subject.

belief is one of the strings "true", "false" and "unlikely" (BELIEFS). The pair’s entry, appended with the pair alone where it has none, records {"actor", "belief", "date"} (and note where given), replacing in place the actor’s earlier belief; actors compare as their IRIs. Whether the pair is stated is left as it is: one actor’s belief leaves the statement and every other actor’s belief standing. A candidate an actor believes "false" is not offered to that actor again (candidates()).

Raises:

ValueError – If property is no property, the path addresses no element and no value node, belief is none of the three, or date is no calendar date.

timetoshare.statements.with_candidate(manifest, subject, property, value, *, stated_by, date, method, service=None, basis=(), match=None, note=None)[source]#

Return the manifest with a candidate: an entry of a pair it does not state.

The entry replaces, in place, another entry of the pair, whose beliefs it keeps; the statements are left as they are. basis is written only when it is not empty, service, match and note only when given. A service or a loader proposing a pair holds no belief.

Raises:

ValueError – If property is no property, the path addresses no element and no value node, date is no calendar date, or the subject states the pair.

timetoshare.statements.with_context(manifest, prefixes)[source]#

Return the manifest with the format’s terms and its prefixes in @context.

Each prefix of used_prefixes takes its namespace from the manifest’s own @context where it declares the prefix, else from prefixes; a prefix the statements do not use is dropped.

Raises:

ValueError – If a prefix the statements use is declared neither in the manifest’s @context nor in prefixes.

timetoshare.statements.with_pair(manifest, subject, property, value, *, provenance=None, actor=None, date=None)[source]#

Return the manifest with the pair (property, value) stated of a subject.

The value is appended to the property’s list (type takes a class IRI string). An entry of the pair, a candidate until now, stays as the stated pair’s entry. With provenance (the members of an entry but property, value and beliefs), they are set on the pair’s entry, which is appended where the pair has none: its value is {"id": ...} for a node with an id and for a type pair, else the value itself, and a type pair’s property is written rdf:type. With actor, the person stating the pair, the entry records that actor’s belief "true" on date, replacing the actor’s earlier belief.

Raises:

ValueError – If property is no property, the path addresses no element and no value node, a date is no calendar date, actor is given without date, or the subject already has the pair.

timetoshare.statements.with_references_renamed(manifest, renamed)[source]#

Return the manifest with the references to renamed elements renamed or dropped.

The keys and values of renamed are bare IDs. A reference is the text "#" + old exactly (other.yaml#old names an element of another manifest and is none) where statements name things: a node’s id, a provenance entry’s basis and stated_by items and its service, and a belief’s actor, in the statements and provenance of the manifest, of every timeline at any depth and of every region, and of every node within them, a node in an entry’s value included. Where renamed[old] is an ID, each reference becomes "#" + renamed[old]. Where it is None, a value that is a node naming the element leaves its list, an entry whose value names it leaves provenance, a basis or stated_by item naming it leaves its list, a belief whose actor it is leaves beliefs and a service naming it is deleted; then every list of values, container, basis, stated_by, beliefs and provenance left empty is deleted, as are a node without id and ordered values left without anything. Each reference is renamed once: with {"a": "b", "b": "c"}, #a becomes #b and #b becomes #c. The elements’ own IDs are never read, so either ID form is taken. The JavaScript package’s withReferencesRenamed gives the same values.

timetoshare.statements.without_pair(manifest, subject, property, value)[source]#

Return the manifest without the pair (property, value) of a subject.

The pair’s entry goes with it; an emptied list, container or provenance is removed.

Raises:

ValueError – If property is no property, the path addresses no element and no value node, or the subject does not have the pair.