Module monodikit.models.genre_specific

Expand source code
from dataclasses import dataclass
from .document import Chant, Division
import re

class Song(Chant):
    pass

class Sequence(Chant):
    pass

class OrdinaryChant(Chant):
    pass

class PlayPassage(Chant):
    pass


from .corpus import Corpus
class Play(Corpus):
    def __init__(self, directory, liturgical_play_id, sample=None, filters=None):
        def cummulative_filter(document_meta, source_meta):
            if document_meta["liturgical_play_id"] != liturgical_play_id:
                return False
            if filters:
                return filters(document_meta, source_meta)
        super().__init__(directory, sample=sample, filters=cummulative_filter)

class ProperTropeComplex(Chant):
    """
    A class representing a trope complex.

    Parameters
    ----------
    entry : str
        The entry to initialize the `ProperTropeComplex` object.

    Attributes
    ----------
    nums : list
        List of signatures of trope elements
    letters : list
        List of signatures of prima chant elements
    ct_volume : str or None
        The Corpus Troporum Volume
    ct_base_chant : str or None
        ...

    Methods
    -------
    get_ct_base_chant()
        Extracts the base chant from the `meta.bibliographischerverweis` attribute using regular expressions.
    get_ct_volume()
        Extracts the volume from the `meta.bibliographischerverweis` attribute using regular expressions.
    get_nums() -> list
        Extracts numbers from the `meta.bibliographischerverweis` attribute and returns them as a list of integers.
    get_letters() -> list
        Extracts uppercase letters from the `meta.bibliographischerverweis` attribute and returns them as a list of strings.
    get_trope_elements() -> list
        Returns a list of divisions from the `data.elements` attribute of the `Document` whose status is "Tropenelement".
    get_primechant_elements() -> list
        Returns a list of divisions from the `data.elements` attribute of the `Document` whose status is "Einsatzmarke" (prime chant elements).
    """

    def __init__(self, entry):
        super().__init__(entry)
        self.nums = self.get_nums()
        self.letters = self.get_letters()
        self.ct_volume = self.get_ct_volume()
        self.ct_base_chant = self.get_ct_base_chant()

    def get_ct_base_chant(self):
        base_chant_match = re.search(r'^.*?(?=\s(?:\d|A))', self.meta.bibliographical_reference)
        return base_chant_match.group(0) if base_chant_match else None

    def get_ct_volume(self):
        volume_match = re.search(r'\(CT\s(\w+)\)$', self.meta.bibliographical_reference)
        return volume_match.group(1) if volume_match else None

    def get_nums(self) -> list:
        return [int(number) for number in re.findall(r"\d+", self.meta.bibliographical_reference)]

    def get_letters(self) -> list:
        return [letter for letter in self.meta.bibliographical_reference.split() if
                len(letter) == 1 and letter.isupper()]

    def get_trope_elements(self):
        return [division for division in self.data.elements if division.status == "Tropenelement"]

    def get_primechant_elements(self):
        return [division for division in self.data.elements if
                division.status == "Einsatzmarke"]  # Does not distinguish between complete and abbreviated (Einsatzmarke) prime chant elements

@dataclass
class TropeElement(Division):
    """
    A dataclass representing a trope element, inheriting from the `Division` class.
    """
    pass

@dataclass
class PrimeChantElement(Division):
    """
    A dataclass representing a prime chant element, inheriting from the `Division` class.
    """
    pass

Classes

class OrdinaryChant (entry_path)

A class representing a document or unit of medieval chant.

A document is represented by its metadata and data, which are loaded from JSON files located in a directory specified by the entry parameter.

Expand source code
class OrdinaryChant(Chant):
    pass

Ancestors

Inherited members

class Play (directory, liturgical_play_id, sample=None, filters=None)

A collection of chants loaded from a directory.

Parameters:

directory : str The input directory that holds the data.

sample : int, optional The number of chants that are given as a sample. Defaults to None.

filter_options : dict or callable, optional If a dict is provided, it does a substring match.

If a callable object is provided, it calls it for every document and creates the document
if True is returned.

Returns:

Corpus A Corpus object containing the chants loaded from the directory.

Examples:

Load chants with a specific substring match:

subcorpus1 = Corpus("../data/*", filter_options={"gattung1": "Sequenz"})

Load chants using a custom filtering function:

subcorpus2 = Corpus("../data/*", filter_options=lambda chant: chant.gattung1 == "Tropus" or chant.gattung1 == "Sequenz")
Expand source code
class Play(Corpus):
    def __init__(self, directory, liturgical_play_id, sample=None, filters=None):
        def cummulative_filter(document_meta, source_meta):
            if document_meta["liturgical_play_id"] != liturgical_play_id:
                return False
            if filters:
                return filters(document_meta, source_meta)
        super().__init__(directory, sample=sample, filters=cummulative_filter)

Ancestors

class PlayPassage (entry_path)

A class representing a document or unit of medieval chant.

A document is represented by its metadata and data, which are loaded from JSON files located in a directory specified by the entry parameter.

Expand source code
class PlayPassage(Chant):
    pass

Ancestors

Inherited members

class PrimeChantElement (data: list, children: list, index: tuple)

A dataclass representing a prime chant element, inheriting from the Division class.

Expand source code
@dataclass
class PrimeChantElement(Division):
    """
    A dataclass representing a prime chant element, inheriting from the `Division` class.
    """
    pass

Ancestors

Inherited members

class ProperTropeComplex (entry)

A class representing a trope complex.

