def test_mixed_unicode(self):
        result = zero_digits(u'P.1, АБ1, ЯК12x, м²')
        expected = tf.convert_to_tensor(u'P.0, АБ0, ЯК00x, м²',
                                        dtype=tf.string)

        expected, result = self.evaluate([expected, result])
        self.assertEqual(expected, result)
    def test_ragged(self):
        source = tf.ragged.constant([['x1', '2x'], ['3x4']])
        expected = tf.constant([['x0', '0x'], ['0x0', '']])
        result = zero_digits(source).to_tensor(default_value='')

        expected, result = self.evaluate([expected, result])
        self.assertAllEqual(expected, result)
    def test_inference_shape(self):
        source = [
            ['1', '2', '3'],
            ['4', '5', '6'],
        ]
        result = zero_digits(source)

        self.assertAllEqual([2, 3], result.shape.as_list())
    def test_actual_shape(self):
        source = [
            ['1', '2', '3'],
            ['4', '5', '6'],
        ]
        result = zero_digits(source)
        result = tf.shape(result)

        result = self.evaluate(result)
        self.assertAllEqual([2, 3], result.tolist())
Esempio n. 5
0
def ngram_features(input_words, minn, maxn):
    input_words = normalize_unicode(input_words, 'NFKC')
    input_words = replace_string(  # accentuation
        input_words,
        [u'\u0060', u' \u0301', u'\u02CA', u'\u02CB', u'\u0300', u'\u0301'],
        [''] * 6)
    input_words = lower_case(input_words)
    input_words = zero_digits(input_words)
    input_words = wrap_with(input_words, '<', '>')
    word_ngrams = char_ngrams(input_words, minn, maxn, itself='ALONE')

    return word_ngrams
    def test_skip(self):
        result = zero_digits([['7', '8']], skip=['8'])

        result = self.evaluate(result)
        self.assertAllEqual([[b'0', b'8']], result)
    def test_2d(self):
        result = zero_digits([['7']])

        result = self.evaluate(result)
        self.assertAllEqual([[b'0']], result)
    def test_0d(self):
        result = zero_digits('7')

        result = self.evaluate(result)
        self.assertEqual(b'0', result)
    def test_empty(self):
        result = zero_digits('')

        result = self.evaluate(result)
        self.assertEqual(b'', result)