# 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

        #check if current head matches the head of the pattern
        if not eval(pat.node):
            return False
        #mark head as matching pattern's head
        ret = [self]
        
        # find a child matching each of the pattern's children
        availableChildren = [(i,c) for i,c in enumerate(self.children)]
        lastMatch = -1
        for c_pat in pat:
            for i,c_t in availableChildren:
                successor = False
                if c_pat.node.startswith("$+"):
                    successor = True
                    c_pat.node = c_pat.node[2:]
                curMatch = c_t.match(c_pat)
                if curMatch:
                    if successor:
                        if i-lastMatch != 1:
                            return False
                    lastMatch = i
                    ret.append(curMatch)
                    availableChildren.remove((i,c_t))
                    break
            if not curMatch: 
                return False
        return ret
    
    
    def get_text(self):

# 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

        #check if current head matches the head of the pattern
        if not eval(pat.node):
            return False
        #mark head as matching pattern's head
        ret = [self]
        
        # find a child matching each of the pattern's children
        availableChildren = [(i,c) for i,c in enumerate(self.children)]
        lastMatch = -1
        for c_pat in pat:
            for i,c_t in availableChildren:
                successor = False
                if c_pat.node.startswith("$+"):
                    successor = True
                    c_pat.node = c_pat.node[2:]
                curMatch = c_t.match(c_pat)
                if curMatch:
                    if successor:
                        if i-lastMatch != 1:
                            return False
                    lastMatch = i
                    ret.append(curMatch)
                    availableChildren.remove((i,c_t))
                    break
            if not curMatch: 
                return False
        return ret
    
    
    def get_text(self):

        ret = [Word(index=self.id,word=self.word)]
