From 6f14ded166e35879e0522f2e62347a3a709518e4 Mon Sep 17 00:00:00 2001 From: Houyhnhnm Date: Sun, 3 Jun 2018 19:34:34 +0200 Subject: feature unification, spellout --- lexicon.py | 3 ++- main.py | 6 +++--- passage.py | 6 ++++-- spec.py | 19 +++++++++++++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lexicon.py b/lexicon.py index c7eef6a..cd6d90a 100644 --- a/lexicon.py +++ b/lexicon.py @@ -35,7 +35,7 @@ class Lexicon(object): def nextLabel(self): nextLabel = 0 if len(self.categories) > 0: - lexeme = self.categories[-1].label + 1 + nextLabel = self.categories[-1].label + 1 return nextLabel def print(self): @@ -62,6 +62,7 @@ class Lexeme(object): self.label = 'unlabeled' def print(self): + print("\n"+str(self.label)) self.cadence.print() print("anticipation:", self.anticipation) print("prolongation:", self.prolongation) diff --git a/main.py b/main.py index 7cf66a2..478c535 100644 --- a/main.py +++ b/main.py @@ -30,14 +30,14 @@ lexicon.populate(g, 4) lexicon.print() passage = Passage(size=12) -passage.printSyntax() realization = passage.spellout(lexicon) - -pprint(realization) +passage.printSyntax() for lex in realization: lex.print() +# next: go through spellout, create musical data, append to music21 score +# then: add good lexemes, dependency of good lexeme pairs to lexicon pre-population, iteratively... diff --git a/passage.py b/passage.py index e88926e..b95ad2c 100644 --- a/passage.py +++ b/passage.py @@ -16,15 +16,16 @@ class Passage(object): for i, node in enumerate(self.tree.levelorder): node.value = i node.unify = {} + self.unified = [] def printSyntax(self): print(self.tree) def spellout(self, lexicon): - # prolonged features trickle down to leaves for node in self.tree.levelorder: node.lexeme = lexicon.selectLexeme() + node.value = node.lexeme.label if node.left: node.left.unify = copy(node.unify) @@ -49,7 +50,7 @@ class Passage(object): spellout = [] # now read out nodes into list, with prolonged features replacing lexical features - for node in self.tree.levelorder: + for node in self.tree.inorder: next_lexeme = deepcopy(node.lexeme) for feat in node.unify.keys(): if feat == 'footprint': @@ -59,6 +60,7 @@ class Passage(object): if feat in ['range','figure','tilt']: next_lexeme.cadence.path[feat] = node.unify[feat] spellout.append(next_lexeme) + self.unified = spellout return spellout diff --git a/spec.py b/spec.py index 4125d97..65e6ec8 100644 --- a/spec.py +++ b/spec.py @@ -3,16 +3,26 @@ from grammar import * footprintRules = [ [{ 'span': [2], - 'gait': ['double','triple'], + 'gait': ['double'], 'foot': [[-1/2, 0, 1/2]], 'step': [[0, 1/2], [0, 1/2], [0, 1/2]], }], + [{ + 'span': [4], + 'gait': ['triple'], + 'foot': [[-1/2, 0, 1/2]], + 'step': [[0], [1/2], [0]], + }], ] functionRules = [ { 'address': ['A1','B1'], - 'transposition': [-1,0,1], + 'transposition': [-1], + }, + { + 'address': ['C1','D1'], + 'transposition': [0], }, ] @@ -22,6 +32,11 @@ pathRules = [ 'figure': ['rampUp', 'rampDown'], 'tilt': ['float', 'dive'], }, + { + 'range': [5,6,7], + 'figure': ['stepUp', 'stepDown'], + 'tilt': ['rise', 'fall'], + }, ] anticipationRules = [ -- cgit v1.2.3