# Path: props/graph_representation/graphParsingException.py
# class GraphParsingException(Exception):
#     """
#     Exception to identify errors coming from the graph parsing process
#     """
#     pass
# 
# Path: props/graph_representation/word.py
# class Word:
#     """
#     word container class, to add the index of the word in addition to the word 
#     
#     @type index: int
#     @var  index: the index of the word within the sentence
#     
#     @type text: string
#     @var  text: the text contained within this word
#     """
#     
#     def __init__(self,index,word):
#         """
#         initialize a word container object
#         """
#         self.index = index
#         self.word = word
#     
#     def to_conll_like(self):
#         return ",".join([str(self.index),self.word])
#     
#     def __str__(self):
#         ret = cgi.escape(self.word)
#         if self.index != NO_INDEX:
#             ret += '<FONT POINT-SIZE="7">[{0}]</FONT>'.format(self.index)
#         return ret
#     
#     def __eq__(self,other_word):
#         return (self.index == other_word.index) and (self.word == other_word.word)
#     
#     def __hash__(self):
#         return self.__str__().__hash__()
# 
# Path: props/constituency_tree/my_definitions.py
# ADVERBIALS = ["ADV", "VOC", "BNF", "DIR", "EXT", "LOC", "MNR", "TMP", "CLR","PRP"]


from __builtin__ import dir
from props.graph_representation.graphParsingException import GraphParsingException
from nltk.tree import Tree
from props.graph_representation.word import Word
from props.dependency_tree.definitions import *
from props.constituency_tree.definitions import *
from props.constituency_tree.my_definitions import any_in
from Tense import tense_rules
        from nltk import Tree
        from nltk.stem.wordnet import WordNetLemmatizer
import copy,os

                
                    
            elif child.parent_relation == 'conj':
                conjElements.append(child)              
        
        if cc:
            self.conjResult.append((copy.copy(cc),copy.copy(conjElements)))
        
        return True
        
    def _PREPOSITIONAL_PREDICATE_FEATURE_psubj(self):
        childrenCopy = [x for x in self.children]
        self.children = [x for i,x in enumerate(self.children) if i not in self.prepChildIndList]
        #self.children.remove(self.children[self.possChild[0]])
        d = {}#self._get_subtree_nodes(includeHead = True)
        ret = {"Value":copy.copy(self),#self.get_original_sentence(False),
               "Span":d.keys()}
        self.children = childrenCopy
        return ret
    
    def _PREPOSITIONAL_PREDICATE_FEATURE_pobj(self):
        prepChild = self.children[self.prepChildInd]
        if not prepChild.children:
            return {"Value":False,
                    "Span":{}}
        pobjChildren = any_in([c.parent_relation for c in prepChild.children], ["pobj"])
        pcompChildren = any_in([c.parent_relation for c in prepChild.children], ["pcomp"])
        if (len(pobjChildren)>1) or (len(pcompChildren)>1):
            print pobjChildren
            print self.word

# Path: props/graph_representation/graphParsingException.py
# class GraphParsingException(Exception):
#     """
#     Exception to identify errors coming from the graph parsing process
#     """
#     pass
# 
# Path: props/graph_representation/word.py
# class Word:
#     """
#     word container class, to add the index of the word in addition to the word 
#     
#     @type index: int
#     @var  index: the index of the word within the sentence
#     
#     @type text: string
#     @var  text: the text contained within this word
#     """
#     
#     def __init__(self,index,word):
#         """
#         initialize a word container object
#         """
#         self.index = index
#         self.word = word
#     
#     def to_conll_like(self):
#         return ",".join([str(self.index),self.word])
#     
#     def __str__(self):
#         ret = cgi.escape(self.word)
#         if self.index != NO_INDEX:
#             ret += '<FONT POINT-SIZE="7">[{0}]</FONT>'.format(self.index)
#         return ret
#     
#     def __eq__(self,other_word):
#         return (self.index == other_word.index) and (self.word == other_word.word)
#     
#     def __hash__(self):
#         return self.__str__().__hash__()
# 
# Path: props/constituency_tree/my_definitions.py
# ADVERBIALS = ["ADV", "VOC", "BNF", "DIR", "EXT", "LOC", "MNR", "TMP", "CLR","PRP"]


# Path: props/dependency_tree/tree.py
from __builtin__ import dir
from props.graph_representation.graphParsingException import GraphParsingException
from nltk.tree import Tree
from props.graph_representation.word import Word
from props.dependency_tree.definitions import *
from props.constituency_tree.definitions import *
from props.constituency_tree.my_definitions import any_in
from Tense import tense_rules
        from nltk import Tree
        from nltk.stem.wordnet import WordNetLemmatizer
import copy,os

                
                    
            elif child.parent_relation == 'conj':
                conjElements.append(child)              
        
        if cc:
            self.conjResult.append((copy.copy(cc),copy.copy(conjElements)))
        
        return True
        
    def _PREPOSITIONAL_PREDICATE_FEATURE_psubj(self):
        childrenCopy = [x for x in self.children]
        self.children = [x for i,x in enumerate(self.children) if i not in self.prepChildIndList]
        #self.children.remove(self.children[self.possChild[0]])
        d = {}#self._get_subtree_nodes(includeHead = True)
        ret = {"Value":copy.copy(self),#self.get_original_sentence(False),
               "Span":d.keys()}
        self.children = childrenCopy
        return ret
    
    def _PREPOSITIONAL_PREDICATE_FEATURE_pobj(self):
        prepChild = self.children[self.prepChildInd]
        if not prepChild.children:
            return {"Value":False,
                    "Span":{}}
        pobjChildren = any_in([c.parent_relation for c in prepChild.children], ["pobj"])
        pcompChildren = any_in([c.parent_relation for c in prepChild.children], ["pcomp"])
        if (len(pobjChildren)>1) or (len(pcompChildren)>1):
            print pobjChildren
            print self.word

            print GraphParsingException("misproper handling for more than one pobj child " +self.report())
