Skip to content
Snippets Groups Projects
Commit 92d36906 authored by Simon Will's avatar Simon Will
Browse files

Begin implementing meters

parent 42d41352
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
ALL_METERS = []
import re
from .model import Reading
def caesurae_together(positions, reward):
def get_reward(meter: Meter, reading: Reading):
# TODO: Check if caesurae occur.
return reward
return get_reward
def bridge(position, reward):
def get_reward(meter: Meter, reading: Reading):
# TODO: Check if bridge occurs.
return reward
return get_reward
class Meter:
def __init__(self, name: str, schema: str, conditions: list = None,
short_name: str = None):
self.name = name
self.schema = schema
self.conditions = ([cond.__get__(self) for cond in conditions]
if conditions else [])
self.short_name = short_name
def match_reading(self, reading: Reading):
return re.match(self.schema, reading.get_syllable_schema())
def get_rewards(self, reading: Reading):
return sum(cond(reading) for cond in self.conditions)
ALL_METERS = [
Meter(
'Catalectic Dactylic Hexameter',
r'(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(–)(⏑⏑|–)(⏑|–)',
phenomena={
caesurae_together([('mora', 6, 'Trithemimeral'),
('mora', 14, 'Hephthemimeral')], 2),
caesurae_together([('mora', 10, 'Penthemimeral')], 1),
caesurae_together([('mora', 16, 'Bucolic Diaeresis')], 1),
bridge(('mora', 15, 'Hermann’s Bridge'), 1)
},
short_name='6da‸'
),
Meter(
'Iambic Trimeter',
r'(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑⏑|–)(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑⏑|–)(⏑|⏑⏑|–)(⏑⏑|–)(⏑)(⏑|–)',
phenomena={
caesurae_together([('element', 4, 'After fourth element')], 1),
caesurae_together([('element', 8, 'After eighth element')], 1),
},
short_name='3ia'
),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment