def test_ragged(self):
        source = tf.ragged.constant([['x', 'yy'], ['zzz zzz']])
        expected = tf.constant([['X', 'YY'], ['ZZZ ZZZ', '']])
        result = upper_case(source).to_tensor(default_value='')

        expected, result = self.evaluate([expected, result])
        self.assertAllEqual(expected, result)
    def test_unicode(self):
        expected = u'ТЕСТ'
        result = upper_case(u'ТеСт')
        expected = tf.convert_to_tensor(expected, dtype=tf.string)

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

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

        result = self.evaluate(result)
        self.assertAllEqual([2, 3], result.tolist())
Exemplo n.º 5
0
def case_features(input_words):
    input_words = normalize_unicode(input_words, 'NFKC')
    words_lower = lower_case(input_words)
    words_upper = upper_case(input_words)
    words_title = title_case(input_words)

    has_case = tf.not_equal(words_lower, words_upper)
    no_case = tf.logical_not(has_case)

    is_lower = tf.logical_and(has_case, tf.equal(input_words, words_lower))

    is_upper = tf.logical_and(has_case, tf.equal(input_words, words_upper))

    is_title = tf.logical_and(has_case, tf.equal(input_words, words_title))

    is_mixed = tf.logical_not(
        tf.logical_or(tf.logical_or(no_case, is_lower),
                      tf.logical_or(is_upper, is_title)))

    return tf.cast(no_case, tf.int32), \
           tf.cast(is_lower, tf.int32), \
           tf.cast(is_upper, tf.int32), \
           tf.cast(is_title, tf.int32), \
           tf.cast(is_mixed, tf.int32)
    def test_skip(self):
        result = upper_case([['x', 'y']], skip=['y'])

        result = self.evaluate(result)
        self.assertAllEqual([[b'X', b'y']], result)
    def test_latin(self):
        result = upper_case('TeSt')

        result = self.evaluate(result)
        self.assertAllEqual(b'TEST', result)
    def test_2d(self):
        result = upper_case([['x']])

        result = self.evaluate(result)
        self.assertAllEqual([[b'X']], result)
    def test_0d(self):
        result = upper_case('x')

        result = self.evaluate(result)
        self.assertAllEqual(b'X', result)
Exemplo n.º 10
0
    def test_empty(self):
        result = upper_case('')

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