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
typea region states that is one, written as a compact IRI under a prefix the manifest’s context declares forNAMESPACE(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,IriReferenceandPrefixIrirefuse, written out because Python’s\sand JavaScript’s\sdiffer.
- 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_contextadds 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
beliefsis a single string or no collection (a mapping included), or names a word that is none ofBELIEF_STATES. The first unknown member by code point of its spelling is named: a string quoted, any other member spelled asspell()spells it, without quotes.
- timetoshare.statements.compact_iri(prefixes, iri, *, aliases=None)[source]#
Return
iriwrittenname:restwith one ofprefixes, or as given.Where a namespace of
aliases(the first in its order) beginsiri, 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’scompactIrigives the same texts.
- 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
textstands for undercontext, orNone.typeisrdf:type; another format term mapping to an IRI is that IRI;p:restistextitself whenrestbegins with//orpis one of the URI schemesinfo,mailto,tagandurn, and the namespace ofpfollowed byrestwhencontextdeclares the prefixp. 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
typeitem is a pair("type", iri). A node’s pairs are its property-IRI keys andtype.- 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 undercontext.The properties are equal after expansion (
typeisrdf:type, which an entry writesrdf:typewhether or not the context declaresrdf). Of the values, literals are equal with the same JSON type (trueis not1); value objects after expanding@type; a node with anidis equal to any node with the same expandedid, whatever else either holds, atypeitemTcounting as{"id": T}; nodes withoutidare equal as JSON after dropping their ownprovenance; 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.
Nonenames the bundle,(); an ID names the timeline (at any depth) or region whoseidiselement_idas 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
pof ap:rest(restnot beginning with//,pnone of the URI schemesinfo,mailto,tagandurn) 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.
beliefis 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"}(andnotewhere 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
propertyis no property, the path addresses no element and no value node,beliefis none of the three, ordateis 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
beliefsit keeps; the statements are left as they are.basisis written only when it is not empty,service,matchandnoteonly when given. A service or a loader proposing a pair holds no belief.- Raises:
ValueError – If
propertyis no property, the path addresses no element and no value node,dateis 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_prefixestakes its namespace from the manifest’s own@contextwhere it declares the prefix, else fromprefixes; a prefix the statements do not use is dropped.- Raises:
ValueError – If a prefix the statements use is declared neither in the manifest’s
@contextnor inprefixes.
- 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 (
typetakes a class IRI string). An entry of the pair, a candidate until now, stays as the stated pair’s entry. Withprovenance(the members of an entry butproperty,valueandbeliefs), they are set on the pair’s entry, which is appended where the pair has none: itsvalueis{"id": ...}for a node with anidand for atypepair, else the value itself, and atypepair’s property is writtenrdf:type. Withactor, the person stating the pair, the entry records that actor’s belief"true"ondate, replacing the actor’s earlier belief.- Raises:
ValueError – If
propertyis no property, the path addresses no element and no value node, a date is no calendar date,actoris given withoutdate, 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
renamedare bare IDs. A reference is the text"#" + oldexactly (other.yaml#oldnames an element of another manifest and is none) where statements name things: a node’sid, a provenance entry’sbasisandstated_byitems and itsservice, and a belief’sactor, 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’svalueincluded. Whererenamed[old]is an ID, each reference becomes"#" + renamed[old]. Where it isNone, a value that is a node naming the element leaves its list, an entry whosevaluenames it leavesprovenance, abasisorstated_byitem naming it leaves its list, a belief whoseactorit is leavesbeliefsand aservicenaming it is deleted; then every list of values, container,basis,stated_by,beliefsandprovenanceleft empty is deleted, as are a node withoutidand ordered values left without anything. Each reference is renamed once: with{"a": "b", "b": "c"},#abecomes#band#bbecomes#c. The elements’ own IDs are never read, so either ID form is taken. The JavaScript package’swithReferencesRenamedgives 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
provenanceis removed.- Raises:
ValueError – If
propertyis no property, the path addresses no element and no value node, or the subject does not have the pair.