# Path: grafeno/transformers/wordnet.py
# class Transformer (Base):
# 
#     def __init__ (self, **kwds):
#         super().__init__(**kwds)
#         self.wnlang = wordnet_langs[self.lang]
# 
#     def post_process (self):
#         super().post_process()
#         for n in self.nodes.values():
#             concept = n.get('concept')
#             if not concept:
#                 continue
#             pos = n.get('sempos')
#             if pos in {'n','v'}:
#                 ss = wn.synsets(concept, pos, lang=self.wnlang)
#             elif pos == 'j':
#                 ss = wn.synsets(concept, 'a', lang=self.wnlang)
#             else:
#                 ss = wn.synsets(concept, lang=self.wnlang)
#             if len(ss):
#                 # WSD by MFS
#                 n['synset'] = ss[0]


from itertools import product
from nltk.corpus import wordnet_ic
from grafeno.transformers.wordnet import Transformer as WNGet

brown_ic = None


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)

# Path: grafeno/transformers/wordnet.py
# class Transformer (Base):
# 
#     def __init__ (self, **kwds):
#         super().__init__(**kwds)
#         self.wnlang = wordnet_langs[self.lang]
# 
#     def post_process (self):
#         super().post_process()
#         for n in self.nodes.values():
#             concept = n.get('concept')
#             if not concept:
#                 continue
#             pos = n.get('sempos')
#             if pos in {'n','v'}:
#                 ss = wn.synsets(concept, pos, lang=self.wnlang)
#             elif pos == 'j':
#                 ss = wn.synsets(concept, 'a', lang=self.wnlang)
#             else:
#                 ss = wn.synsets(concept, lang=self.wnlang)
#             if len(ss):
#                 # WSD by MFS
#                 n['synset'] = ss[0]


# Path: grafeno/transformers/sim_link.py
from itertools import product
from nltk.corpus import wordnet_ic
from grafeno.transformers.wordnet import Transformer as WNGet


brown_ic = None


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