class_docstr: Класс, реализующий взвешенный конечный преобразователь,
  осуществляющий замены из заданного списка операций
  
  Аргументы:
  ----------
  alphabet : list
      алфавит
  
  operation_costs : dict or None(optional, default=None)
      словарь вида {(up,low) : cost}
  
  allow_spaces : bool(optional, default=False)
      разрешены ли элементы трансдукции, содержащие пробел
      (используется только если явно не заданы operation costs
      и они равны значению по умолчанию)
class_docstr_tok: ["\u041a\u043b\u0430\u0441\u0441",",","\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439","\u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u044b\u0439","\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439","\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c",",","\u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0449\u0438\u0439","\u0437\u0430\u043c\u0435\u043d\u044b","\u0438\u0437","\u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e","\u0441\u043f\u0438\u0441\u043a\u0430","\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439","\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b",":","--","--","--","--","--","alphabet",":","list","\u0430\u043b\u0444\u0430\u0432\u0438\u0442","operation_costs",":","dict","or","None","(","optional",",","default=None",")","\u0441\u043b\u043e\u0432\u0430\u0440\u044c","\u0432\u0438\u0434\u0430","{","(","up",",","low",")",":","cost","}","allow_spaces",":","bool","(","optional",",","default=False",")","\u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u044b","\u043b\u0438","\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u0438",",","\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435","\u043f\u0440\u043e\u0431\u0435\u043b","(","\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f","\u0442\u043e\u043b\u044c\u043a\u043e","\u0435\u0441\u043b\u0438","\u044f\u0432\u043d\u043e","\u043d\u0435","\u0437\u0430\u0434\u0430\u043d\u044b","operation","costs","\u0438","\u043e\u043d\u0438","\u0440\u0430\u0432\u043d\u044b","\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e","\u043f\u043e","\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e",")"]
docstr: Вычисляет трансдукцию минимальной стоимости,
  отображающую first в second
  
  Аргументы:
  -----------
  first : string
  second : string
      Верхний и нижний элементы трансдукции
  
  return_transduction : bool (optional, default=False)
      следует ли возвращать трансдукцию минимального веса
      (см. возвращаемое значение)
  
  Возвращает:
  -----------
  (final_cost, transductions) : tuple(float, list)
      если return_transduction=True, то возвращает
      минимальную стоимость трансдукции, переводящей first в second
      и список трансдукций с данной стоимостью
  
  final_cost : float
      если return_transduction=False, то возвращает
      минимальную стоимость трансдукции, переводящей first в second
docstr_tok: ["\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u044e","\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439","\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438",",","\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0443\u044e","first","\u0432","second","\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b",":","--","--","--","--","--","-","first",":","string","second",":","string","\u0412\u0435\u0440\u0445\u043d\u0438\u0439","\u0438","\u043d\u0438\u0436\u043d\u0438\u0439","\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u0438","return_transduction",":","bool","(","optional",",","default=False",")","\u0441\u043b\u0435\u0434\u0443\u0435\u0442","\u043b\u0438","\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u044e","\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e","\u0432\u0435\u0441\u0430","(","\u0441\u043c",".","\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435","\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435",")","\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442",":","--","--","--","--","--","-","(","final_cost",",","transductions",")",":","tuple","(","float",",","list",")","\u0435\u0441\u043b\u0438","return_transduction=True",",","\u0442\u043e","\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442","\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e","\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u0438",",","\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044f\u0449\u0435\u0439","first","\u0432","second","\u0438","\u0441\u043f\u0438\u0441\u043e\u043a","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u0439","\u0441","\u0434\u0430\u043d\u043d\u043e\u0439","\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c\u044e","final_cost",":","float","\u0435\u0441\u043b\u0438","return_transduction=False",",","\u0442\u043e","\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442","\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e","\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c","\u0442\u0440\u0430\u043d\u0441\u0434\u0443\u043a\u0446\u0438\u0438",",","\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044f\u0449\u0435\u0439","first","\u0432","second"]
code: def distance(self, first, second, return_transduction=False):
      """
      Вычисляет трансдукцию минимальной стоимости,
      отображающую first в second
  
      Аргументы:
      -----------
      first : string
      second : string
          Верхний и нижний элементы трансдукции
  
      return_transduction : bool (optional, default=False)
          следует ли возвращать трансдукцию минимального веса
          (см. возвращаемое значение)
  
      Возвращает:
      -----------
      (final_cost, transductions) : tuple(float, list)
          если return_transduction=True, то возвращает
          минимальную стоимость трансдукции, переводящей first в second
          и список трансдукций с данной стоимостью
  
      final_cost : float
          если return_transduction=False, то возвращает
          минимальную стоимость трансдукции, переводящей first в second
      """
      if return_transduction:
          add_pred = lambda x, y: (y == np.inf or x < y)
      else:
          add_pred = lambda x, y: (y == np.inf or x <= y)
      clear_pred = lambda x, y: x < y < np.inf
      update_func = lambda x, y: min(x, y)
      costs, backtraces = self._fill_levenshtein_table(
          first, second, update_func, add_pred, clear_pred
      )
      final_cost = costs[-1][-1]
      if final_cost == np.inf:
          transductions = [None]
      elif return_transduction:
          transductions = self._backtraces_to_transductions(
              first, second, backtraces, final_cost, return_cost=False
          )
      if return_transduction:
          return final_cost, transductions
      else:
          return final_cost
  
imports: import copy
  import itertools
  import numpy
  from sortedcontainers import SortedListWithKey
  from .tabled_trie import Trie, make_trie
label_desc: Use image node_id 4 for calling the SegmentTransducer obj's underlying member method code with example usage: obj.distance(first, second, return_transduction) and returns: final_cost,  transductions, final_cost