Package musicbrainz2 :: Module model :: Class Relation

[frames] | no frames]

# Class Relation

source code

    object --+
             |
            Relation

Represents a relation between two Entities.

There may be an arbitrary number of relations between all first class objects in MusicBrainz. The Relation itself has multiple attributes, which may or may not be used for a given relation type.

Note that a Relation object only contains the target but not the source end of the relation.

To Do: Add some examples.

Instance Methods

__init__(self, relationType=None, targetType=None, targetId=None, direction=`'``none``'`, attributes=None, beginDate=None, endDate=None, target=None) Constructor. | source code

getType(self) Returns this relation's type. | source code

setType(self, type_) Sets this relation's type. | source code

getTargetId(self) Returns the target's ID. | source code

setTargetId(self, targetId) Sets the target's ID. | source code

getTargetType(self) Returns the target's type. | source code

setTargetType(self, targetType) Sets the target's type. | source code

getAttributes(self) Returns a list of attributes describing this relation. | source code

addAttribute(self, attribute) Adds an attribute to the list. | source code

getBeginDate(self) Returns the begin date. | source code

setBeginDate(self, dateStr) Sets the begin date. | source code

getEndDate(self) Returns the end date. | source code

setEndDate(self, dateStr) Sets the end date. | source code

getDirection(self) Returns the reading direction. | source code

setDirection(self, direction) Sets the reading direction. | source code

getTarget(self) Returns this relation's target object. | source code

setTarget(self, target) Sets this relation's target object. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables
| TO_ARTIST = ``'``http://musicbrainz.org/ns/rel-1.0#Artist``'`` Identifies relations linking to an artist.
| TO_RELEASE = ``'``http://musicbrainz.org/ns/rel-1.0#Release``'`` Identifies relations linking to a release.
| TO_TRACK = ``'``http://musicbrainz.org/ns/rel-1.0#Track``'`` Identifies relations linking to a track.
| TO_URL = ``'``http://musicbrainz.org/ns/rel-1.0#Url``'`` Identifies relations linking to an URL.
| DIR_BOTH = ``'``both``'`` Relation reading direction doesn't matter (no longer used!).
| DIR_FORWARD = ``'``forward``'`` Relation reading direction is from source to target.
| DIR_BACKWARD = ``'``backward``'`` Relation reading direction is from target to source.
| DIR_NONE = ``'``none``'`` Relation reading direction doesn't matter.

Properties
| type The relation's type.
| targetId The type of target this relation points to.
| attributes The list of attributes describing this relation.
| beginDate The begin date.
| endDate The end date.
| direction The reading direction.
| target The relation's target object.
Inherited from `object`: `__class__`

Method Details

### __init__(self, relationType=None, targetType=None, targetId=None, direction=`'``none``'`, attributes=None, beginDate=None, endDate=None, target=None)
(Constructor)

source code

Constructor.

Parameters:
  - `relationType` - a string containing an absolute URI
  - `targetType` - a string containing an absolute URI
  - `targetId` - a string containing an absolute URI
  - `direction` - one of `Relation.DIR_FORWARD`, `Relation.DIR_BACKWARD`, or `Relation.DIR_NONE`
  - `attributes` - a list of strings containing absolute URIs
  - `beginDate` - a string containing a date
  - `endDate` - a string containing a date
  - `target` - an instance of a subclass of Entity
Overrides: object.__init__

### getType(self)

source code

Returns this relation's type.

Returns:
  a string containing an absolute URI, or None

### setType(self, type_)

source code

Sets this relation's type.

Parameters:
  - `type_` - a string containing an absolute URI

### getTargetId(self)

source code

Returns the target's ID.

This is the ID the relation points to. It is an absolute URI, and in case of an URL relation, it is a URL.

Returns:
  a string containing an absolute URI

### setTargetId(self, targetId)

source code

Sets the target's ID.

Parameters:
  - `targetId` - a string containing an absolute URI

See Also: getTargetId

### getTargetType(self)

source code

Returns the target's type.

For MusicBrainz data, the following target types are defined:

- artists: Relation.TO_ARTIST
- releases: Relation.TO_RELEASE
- tracks: Relation.TO_TRACK
- urls: Relation.TO_URL

Returns:
  a string containing an absolute URI

### setTargetType(self, targetType)

source code

Sets the target's type.

Parameters:
  - `targetType` - a string containing an absolute URI

See Also: getTargetType

### getAttributes(self)

source code

Returns a list of attributes describing this relation.

The attributes permitted depend on the relation type.

Returns:
  a list of strings containing absolute URIs

### addAttribute(self, attribute)

source code

Adds an attribute to the list.

Parameters:
  - `attribute` - a string containing an absolute URI

### getBeginDate(self)

source code

Returns the begin date.

The definition depends on the relation's type. It may for example be the day of a marriage or the year an artist joined a band. For other relation types this may be undefined.

Returns:
  a string containing a date

### setBeginDate(self, dateStr)

source code

Sets the begin date.

Parameters:
  - `dateStr` - a string containing a date

See Also: getBeginDate

### getEndDate(self)

source code

Returns the end date.

As with the begin date, the definition depends on the relation's type. Depending on the relation type, this may or may not be defined.

Returns:
  a string containing a date

See Also: getBeginDate

### setEndDate(self, dateStr)

source code

Sets the end date.

Parameters:
  - `dateStr` - a string containing a date

See Also: getBeginDate

### getDirection(self)

source code

Returns the reading direction.

The direction may be one of Relation.DIR_FORWARD, Relation.DIR_BACKWARD, or Relation.DIR_NONE, depending on how the relation should be read. For example, if direction is Relation.DIR_FORWARD for a cover relation, it is read as "X is a cover of Y". For some relations there is no reading direction (like marriages) and the web service doesn't send a direction. In these cases, the direction is set to Relation.DIR_NONE.

Returns:
  Relation.DIR_FORWARD, Relation.DIR_BACKWARD, or Relation.DIR_NONE

### setDirection(self, direction)

source code

Sets the reading direction.

Parameters:
  - `direction` - Relation.DIR_FORWARD, Relation.DIR_BACKWARD, or Relation.DIR_NONE

See Also: getDirection

### getTarget(self)

source code

Returns this relation's target object.

Note that URL relations never have a target object. Use the getTargetId method to get the URL.

Returns:
  a subclass of Entity, or None

### setTarget(self, target)

source code

Sets this relation's target object.

Note that URL relations never have a target object, they are set using setTargetId.

Parameters:
  - `target` - a subclass of Entity

Property Details

### type

The relation's type.

Get Method:
  getType(self) - Returns this relation's type.
Set Method:
  setType(self, type_) - Sets this relation's type.

### targetId

The type of target this relation points to.

Get Method:
  getTargetId(self) - Returns the target's ID.
Set Method:
  setTargetId(self, targetId) - Sets the target's ID.

### attributes

The list of attributes describing this relation.

Get Method:
  getAttributes(self) - Returns a list of attributes describing this relation.

### beginDate

The begin date.

Get Method:
  getBeginDate(self) - Returns the begin date.
Set Method:
  setBeginDate(self, dateStr) - Sets the begin date.

### endDate

The end date.

Get Method:
  getEndDate(self) - Returns the end date.
Set Method:
  setEndDate(self, dateStr) - Sets the end date.

### direction

The reading direction.

Get Method:
  getDirection(self) - Returns the reading direction.
Set Method:
  setDirection(self, direction) - Sets the reading direction.

### target

The relation's target object.

Get Method:
  getTarget(self) - Returns this relation's target object.
Set Method:
  setTarget(self, target) - Sets this relation's target object.