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 custom Translations according with how different arguments to translate are (or are not) distinguished.

The actual properties of a Translation subclass must be assigned within the translate method

Parameters
sourcestuple

The sources that go into the translation. Sub-classes may choose to pass these to their superclass’ make_translation method or not.

Returns
a description of the translation
transform(*args, **kwargs)[source]

Just calls translate and returns its result.

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 sourceObjectProperty

Attribute: source

The data source that was translated into this one

TransformationObjectProperty

Attribute: transformation

Information about the transformation process that created this object

TranslationObjectProperty

Attribute: translation

Information about the translation process that created this object

DescriptionDatatypeProperty

Attribute: description

Free-text describing the data 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 (or Translator.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 other DataSources

Attributes
input_typetype or tuple of type

A source for data that can get translated into owmeta_core objects.

output_typetype or tuple of type

A source for data that can get translated into owmeta_core objects.

transformation_typetype

Record of the how a DataSource was produced and the sources of the transformation that produced it.

output_keystr

The “key” for outputs from this transformer (see IdentifierMixin). Normally only defined during execution of __call__

output_identifierstr

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 result DataSource.after_transform is called.

make_new_output(sources, *args, **kwargs)[source]

Make a new output DataSource. Typically called within transform.

make_transformation(sources=())[source]

It’s intended that implementations of DataTransformer will override this method to make custom Transformations according with how different arguments to transform are (or are not) distinguished.

The actual properties of a Transformation subclass must be assigned within the transform 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 input DataSource 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
transformerDataTransformer

transformer to execute

output_keystr

Output key. Used for generating the output’s identifier. Exclusive with output_identifier

output_identifierstr

Output identifier. Exclusive with output_key

data_sourceslist of DataSource

Input data sources

named_data_sourcesdict

Named input data sources

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