owmeta_core.datasource module¶
- exception owmeta_core.datasource.ExtraSourceFound[source]¶
Bases:
Exception
Raised by
transform
when more than one source is found in the current context
- exception owmeta_core.datasource.NoSourceFound[source]¶
Bases:
Exception
Raised by
transform
when a source cannot be found in the current context
- exception owmeta_core.datasource.NoTranslatorFound[source]¶
Bases:
Exception
Raised by
transform
when a translator cannot be found in the current context
- class owmeta_core.datasource.BaseDataTranslator(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
DataTransformer
Input type(s):
DataSource
Output type(s):
DataSource
- make_transformation(sources=())[source]¶
Just calls
make_translation
and returns its result.
- make_translation(sources=())[source]¶
It’s intended that implementations of
BaseDataTranslator
will override this method to make customTranslations
according with how different arguments totranslate
are (or are not) distinguished.The actual properties of a
Translation
subclass must be assigned within thetranslate
method- Parameters
- sources
tuple
The sources that go into the translation. Sub-classes may choose to pass these to their superclass’ make_translation method or not.
- sources
- Returns
a
description
of
the
translation
- translate(*args, **kwargs)[source]¶
Notionally, this method takes one or more data sources, and translates them into some other data source that captures essentially the same information, but, possibly, in a different format. Additional sources can be passed in as well for auxiliary information which are not “translated” in their entirety into the output data source. Such auxiliarry data sources should be distinguished from the primary ones in the translation
- Parameters
- *args
Input data sources
- **kwargs
Named input data sources
- Returns
the
output
data
source
- class owmeta_core.datasource.DataObjectContextDataSource(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
DataSource
- Input source
ObjectProperty
Attribute:
source
The data source that was translated into this one
- Transformation
ObjectProperty
Attribute:
transformation
Information about the transformation process that created this object
- Translation
ObjectProperty
Attribute:
translation
Information about the translation process that created this object
- Description
DatatypeProperty
Attribute:
description
Free-text describing the data source
- Input source
- class owmeta_core.datasource.DataSource(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
DataObject
A source for data that can get translated into owmeta_core objects.
The value for any field can be passed to
__init__
by name. Additionally, if the sub-class definition of a DataSource assigns a value for that field like:class A(DataSource): some_field = 3
that value will be used over the default value for the field, but not over any value provided to
__init__
.- after_transform()[source]¶
Called after
Transformer.transform
.This method should handle any of the things that should happen for an output data source after
Transformer.transform
(orTranslator.translate
). This can include things like flushing output to files, closing file handles, and writing triples in a Context.NOTE: Be sure to call this method via super() in sub-classes
- identifier_augment()[source]¶
It doesn’t make much sense to have translation and transformation set, so we just take the first of them
- description¶
“Description”, a
DatatypeProperty
: Free-text describing the data source
- source¶
“Input source”, a
ObjectProperty
: The data source that was translated into this one
- transformation¶
“Transformation”, a
ObjectProperty
: Information about the transformation process that created this object
- translation¶
“Translation”, a
ObjectProperty
: Information about the translation process that created this object
- class owmeta_core.datasource.DataSourceType(name, typ, dct)[source]¶
Bases:
ContextMappedClass
A type for DataSources
Sets up the graph with things needed for MappedClasses
- class owmeta_core.datasource.DataTransformer(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
DataObject
Transforms one or more
DataSources
to one or more otherDataSources
- Attributes
input_type
type
ortuple
of
type
A source for data that can get translated into owmeta_core objects.
output_type
type
ortuple
of
type
A source for data that can get translated into owmeta_core objects.
transformation_type
type
Record of the how a
DataSource
was produced and the sources of the transformation that produced it.- output_key
str
The “key” for outputs from this transformer (see
IdentifierMixin
). Normally only defined during execution of __call__- output_identifier
str
The identifier for outputs from this transformer. Normally only defined during execution of __call__
- input_type¶
alias of
DataSource
- output_type¶
alias of
DataSource
- transformation_type¶
alias of
Transformation
- after_transform()[source]¶
Called after
transform
runs in__call__
and after the resultDataSource.after_transform
is called.
- make_new_output(sources, *args, **kwargs)[source]¶
Make a new output
DataSource
. Typically called withintransform
.
- make_transformation(sources=())[source]¶
It’s intended that implementations of
DataTransformer
will override this method to make customTransformations
according with how different arguments totransform
are (or are not) distinguished.The actual properties of a
Transformation
subclass must be assigned within thetransform
method
- transform(*args, **kwargs)[source]¶
Notionally, this method takes a data source, which is transformed into some other data source. There doesn’t necessarily need to be an input data source.
- Parameters
- *args
Input data sources
- **kwargs
Named input data sources
- Returns
the
output
data
source
- transform_with(translator_type, *sources, output_key=None, output_identifier=None, **named_sources)[source]¶
Transform with the given
DataTransformer
and sources.This should be used in a
transform
implementation to compose multiple transformations. An instance of the transformer will be created and contextualized with the this transformer’s context unless the given transformer already has a context.
- class owmeta_core.datasource.DataTranslator(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
BaseDataTranslator
A specialization with the
GenericTranslation
translation type that adds sources for the translation automatically when a new output is made- translation_type¶
alias of
GenericTranslation
- class owmeta_core.datasource.GenericTranslation(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
Translation
A generic translation that just has sources in any order
- class owmeta_core.datasource.OneOrMore(source_type)[source]¶
Bases:
object
Wrapper for
DataTransformer
inputDataSource
types indicating that one or more of the wrapped type must be provided to the translator
- class owmeta_core.datasource.PersonDataTranslator(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
BaseDataTranslator
A person who was responsible for carrying out the translation of a data source manually
- property person¶
A person responsible for carrying out the translation.
- class owmeta_core.datasource.Transformation(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
DataObject
Record of the how a
DataSource
was produced and the sources of the transformation that produced it. Unlike the ‘source’ field attached to DataSources, the Translation may distinguish different kinds of input source to a transformation.
- class owmeta_core.datasource.Translation(*args, no_type_decl=False, **kwargs)[source]¶
Bases:
Transformation
A transformation where, notionally, the general character of the input is preserved.
In contrast to just a transformation, a translation wouldn’t just pick out, say, one record within an input source containing several, but would have an output source with o
- owmeta_core.datasource.transform(transformer, output_key=None, output_identifier=None, data_sources=(), named_data_sources=None)[source]¶
Do a translation with the named translator and inputs
- Parameters
- transformer
DataTransformer
transformer to execute
- output_key
str
Output key. Used for generating the output’s identifier. Exclusive with output_identifier
- output_identifier
str
Output identifier. Exclusive with output_key
- data_sources
list
of
DataSource
Input data sources
- named_data_sources
dict
Named input data sources
- transformer
- Raises
NoTranslatorFound
when a translator is not found
NoSourceFound
when a source cannot be looked up in the given context
ExtraSourceFound
when a more than one source is found in the given context for the given source identifier