diff options
| author | Houyhnhnm <hykusb@bitmai.la> | 2018-06-03 18:47:29 +0200 |
|---|---|---|
| committer | Houyhnhnm <hykusb@bitmai.la> | 2018-06-03 18:47:29 +0200 |
| commit | 01071c8123e6b30eeff88272bf4fc7325d62dd5a (patch) | |
| tree | 9598b4cc53546df62804e672e3c14215edf8ee94 /lexicon.py | |
| parent | 3786e330479d00517ecb894804180f59b0544e1a (diff) | |
added syntax tree generation, feature unification
Diffstat (limited to 'lexicon.py')
| -rw-r--r-- | lexicon.py | 77 |
1 files changed, 54 insertions, 23 deletions
@@ -3,40 +3,71 @@ from numpy.random import choice, seed class Lexicon(object): - def __init__(self, genesis_size=0): + def __init__(self): self.categories = [] - def generate(self, grammar, number_categories=0): - for x in range(number): - cadence = - anticipation = - prolongation = - lexeme = Lexeme(cadence, anticipation, prolongation) - self + def populate(self, grammar, number_categories=0): + for x in range(number_categories): + lexeme = self.makeLexeme(grammar) + lexeme.label = self.nextLabel() + self.categories.append(lexeme) + + def addLexeme(self, grammar, lexeme=None): + if lexeme == None: + lexeme = self.makeLexeme(grammar) + lexeme.label = self.nextLabel() + self.categories.append(lexeme) + + def makeLexeme(self, grammar): + cadence = grammar.phonology.makeCadence() + anticipation = grammar.morphology.selectAnticipation() + prolongation = grammar.morphology.selectProlongation() + lexeme = Lexeme(cadence, anticipation, prolongation) + return lexeme + + def selectLexeme(self, index=None): + if index == None: + lexeme = choice(self.categories) + else: + lexeme = self.categories[index] + return lexeme + + def nextLabel(self): + nextLabel = 0 + if len(self.categories) > 0: + lexeme = self.categories[-1].label + 1 + return nextLabel + + def print(self): + for i, lex in enumerate(self.categories): + print('Lexeme', str(i)) + print('--------') + lex.print() + print() - def addLexeme(): - - def makeCategory(): - - - def makeLexeme(cadence, anticipation=None, prolongation=None): - - - def makeProjection(self): - pass class Lexeme(object): """the specification of an dependant and its agreement""" - def __init__(self, cadence=None, anticipation=None, prolongation=None): - if cadence=None: + def __init__(self, cadence, anticipation=None, prolongation=None): self.cadence = cadence - # lexemes - self.antecedents = [] - self.consequents = [] + # projections self.anticipation = anticipation self.prolongation = prolongation + # dependents + self.antecedents = [] + self.consequents = [] + + self.label = 'unlabeled' + + def print(self): + self.cadence.print() + print("anticipation:", self.anticipation) + print("prolongation:", self.prolongation) + print("antecedents:", self.antecedents) + print("consequents:", self.consequents) + def addAntecedent(self, category): self.antecedents.append(category) return self |