PhraseTypeExpansion.py
840 Bytes
#! /usr/bin/python
# -*- coding: utf-8 -*-
from Phrase import phrase_from_tree
def analyze_tree(tree):
opinion = tree._children[0]._children[0]._attrs['value']
phrases = [phrase_from_tree(tree._children[1]._children[0]._children[0])]
if len(tree._children[1]._children[0]._children) > 1:
print "ERR"
return opinion, phrases
class PhraseTypeExpansion:
def __init__(self, opinion, phrases):
self._phrases = phrases
self._opinion = opinion
@classmethod
def fromTree(cls, expansion_tree):
opinion, phrases = analyze_tree(expansion_tree)
return cls(opinion, phrases)
def __unicode__(self):
return '[' + ','.join([unicode(phrase) for phrase in self._phrases]) + ']'
def toUnicode(self, phrase_type):
return unicode(self)