# Path: grafeno/transformers/sim_link.py
# class Transformer (WNGet):
# 
#     def __init__ (self, sim_threshold = 0.1, sim_weight = 1, **kwds):
#         global brown_ic
#         super().__init__(**kwds)
#         if not brown_ic:
#             brown_ic = wordnet_ic.ic('ic-brown.dat')
#         self.__threshold = sim_threshold
#         self.__weight = sim_weight
# 
#     def get_similarity (self, a, b):
#         if 'synset' not in a or 'synset' not in b \
#                 or a.get('sempos','x') != b.get('sempos','-'):
#             return 0
#         sa = a['synset']
#         sb = b['synset']
#         return sa.jcn_similarity(sb, brown_ic)
# 
#     def post_insertion (self, sentence_nodes):
#         super().post_insertion(sentence_nodes)
#         g = self.graph
#         threshold = self.__threshold
#         weight = self.__weight
#         oldnodes = set(g.node.keys())-set(sentence_nodes)
#         for n, m in product(sentence_nodes, oldnodes):
#             if m == n:
#                 continue
#             sim = self.get_similarity(g.node[n], g.node[m])
#             if sim > threshold:
#                 g.add_edge(n, m, 'SIM', weight=weight)
#                 g.add_edge(m, n, 'SIM', weight=weight)


import pexpect
from grafeno.transformers.sim_link import Transformer as SimLink


class Transformer (SimLink):

    def __init__ (self, sim_threshold = 100, sim_weight = 1, **kwds):
        super().__init__(sim_threshold=sim_threshold, sim_weight=sim_weight, **kwds)
        self.__child = pexpect.spawn("/usr/bin/env WNSEARCHDIR=/usr/share/wordnet similarity.pl --type WordNet::Similarity::lesk --interact")
        self.__child.delaybeforesend = 0

    def get_similarity (self, a, b):
        child = self.__child
        sa = a['concept']
        sb = b['concept']
        child.expect("Concept #1:")

# Path: grafeno/transformers/sim_link.py
# class Transformer (WNGet):
# 
#     def __init__ (self, sim_threshold = 0.1, sim_weight = 1, **kwds):
#         global brown_ic
#         super().__init__(**kwds)
#         if not brown_ic:
#             brown_ic = wordnet_ic.ic('ic-brown.dat')
#         self.__threshold = sim_threshold
#         self.__weight = sim_weight
# 
#     def get_similarity (self, a, b):
#         if 'synset' not in a or 'synset' not in b \
#                 or a.get('sempos','x') != b.get('sempos','-'):
#             return 0
#         sa = a['synset']
#         sb = b['synset']
#         return sa.jcn_similarity(sb, brown_ic)
# 
#     def post_insertion (self, sentence_nodes):
#         super().post_insertion(sentence_nodes)
#         g = self.graph
#         threshold = self.__threshold
#         weight = self.__weight
#         oldnodes = set(g.node.keys())-set(sentence_nodes)
#         for n, m in product(sentence_nodes, oldnodes):
#             if m == n:
#                 continue
#             sim = self.get_similarity(g.node[n], g.node[m])
#             if sim > threshold:
#                 g.add_edge(n, m, 'SIM', weight=weight)
#                 g.add_edge(m, n, 'SIM', weight=weight)


# Path: grafeno/transformers/lesk_link.py
import pexpect
from grafeno.transformers.sim_link import Transformer as SimLink



class Transformer (SimLink):

    def __init__ (self, sim_threshold = 100, sim_weight = 1, **kwds):
        super().__init__(sim_threshold=sim_threshold, sim_weight=sim_weight, **kwds)
        self.__child = pexpect.spawn("/usr/bin/env WNSEARCHDIR=/usr/share/wordnet similarity.pl --type WordNet::Similarity::lesk --interact")
        self.__child.delaybeforesend = 0

    def get_similarity (self, a, b):
        child = self.__child
        sa = a['concept']
        sb = b['concept']
        child.expect("Concept #1:")

        child.sendline(sa)