Skip to content
Snippets Groups Projects
model.py 2.76 KiB
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import List
import numpy as np


class Verse:
    
    self.readings = list()
    self.author = None
    self.work = None
    self.place = None
    
    def __init__(self, verse:str, 
                 readings:List[Reading] = list()):
        self.text = verse
        if readings = None:
            pass
        else:
            self.readings = readings
        
    def set_author(author:str):
        self.author = author
        
    def set_work(work:str):
        self.work = work
        
    def set_place(place:str):
        self.place = place
        
        
class Reading:
    
    self.tokens = list()
    
    def __init__(self, tokens:List[Token]):
        self.tokens = tokens
    
    
class Token:
    
    def __init__(self, token:str, span:List[int],
                 syllables:List[Syllable]=list):
        if len(token) != span[1]-span[0]:
            raise ValueError('Token length does not match token span.')
        else:
            self.text = token
            self.span = span
            self.syllables = syllables


class Syllable:

    def __init__(self, syllable:str,
                 span:List[int], idx:int,
                 syllable_length:int, vowel_length:int,
                 phenomena:dict=dict()):
        if len(syllable) != span[1]-span[0]:
            raise ValueError('Syllable length does not match syllable span.')
        else:
            self.text = syllable
            self.span = span
            self.id = idx
            self.syllable_length = syllable_length
            self.vowel_length = vowel_length
            self.phenomena = phenomena
            
        
class Phenomenon:
    
    def __init__(self, name:str, caused_by=False, overruled_by=False):
        self.name = name
        self.caused_by = caused_by
        self.overruled_by = overruled_by

class PositionalLengthening(Phenomenon):
    def __init__(self, chars:str):
        Phenomenon.__init__(self, 'positional lengthening')
        self.chars = chars
        
class IambicShortening(Phenomenon):
    def __init__(self, typus:str):
        Phenomenon.__init__(self, 'iambic shortening')
        self.typus = typus
        
class S_Elision(Phenomenon):
    def __init__(self):
        Phenomenon.__init__(self, 's-elision')
        omitted = 's'

class VerseEnd(Phenomenon):
Victor Zimmermann's avatar
Victor Zimmermann committed
    def __init__(self):
        Phenomenon.__init__(self,'verse end')
        

class MultisyllablePhenomenon(Phenomenon):
    
    def __init__(self, name:str, beginning:int, end:int):
        Phenomenon.__init__(self, name)
        self.beginning = beginning
        self.end = end
      
class Apheresis(MultisyllablePhenomenon):
    def __init__(self,beginning,end):
        MultisyllablePhenomenon.__init__(self, 'apheresis', beginning, end)