Parameters

entry : str
The entry to initialize the ProperTropeComplex object.

Attributes

nums : list
List of signatures of trope elements
letters : list
List of signatures of prima chant elements
ct_volume : str or None
The Corpus Troporum Volume
ct_base_chant : str or None

Methods

get_ct_base_chant() Extracts the base chant from the meta.bibliographischerverweis attribute using regular expressions. get_ct_volume() Extracts the volume from the meta.bibliographischerverweis attribute using regular expressions. get_nums() -> list Extracts numbers from the meta.bibliographischerverweis attribute and returns them as a list of integers. get_letters() -> list Extracts uppercase letters from the meta.bibliographischerverweis attribute and returns them as a list of strings. get_trope_elements() -> list Returns a list of divisions from the data.elements attribute of the Document whose status is "Tropenelement". get_primechant_elements() -> list Returns a list of divisions from the data.elements attribute of the Document whose status is "Einsatzmarke" (prime chant elements).

Expand source code
class ProperTropeComplex(Chant):
    """
    A class representing a trope complex.

    Parameters
    ----------
    entry : str
        The entry to initialize the `ProperTropeComplex` object.

    Attributes
    ----------
    nums : list
        List of signatures of trope elements
    letters : list
        List of signatures of prima chant elements
    ct_volume : str or None
        The Corpus Troporum Volume
    ct_base_chant : str or None
        ...

    Methods
    -------
    get_ct_base_chant()
        Extracts the base chant from the `meta.bibliographischerverweis` attribute using regular expressions.
    get_ct_volume()
        Extracts the volume from the `meta.bibliographischerverweis` attribute using regular expressions.
    get_nums() -> list
        Extracts numbers from the `meta.bibliographischerverweis` attribute and returns them as a list of integers.
    get_letters() -> list
        Extracts uppercase letters from the `meta.bibliographischerverweis` attribute and returns them as a list of strings.
    get_trope_elements() -> list
        Returns a list of divisions from the `data.elements` attribute of the `Document` whose status is "Tropenelement".
    get_primechant_elements() -> list
        Returns a list of divisions from the `data.elements` attribute of the `Document` whose status is "Einsatzmarke" (prime chant elements).
    """

    def __init__(self, entry):
        super().__init__(entry)
        self.nums = self.get_nums()
        self.letters = self.get_letters()
        self.ct_volume = self.get_ct_volume()
        self.ct_base_chant = self.get_ct_base_chant()

    def get_ct_base_chant(self):
        base_chant_match = re.search(r'^.*?(?=\s(?:\d|A))', self.meta.bibliographical_reference)
        return base_chant_match.group(0) if base_chant_match else None

    def get_ct_volume(self):
        volume_match = re.search(r'\(CT\s(\w+)\)$', self.meta.bibliographical_reference)
        return volume_match.group(1) if volume_match else None

    def get_nums(self) -> list:
        return [int(number) for number in re.findall(r"\d+", self.meta.bibliographical_reference)]

    def get_letters(self) -> list:
        return [letter for letter in self.meta.bibliographical_reference.split() if
                len(letter) == 1 and letter.isupper()]

    def get_trope_elements(self):
        return [division for division in self.data.elements if division.status == "Tropenelement"]

    def get_primechant_elements(self):
        return [division for division in self.data.elements if
                division.status == "Einsatzmarke"]  # Does not distinguish between complete and abbreviated (Einsatzmarke) prime chant elements

Ancestors

Methods

def get_ct_base_chant(self)
Expand source code
def get_ct_base_chant(self):
    base_chant_match = re.search(r'^.*?(?=\s(?:\d|A))', self.meta.bibliographical_reference)
    return base_chant_match.group(0) if base_chant_match else None
def get_ct_volume(self)
Expand source code
def get_ct_volume(self):
    volume_match = re.search(r'\(CT\s(\w+)\)$', self.meta.bibliographical_reference)
    return volume_match.group(1) if volume_match else None
def get_letters(self) ‑> list
Expand source code
def get_letters(self) -> list:
    return [letter for letter in self.meta.bibliographical_reference.split() if
            len(letter) == 1 and letter.isupper()]
def get_nums(self) ‑> list
Expand source code
def get_nums(self) -> list:
    return [int(number) for number in re.findall(r"\d+", self.meta.bibliographical_reference)]
def get_primechant_elements(self)
Expand source code
def get_primechant_elements(self):
    return [division for division in self.data.elements if
            division.status == "Einsatzmarke"]  # Does not distinguish between complete and abbreviated (Einsatzmarke) prime chant elements
def get_trope_elements(self)
Expand source code
def get_trope_elements(self):
    return [division for division in self.data.elements if division.status == "Tropenelement"]

Inherited members

class Sequence (entry_path)

A class representing a document or unit of medieval chant.

A document is represented by its metadata and data, which are loaded from JSON files located in a directory specified by the entry parameter.

Expand source code
class Sequence(Chant):
    pass

Ancestors

Inherited members

class Song (entry_path)

A class representing a document or unit of medieval chant.

A document is represented by its metadata and data, which are loaded from JSON files located in a directory specified by the entry parameter.

Expand source code
class Song(Chant):
    pass

Ancestors

Inherited members

class TropeElement (data: list, children: list, index: tuple)

A dataclass representing a trope element, inheriting from the Division class.

Expand source code
@dataclass
class TropeElement(Division):
    """
    A dataclass representing a trope element, inheriting from the `Division` class.
    """
    pass

Ancestors

Inherited members