def test_lower(self):
   ''' test lower string'''
   with self.session():
     output = py_x_ops.str_lower("Hello WORLD").eval()
     self.assertEqual(b'hello world', output)
     output = py_x_ops.str_lower(["Hello WORLD", "ABC XYZ"]).eval()
     self.assertAllEqual([b'hello world', b'abc xyz'], output)
Beispiel #2
0
def clean_english_str_tf(input_str):
    """Clean English string with tensorflow oprations."""
    # pylint: disable=anomalous-backslash-in-string
    string = tf.regex_replace(input_str, r"[^A-Za-z0-9(),!?\'\`<>/]", " ")
    string = tf.regex_replace(string, "\'s", " \'s")
    string = tf.regex_replace(string, "\'ve", " \'ve")
    string = tf.regex_replace(string, "n\'t", " n\'t")
    string = tf.regex_replace(string, "\'re", " \'re")
    string = tf.regex_replace(string, "\'d", " \'d")
    string = tf.regex_replace(string, "\'ll", " \'ll")
    string = tf.regex_replace(string, ",", " , ")
    string = tf.regex_replace(string, "!", " ! ")
    string = tf.regex_replace(string, "\(", " ( ")
    string = tf.regex_replace(string, "\)", " ) ")
    string = tf.regex_replace(string, "\?", " ? ")
    string = tf.regex_replace(string, "\s{2,}", " ")
    string = tf.string_strip(string)
    string = py_x_ops.str_lower(string)
    return string