Пример #1
0
    def __get_handlers(self, vb, target):
        if (vb.lemma_, target.lemma_) in self._handlers:
            return self._handlers[(vb.lemma_, target.lemma_)]

        from gitgud.nlp import nlp

        handlers = [(nlp(k[0])[0].similarity(vb), nlp(k[1])[0].similarity(target), v) for k, v in self._handlers.items()]
        handlers = sorted(handlers, reverse=True, key=lambda x: x[0] * 10 + x[1])

        if not handlers:
            return [default_handler]

        sim_vb, sim_tgt, handler = handlers[0]
        return handler if sim_vb > 0.65 and sim_tgt > 0.65 else [default_handler]
Пример #2
0
    def __get_handlers(self, vb):
        if vb.lemma_ in self._handlers:
            return self._handlers[vb.lemma_]

        from gitgud.nlp import nlp

        handlers = [(nlp(k)[0].similarity(vb), v) for k, v in self._handlers.items()]
        handlers = sorted(handlers, reverse=True, key=lambda x: x[0])

        if not handlers:
            return [default_handler]

        sim, handler = handlers[0]
        return handler if sim > 0.65 else [default_handler]