Syntax.py 954 Bytes
#! /usr/bin/python
# -*- coding: utf-8 -*-

from Schema import Schema


def analyze_tree(tree):

    phrases = {}
    schemata = []
    
    for schema_tree in tree._children[0]._children[0]._children:
        schema = Schema.fromTree(schema_tree)
        schemata.append(schema)
        phrases.update(schema.getPhraseIds())
        
    return phrases, schemata
        

class Syntax:

    def __init__(self, phrases, schemata):
        self._phrases = phrases
        self._schemata = schemata
        self._fake = fake

    @classmethod
    def fromTree(cls, syntax_tree):
        phrases, schemata = analyze_tree(syntax_tree)
        return cls(phrases, schemata)

    def getPhraseIds(self):
        return self._phrases

    def store(self, entry):
        for schema in self._schemata:
            schema.store(entry)
    
    def __unicode__(self):
        return '[' + ','.join([unicode(schema) for schema in self._schemata]) + ']'