def test_ragged(self): source = tf.ragged.constant([['x', 'yy'], ['zzz zzz']]) expected = tf.constant([['X', 'Yy'], ['Zzz Zzz', '']]) result = title_case(source).to_tensor(default_value='') expected, result = self.evaluate([expected, result]) self.assertAllEqual(expected, result)
def test_unicode(self): expected = [u'Тест', u'\u01C5'] result = title_case([u'Тест', u'\u01C6']) 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 = title_case(source) self.assertAllEqual([2, 3], result.shape.as_list())
def test_actual_shape(self): source = [ ['1', '2', '3'], ['4', '5', '6'], ] result = title_case(source) result = tf.shape(result) result = self.evaluate(result) self.assertAllEqual([2, 3], result.tolist())
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 = title_case([['x', 'y']], skip=['y']) result = self.evaluate(result) self.assertAllEqual([[b'X', b'y']], result)
def test_latin(self): result = title_case('TeSt') result = self.evaluate(result) self.assertAllEqual(b'Test', result)
def test_2d(self): result = title_case([['x']]) result = self.evaluate(result) self.assertAllEqual([[b'X']], result)
def test_0d(self): result = title_case('x') result = self.evaluate(result) self.assertAllEqual(b'X', result)
def test_empty(self): result = title_case('') result = self.evaluate(result) self.assertAllEqual(b'', result)