Source code for soweego.importer.models.discogs_entity

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""`Discogs <>`_
`SQLAlchemy <>`_ ORM entities."""

__author__ = 'Marco Fossati'
__email__ = ''
__version__ = '1.0'
__license__ = 'GPL-3.0'
__copyright__ = 'Copyleft 2018, Hjfocs'

from sqlalchemy import Column, String, Text
from sqlalchemy.ext.declarative import declarative_base

from soweego.importer.models.base_entity import BaseEntity, BaseRelationship
from soweego.importer.models.base_link_entity import BaseLinkEntity
from soweego.importer.models.base_nlp_entity import BaseNlpEntity

BASE = declarative_base()

ARTIST_TABLE = 'discogs_artist'  # Abstract table

MASTER_TABLE = 'discogs_master'
MUSICIAN_TABLE = 'discogs_musician'
MUSICIAN_LINK_TABLE = 'discogs_musician_link'
MUSICIAN_NLP_TABLE = 'discogs_musician_nlp'
GROUP_TABLE = 'discogs_group'
GROUP_LINK_TABLE = 'discogs_group_link'
GROUP_NLP_TABLE = 'discogs_group_nlp'

MASTER_ARTIST_RELATIONSHIP_TABLE = 'discogs_master_artist_relationship'

[docs]class DiscogsArtistEntity(BaseEntity): """A Discogs *artist*: either a musician or a band. It comes from the ``_artists.xml.gz`` dataset. See the `download page <>`_. All ORM entities describing Discogs people should inherit this class. **Attributes:** - **real_name** (text) - a name in real life - **data_quality** (string(20)) - an indicator of data quality """ __tablename__ = ARTIST_TABLE # Name in real life real_name = Column(Text) # Discogs-specific indicator of data quality data_quality = Column(String(20)) __abstract__ = True
[docs]class DiscogsMasterEntity(BaseEntity): """A Discogs *master*: a musical work, which can have multiple *releases*. It comes from the ``_masters.xml.gz`` dataset. See the `download page <>`_. **Attributes:** - **main_release_id** (string(50)) - a Discogs identifier of the main release for this musical work - **genres** (text) - a string list of musical genres """ __tablename__ = MASTER_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True} main_release_id = Column(String(50)) genres = Column(Text) # Discogs-specific indicator of data quality data_quality = Column(String(20))
[docs]class DiscogsMusicianEntity(DiscogsArtistEntity): """A Discogs musician.""" __tablename__ = MUSICIAN_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True}
[docs]class DiscogsMusicianLinkEntity(BaseLinkEntity): """A Discogs musician Web link (URL).""" __tablename__ = MUSICIAN_LINK_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True}
[docs]class DiscogsMusicianNlpEntity(BaseNlpEntity, BASE): """A Discogs musician textual description.""" __tablename__ = MUSICIAN_NLP_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True}
[docs]class DiscogsGroupEntity(DiscogsArtistEntity): """A Discogs *group*, namely a band.""" __tablename__ = GROUP_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True}
[docs]class DiscogsGroupLinkEntity(BaseLinkEntity): """A Discogs band Web link (URL).""" __tablename__ = GROUP_LINK_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True}
[docs]class DiscogsGroupNlpEntity(BaseNlpEntity, BASE): """A Discogs band textual description.""" __tablename__ = GROUP_NLP_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True}
[docs]class DiscogsMasterArtistRelationship(BaseRelationship): """A relationship between a Discogs musical work and the Discogs musician or band who made it.""" __tablename__ = MASTER_ARTIST_RELATIONSHIP_TABLE __mapper_args__ = {'polymorphic_identity': __tablename__, 'concrete': True} def __repr__(self): return super().__repr__()