r"""Splits each string in `input` into a sequence of Unicode code points. `result[i1...iN, j]` is the substring of `input[i1...iN]` that encodes its `j`th character, when decoded using `input_encoding`. Args: input: An `N` dimensional potentially ragged `string` tensor with shape `
(input,
input_encoding,
errors="replace",
replacement_char=0xFFFD,
name=None)
| 285 | |
| 286 | @tf_export("strings.unicode_split") |
| 287 | def unicode_split(input, |
| 288 | input_encoding, |
| 289 | errors="replace", |
| 290 | replacement_char=0xFFFD, |
| 291 | name=None): |
| 292 | r"""Splits each string in `input` into a sequence of Unicode code points. |
| 293 | |
| 294 | `result[i1...iN, j]` is the substring of `input[i1...iN]` that encodes its |
| 295 | `j`th character, when decoded using `input_encoding`. |
| 296 | |
| 297 | Args: |
| 298 | input: An `N` dimensional potentially ragged `string` tensor with shape |
| 299 | `[D1...DN]`. `N` must be statically known. |
| 300 | input_encoding: String name for the unicode encoding that should be used to |
| 301 | decode each string. |
| 302 | errors: Specifies the response when an input string can't be converted |
| 303 | using the indicated encoding. One of: |
| 304 | * `'strict'`: Raise an exception for any illegal substrings. |
| 305 | * `'replace'`: Replace illegal substrings with `replacement_char`. |
| 306 | * `'ignore'`: Skip illegal substrings. |
| 307 | replacement_char: The replacement codepoint to be used in place of invalid |
| 308 | substrings in `input` when `errors='replace'`. |
| 309 | name: A name for the operation (optional). |
| 310 | |
| 311 | Returns: |
| 312 | A `N+1` dimensional `int32` tensor with shape `[D1...DN, (num_chars)]`. |
| 313 | The returned tensor is a `tf.Tensor` if `input` is a scalar, or a |
| 314 | `tf.RaggedTensor` otherwise. |
| 315 | |
| 316 | #### Example: |
| 317 | ```python |
| 318 | >>> input = [s.encode('utf8') for s in (u'G\xf6\xf6dnight', u'\U0001f60a')] |
| 319 | >>> tf.strings.unicode_split(input, 'UTF-8').tolist() |
| 320 | [['G', '\xc3\xb6', '\xc3\xb6', 'd', 'n', 'i', 'g', 'h', 't'], |
| 321 | ['\xf0\x9f\x98\x8a']] |
| 322 | ``` |
| 323 | """ |
| 324 | with ops.name_scope(name, "UnicodeSplit", [input]): |
| 325 | codepoints = _unicode_decode(input, input_encoding, errors, |
| 326 | replacement_char, False, with_offsets=False) |
| 327 | return unicode_encode( |
| 328 | ragged_array_ops.expand_dims(codepoints, -1), |
| 329 | output_encoding=input_encoding, |
| 330 | errors=errors, |
| 331 | replacement_char=replacement_char) |
| 332 | |
| 333 | |
| 334 | @tf_export("strings.unicode_split_with_offsets") |
nothing calls this directly
no test coverage detected