# 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__()
# 
# NO_INDEX = -1 # index used in cases where there's no such word in the sentence
# 
# def strip_punctuations(ls):
#     """
#     removes punctuations from beginning and end of the list
#     """
#     puncts = ':.,;\t '
#     sep = "\t"
#     totalElms = len(ls)
#     s = sep.join([x.word for x in ls])
#     ret = ls[totalElms-len(s.lstrip(puncts).split(sep)):len(s.rstrip(puncts).split(sep))]
#     return ret
# 
# Path: props/dependency_tree/definitions.py
# REASON_LABEL = "reason"
# OUTCOME_LABEL = "outcome"
# EVENT_LABEL = "event"
# CONDITION_LABEL = "condition"
# FIRST_ENTITY_LABEL = "sameAs_arg"
# SECOND_ENTITY_LABEL = "sameAs_arg"
# POSSESSOR_LABEL = "possessor"
# POSSESSED_LABEL = "possessed"
# ARG_LABEL = "arg"
# POSS_LABEL = "poss"
# MARK_LABEL = "mark"
# EXPL_LABEL = 'expl'
# SOURCE_LABEL = 'source'
# MODIFIER_LABEL = "modifier"
# POSSESSIVE_LABEL = "possessive"
# SUBJ_LABEL  = "subj"
# OBJECT_LABEL = "obj"
# DIRECT_OBJECT_LABEL = "dobj"
# INDIRECT_OBJECT_LABEL = "iobj"
# VB = "VB"       #Verb, base form
# VBD = "VBD"     #Verb, past tense
# VBG = "VBG"     #Verb, gerund or present participle
# VBN = "VBN"     #Verb, past participle
# VBP = "VBP"     #Verb, non-3rd person singular present
# VBZ = "VBZ"     #Verb, 3rd person singular present
# VERB_POS = [VB,VBD,VBP,VBZ,VBN] # all types of verb pos
# TO = "TO"
# IN = "IN"
# MD = "MD"
# DOT = "."
# COMMA = ","
# TENSE_PAST = "past"
# TENSE_PRESENT = "present"
# TENSE_FUTURE = "future"
# TENSE_UNKNOWN = "unknown"
# WILL = "will"
# WONT = "wo"
# WOULD = "would"
# D = "'d"
# HAVE = "have"
# BE = "be"
# BEEN = "been"
# FUTURE_MODALS = [WILL, WONT, WOULD, ll, D, "may", "might"] # "wo" is the Modal part of "won't"
# AS = "as"
# COND_IF = "if"
# COND_AFTER = "after"
# def aux_children_with_pos(pos_tag):


from props.graph_representation.word import Word,NO_INDEX, strip_punctuations
from copy import deepcopy, copy
from props.dependency_tree.definitions import time_prep, definite_label,\
    adjectival_mod_dependencies
import cgi

    @return a node representing the union of both nodes
    """
    
    # join all values
    isPredicate = (node1.isPredicate or node2.isPredicate)
    text = list(set(node1.get_text(gr)).union(node2.get_text(gr)))
    original_text = list(set(node1.original_text).union(node2.original_text))
    surface_form = list(set(node1.surface_form).union(node2.surface_form))
    features = {}
    features.update(node1.features)
    features.update(node2.features)
    
    # remove contradicting features
    for k in set(node1.features).intersection(node2.features):
        if node1.features[k]!=node2.features[k]: 
                del(features[k])
                
    if isDefinite(node1) or isDefinite(node2):
        features["Definite"] = "definite" 
    
    # return new node
    ret = Node(isPredicate = isPredicate,
                text = text,
                features = features,
                gr = gr)
    ret.original_text = original_text
    ret.surface_form = surface_form
    return ret
    
def isDefinite(node):

# 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__()
# 
# NO_INDEX = -1 # index used in cases where there's no such word in the sentence
# 
# def strip_punctuations(ls):
#     """
#     removes punctuations from beginning and end of the list
#     """
#     puncts = ':.,;\t '
#     sep = "\t"
#     totalElms = len(ls)
#     s = sep.join([x.word for x in ls])
#     ret = ls[totalElms-len(s.lstrip(puncts).split(sep)):len(s.rstrip(puncts).split(sep))]
#     return ret
# 
# Path: props/dependency_tree/definitions.py
# REASON_LABEL = "reason"
# OUTCOME_LABEL = "outcome"
# EVENT_LABEL = "event"
# CONDITION_LABEL = "condition"
# FIRST_ENTITY_LABEL = "sameAs_arg"
# SECOND_ENTITY_LABEL = "sameAs_arg"
# POSSESSOR_LABEL = "possessor"
# POSSESSED_LABEL = "possessed"
# ARG_LABEL = "arg"
# POSS_LABEL = "poss"
# MARK_LABEL = "mark"
# EXPL_LABEL = 'expl'
# SOURCE_LABEL = 'source'
# MODIFIER_LABEL = "modifier"
# POSSESSIVE_LABEL = "possessive"
# SUBJ_LABEL  = "subj"
# OBJECT_LABEL = "obj"
# DIRECT_OBJECT_LABEL = "dobj"
# INDIRECT_OBJECT_LABEL = "iobj"
# VB = "VB"       #Verb, base form
# VBD = "VBD"     #Verb, past tense
# VBG = "VBG"     #Verb, gerund or present participle
# VBN = "VBN"     #Verb, past participle
# VBP = "VBP"     #Verb, non-3rd person singular present
# VBZ = "VBZ"     #Verb, 3rd person singular present
# VERB_POS = [VB,VBD,VBP,VBZ,VBN] # all types of verb pos
# TO = "TO"
# IN = "IN"
# MD = "MD"
# DOT = "."
# COMMA = ","
# TENSE_PAST = "past"
# TENSE_PRESENT = "present"
# TENSE_FUTURE = "future"
# TENSE_UNKNOWN = "unknown"
# WILL = "will"
# WONT = "wo"
# WOULD = "would"
# D = "'d"
# HAVE = "have"
# BE = "be"
# BEEN = "been"
# FUTURE_MODALS = [WILL, WONT, WOULD, ll, D, "may", "might"] # "wo" is the Modal part of "won't"
# AS = "as"
# COND_IF = "if"
# COND_AFTER = "after"
# def aux_children_with_pos(pos_tag):


# Path: props/graph_representation/newNode.py
from props.graph_representation.word import Word,NO_INDEX, strip_punctuations
from copy import deepcopy, copy
from props.dependency_tree.definitions import time_prep, definite_label,\
    adjectival_mod_dependencies
import cgi

    @return a node representing the union of both nodes
    """
    
    # join all values
    isPredicate = (node1.isPredicate or node2.isPredicate)
    text = list(set(node1.get_text(gr)).union(node2.get_text(gr)))
    original_text = list(set(node1.original_text).union(node2.original_text))
    surface_form = list(set(node1.surface_form).union(node2.surface_form))
    features = {}
    features.update(node1.features)
    features.update(node2.features)
    
    # remove contradicting features
    for k in set(node1.features).intersection(node2.features):
        if node1.features[k]!=node2.features[k]: 
                del(features[k])
                
    if isDefinite(node1) or isDefinite(node2):
        features["Definite"] = "definite" 
    
    # return new node
    ret = Node(isPredicate = isPredicate,
                text = text,
                features = features,
                gr = gr)
    ret.original_text = original_text
    ret.surface_form = surface_form
    return ret
    
def isDefinite(node):

    return node.features.get("Definite",False) == definite_label
