Esempio n. 1
0
def convert(message):
    """ Convert input text and return output
    """
    transducers = []
    for mapping in message['data']['mappings']:
        mappings_obj = Mapping(hot_to_mappings(mapping['mapping']),
                               abbreviations=flatten_abbreviations(
                                   mapping['abbreviations']),
                               **mapping['kwargs'])
        transducer = Transducer(mappings_obj)
        transducers.append(transducer)
    transducer = CompositeTransducer(transducers)
    if message['data']['index']:
        tg = transducer(message['data']['input_string'])
        data, links = return_echart_data(tg)
        emit(
            'conversion response', {
                'output_string': tg.output_string,
                'index_data': data,
                'index_links': links
            })
    else:
        output_string = transducer(
            message['data']['input_string']).output_string
        emit('conversion response', {'output_string': output_string})
Esempio n. 2
0
def convert(message):
    """ Convert input text and return output
    """
    mappings = Mapping(hot_to_mappings(message['data']['mappings']),
                       abbreviations=flatten_abbreviations(
                           message['data']['abbreviations']),
                       **message['data']['kwargs'])
    transducer = Transducer(mappings)
    output_string = transducer(message['data']['input_string'])
    emit('conversion response', {'output_string': output_string})
Esempio n. 3
0
 def test_abb_flatten_and_expand(self):
     test_rows = [["VOWEL", 'a', 'e', 'i', 'o', 'u'],
                  ["OTHER", 't', 'e', 's', 't']]
     default_dict = defaultdict(list)
     default_dict['VOWEL'].extend(['a', 'e', 'i', 'o', 'u'])
     default_dict['OTHER'].extend(['t', 'e', 's', 't'])
     empty_rows = []
     while len(empty_rows) < 10:
         empty_rows.append(['', '', '', '', '', ''])
     self.assertEqual(utils.flatten_abbreviations(test_rows), default_dict)
     self.assertEqual(utils.expand_abbreviations(default_dict), test_rows)
     self.assertEqual(utils.expand_abbreviations({}), empty_rows)
Esempio n. 4
0
def index_convert(message):
    """ Convert input text and return output with indices for echart
    """
    mappings = Mapping(hot_to_mappings(message['data']['mappings']),
                       abbreviations=flatten_abbreviations(
                           message['data']['abbreviations']),
                       **message['data']['kwargs'])
    transducer = Transducer(mappings)
    output_string, indices = transducer(message['data']['input_string'],
                                        index=True)
    data, links = return_echart_data(indices)
    emit('index conversion response', {
        'output_string': output_string,
        'index_data': data,
        'index_links': links
    })