owmeta_core.mapper module¶
- exception owmeta_core.mapper.ClassRedefinitionAttempt(mapper, maybe_cls, cls)[source]¶
Bases:
Exception
Thrown when a
Mapper.add_class
is called on a class when a class with the same name has already been added to the mapper
- class owmeta_core.mapper.Mapper(name=None, class_registry_context=None, class_registry_context_list=None, **kwargs)[source]¶
Bases:
Configurable
Keeps track of relationships between Python classes and RDF classes
The mapping this object manages may also be written to the RDF graph as
class registry entries
. The entries are written to the “class registry context”, which can be specified when the Mapper is created.- Parameters
- name
str
,optional
Name of the mapper for diagnostic/debugging purposes
- class_registry_context
owmeta_core.context.Context
orstr
,optional
The context where mappings should be saved and/or retrieved from. Either the context object itself or the ID for it. If not provided, then the class registry context ID is looked up from the Mapper’s configuration at
CLASS_REGISTRY_CONTEXT_KEY
- class_registry_context_list
list
of
owmeta_core.context.Context
orstr
,optional
List of contexts or context IDs where registry entries should be retrieved from if the class_registry_context doesn’t yield a mapping
- **kwargs
passed to super-classes
- name
- add_class(cls)[source]¶
Add a class to the mapper
- Parameters
- cls
type
The class to add to the mapper
- cls
- Raises
ClassRedefinitionAttempt
Thrown when
add_class
is called on a class when a class with the same name has already been added to the mapper
- resolve_class(uri, context)[source]¶
Look up the Python class for the given URI recovered from the given
Context
- Parameters
- uri
rdflib.term.URIRef
The URI to look up
- context
Context
The context the URI was found in. May affect which Python class is returned.
- uri
- property class_registry_context¶
Context where class registry entries are stored
- property class_registry_context_list¶
Context where class registry entries are retrieved from if
class_registry_context
doesn’t contain an appropriate entry
- owmeta_core.mapper.CLASS_REGISTRY_CONTEXT_KEY = 'class_registry_context_id'¶
- class_registry_context_id¶
Configuration file key for the URI of the class registry RDF graph context.
The class registry context holds the mappings between RDF types and Python classes for a project or bundle.
- owmeta_core.mapper.CLASS_REGISTRY_CONTEXT_LIST_KEY = 'class_registry_context_list'¶
- class_registry_context_list¶
Configuration file key for the list of class registry contexts
If it is specified, then
class_registry_context_id
should be searched first for class registry entries. The class registry list may be built automatically or not defined at all depending on who makes theConfiguration
, but if it is specified with this property, then it should be respected.