MivotInstance

class pyvo.mivot.writer.MivotInstance(dmtype, *, dmrole=None, dmid=None)[source]

Bases: object

API for building <INSTANCE> elements of MIVOT annotation step by step.

This class provides methods for incremental construction of a MIVOT instance. It builds <INSTANCE> elements that can contain <ATTRIBUTE>, <INSTANCE>, and <REFERENCE>. Support for <COLLECTION> elements is not yet implemented.

The main features are:

  • Model-agnostic: The implementation is independent of any specific data model.

  • Syntax validation: Ensures basic MIVOT syntax rules are followed.

  • Context-agnostic: Ignores context-dependent syntax rules.

Attributes:
_dmtypestring

Instance type (class VO-DML ID)

_dmrolestring

Role played by the instance in the context where it is used (given by the VO-DML serialization of the model)

_dmidstring

Free identifier of the instance

Parameters:
dmtypestr

dmtype of the INSTANCE (mandatory)

dmrolestr, optional

dmrole of the INSTANCE

dmidstr, optional

dmid of the INSTANCE

Raises:
MappingError

If dmtype is not provided

Attributes Summary

dmid

Methods Summary

add_attribute([dmtype, dmrole, value, unit])

Add an <ATTRIBUTE> element to the instance.

add_collection(dmrole, mivot_instances)

to be documented

add_instance(mivot_instance)

Add a nested <INSTANCE> element to the instance.

add_reference([dmrole, dmref])

Add a <REFERENCE> element to the instance.

xml_string()

Build and serialize the <INSTANCE> element as a string.

Attributes Documentation

dmid

Methods Documentation

add_attribute(dmtype=None, dmrole=None, *, value=None, unit=None)[source]

Add an <ATTRIBUTE> element to the instance.

Parameters:
dmtypestr

dmtype of the ATTRIBUTE (mandatory)

dmrolestr

dmrole of the ATTRIBUTE (mandatory)

valuestr or numerical, optional

ID of the column to set the attribute value. If ref is a string starting with a * or is numerical, it is considered as a value (* stripped) as a ref otherwise

unitstr, optional

Unit of the attribute

Raises:
MappingError

If dmtype or dmrole is not provided, or if both ref and value are not defined

add_collection(dmrole, mivot_instances)[source]

to be documented

add_instance(mivot_instance)[source]

Add a nested <INSTANCE> element to the instance.

Parameters:
mivot_instanceMivotInstance

INSTANCE to be added

Raises:
MappingError

If mivot_instance is not of type MivotInstance

add_reference(dmrole=None, dmref=None)[source]

Add a <REFERENCE> element to the instance.

Parameters:
dmrolestr

dmrole of the REFERENCE (mandatory)

dmrefstr

dmref of the REFERENCE (mandatory)

Raises:
MappingError

If dmrole or dmref is not provided

xml_string()[source]

Build and serialize the <INSTANCE> element as a string.

Returns:
str

The string representation of the <INSTANCE> element