ontocast.onto.prefixes¶
One prefix per namespace: the rule every prompt, parse and export follows.
A namespace is shown under exactly one prefix, chosen by the first rule that applies and leaves the prefix free:
- a well-known namespace keeps its standard prefix (
unit:,sosa:); - a catalog ontology's own namespace takes its author's declared prefix, when that prefix is valid -- not a standard prefix of another namespace, not a library id;
- else the ontology's id;
- a namespace no catalog ontology owns takes the prefix its users bind most;
- else a slug of the namespace.
Every other prefix seen bound to a namespace is an alias: accepted when the model writes it and rewritten where authored prose uses it, never shown. Ids may repeat across ontologies; shown prefixes never do, so a shown prefix is the one short handle that names a single ontology.
Attributes¶
CURIE_IN_TEXT = re.compile('(?<![\\w:/#<.-])([A-Za-z][\\w.-]*):([A-Za-z_](?:[\\w.-]*[\\w-])?)')
module-attribute
¶
NOTE_PREDICATES = (SKOS.scopeNote, SKOS.definition, RDFS.comment)
module-attribute
¶
__all__ = ['PrefixTable', 'bind_own_namespace', 'build_prefix_table', 'standard_namespace_prefixes', 'standard_prefix_for', 'valid_shown_prefix']
module-attribute
¶
Classes¶
PrefixTable
¶
The shown prefix of each namespace, and the aliases accepted for it.
Build it with :func:build_prefix_table. Standard namespaces need no
entry: :meth:prefix_for falls back to their standard prefix.
Source code in ontocast/onto/prefixes.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
Attributes¶
aliases = dict(aliases)
instance-attribute
¶
shown = dict(shown)
instance-attribute
¶
Methods:¶
__init__(shown, aliases)
¶
Source code in ontocast/onto/prefixes.py
bind(graph)
¶
Bind the shown prefix of every namespace graph binds or uses.
Source code in ontocast/onto/prefixes.py
namespace_for(prefix)
¶
normalize(graph)
¶
Make graph read under this table, in place.
Binds the shown prefixes and rewrites the CURIEs in its note text, so a prompt rendered from it shows one prefix per namespace. Use it on a prompt's copy of a context graph, never on a stored ontology.
Source code in ontocast/onto/prefixes.py
parse_map()
¶
Prefix -> namespace for every shown prefix and every alias.
Source code in ontocast/onto/prefixes.py
prefix_for(namespace)
¶
The prefix shown for namespace, if it has one.
prefix_or_claim(namespace, candidate)
¶
The shown prefix of namespace, else candidate as the table
would claim it: numbered when another namespace holds it.
For an ontology the catalog does not hold yet, such as a home being minted.
Source code in ontocast/onto/prefixes.py
qname(iri)
¶
iri as prefix:local under the shown prefixes, else as is.
Source code in ontocast/onto/prefixes.py
rewrite_curies(text, source_bindings=None)
¶
Show every CURIE in text under its namespace's shown prefix.
A token prefix:Local is rewritten only when source_bindings
(the bindings of the graph the text comes from) or an unambiguous
alias maps its prefix to a namespace shown under another prefix. Any
other text, unknown prefixes included, is left as it is.
Source code in ontocast/onto/prefixes.py
Functions:¶
author_prefix_id(graph, namespace)
¶
bind_own_namespace(graph, namespace, ontology_id)
¶
Bind the shown prefix of an ontology's own namespace on its graph.
A standard namespace takes its standard prefix; else a valid prefix the graph already binds to it (the author's) is kept; else the id is bound.
Returns:
| Type | Description |
|---|---|
str
|
The prefix now bound to |
Source code in ontocast/onto/prefixes.py
build_prefix_table(ontologies, others=())
¶
The prefix table of a catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontologies
|
Iterable[Ontology]
|
The catalog's head ontologies. |
required |
others
|
Iterable[Graph]
|
Further graphs whose bindings name namespaces (the shapes). |
()
|
Returns:
| Type | Description |
|---|---|
PrefixTable
|
The table: rules 2-5 of the module docstring, in that order; rule 1 |
PrefixTable
|
holds through :meth: |
Source code in ontocast/onto/prefixes.py
standard_namespace_prefixes()
cached
¶
Namespace IRI -> its standard prefix.
The well-known vocabularies first, then the library's prefix tables, then the remaining standard prefixes, the lexically first where a namespace has several.
Source code in ontocast/onto/prefixes.py
standard_prefix_for(namespace)
¶
The standard prefix of namespace, if it is a standard namespace.
valid_shown_prefix(prefix, namespace)
¶
Whether prefix may be shown for namespace.
It must be a prefix name, not one rdflib generated, not a library namespace's, and not the standard prefix of another namespace.