จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เทนเซอร์โฟลว์:: ปฏิบัติการ:: UnicodeTranscode
#include <string_ops.h>
แปลงรหัสข้อความอินพุตจากการเข้ารหัสต้นทางเป็นการเข้ารหัสปลายทาง
สรุป
อินพุตเป็นสตริงเทนเซอร์ที่มีรูปร่างใดๆ เอาต์พุตเป็นสตริงเทนเซอร์ที่มีรูปร่างเดียวกันซึ่งมีสตริงที่แปลงรหัสแล้ว สตริง เอาต์พุต จะเป็นยูนิโค้ดที่ถูกต้องเสมอ หากอินพุตมีตำแหน่งการเข้ารหัสที่ไม่ถูกต้อง แอตทริบิวต์ errors
จะกำหนดนโยบายสำหรับวิธีจัดการกับตำแหน่งเหล่านั้น หากใช้นโยบายการจัดการข้อผิดพลาดเริ่มต้น การจัดรูปแบบที่ไม่ถูกต้องจะถูกแทนที่ในเอาต์พุตด้วย replacement_char
หากนโยบายข้อผิดพลาดคือ ignore
ตำแหน่งการเข้ารหัสที่ไม่ถูกต้องในอินพุตจะถูกข้ามไปและไม่รวมอยู่ในเอาต์พุต หากตั้งค่าเป็น strict
การจัดรูปแบบที่ไม่ถูกต้องจะส่งผลให้เกิดข้อผิดพลาด InvalidArgument
การดำเนินการนี้สามารถใช้กับ output_encoding = input_encoding
เพื่อบังคับใช้การจัดรูปแบบที่ถูกต้องสำหรับอินพุต แม้ว่าจะอยู่ในการเข้ารหัสที่ต้องการแล้วก็ตาม
หากอินพุตนำหน้าด้วย Byte Order Mark ที่จำเป็นในการกำหนดการเข้ารหัส (เช่น หากการเข้ารหัสเป็น UTF-16 และ BOM ระบุว่าเป็น big-endian) BOM นั้นจะถูกใช้และไม่ปล่อยลงในเอาต์พุต หากการเข้ารหัสอินพุตถูกทำเครื่องหมายด้วย endianness ที่ชัดเจน (เช่น UTF-16-BE) BOM จะถูกตีความว่าเป็นช่องว่างที่ไม่แยกและจะถูกเก็บไว้ในเอาต์พุต (รวมถึง UTF-8 เสมอ)
ผลลัพธ์ที่ได้คือหากอินพุตถูกทำเครื่องหมายว่าเป็น endianness ที่ชัดเจน การแปลงรหัสจะตรงตามจุดรหัสทั้งหมดในแหล่งที่มา หากไม่ได้ทำเครื่องหมายด้วย endianness ที่ชัดเจน BOM จะไม่ถือว่าเป็นส่วนหนึ่งของสตริง แต่เป็นข้อมูลเมตา ดังนั้นจะไม่ถูกเก็บรักษาไว้ในเอาต์พุต
ข้อโต้แย้ง:
- ขอบเขต: วัตถุ ขอบเขต
- input: ข้อความที่จะประมวลผล จะมีรูปร่างแบบไหนก็ได้
- input_encoding: การเข้ารหัสข้อความของสตริงอินพุต นี่คือการเข้ารหัสใดๆ ที่สนับสนุนโดยตัวแปลงอัลกอริทึม ucnv ของ ICU ตัวอย่าง:
"UTF-16", "US ASCII", "UTF-8"
- output_encoding: การเข้ารหัส Unicode ที่จะใช้ในเอาต์พุต จะต้องเป็นหนึ่งใน
"UTF-8", "UTF-16-BE", "UTF-32-BE"
การเข้ารหัสแบบหลายไบต์จะเป็นแบบ big-endian
แอ็ตทริบิวต์ทางเลือก (ดู Attrs
):
- ข้อผิดพลาด: นโยบายการจัดการข้อผิดพลาดเมื่อพบการจัดรูปแบบที่ไม่ถูกต้องในอินพุต ค่า 'เข้มงวด' จะทำให้การดำเนินการสร้างข้อผิดพลาด InvalidArgument ในการจัดรูปแบบอินพุตที่ไม่ถูกต้อง ค่า 'replace' (ค่าเริ่มต้น) จะทำให้การดำเนินการแทนที่การจัดรูปแบบที่ไม่ถูกต้องในอินพุตด้วย codepoint
replacement_char
ค่า 'ละเว้น' จะทำให้การดำเนินการข้ามการจัดรูปแบบที่ไม่ถูกต้องในอินพุต และไม่มีอักขระเอาต์พุตที่สอดคล้องกัน - replacement_char: codepoint อักขระทดแทนที่จะใช้แทนที่การจัดรูปแบบที่ไม่ถูกต้องในอินพุตเมื่อ
errors='replace'
สามารถใช้จุดโค้ดยูนิโค้ด ที่ ถูกต้องได้ ค่าเริ่มต้นคืออักขระแทนที่ Unicode เริ่มต้นคือ 0xFFFD หรือ U+65533)
โปรดทราบว่าสำหรับ UTF-8 การส่งอักขระแทนที่ที่แสดงเป็น 1 ไบต์ เช่น ' ' จะคงการจัดแนวสตริงไว้ที่ต้นทาง เนื่องจากไบต์ที่ไม่ถูกต้องจะถูกแทนที่ด้วยการแทนที่ 1 ไบต์ สำหรับ UTF-16-BE และ UTF-16-LE อักขระแทนที่ 1 หรือ 2 ไบต์ใดๆ จะรักษาการจัดตำแหน่งของไบต์กับแหล่งที่มา
- แทนที่อักขระควบคุม C0 (00-1F) ด้วย
replacement_char
หรือไม่ ค่าเริ่มต้นเป็นเท็จ
ผลตอบแทน:
-
Output
: เทนเซอร์สตริงที่มีข้อความยูนิโค้ดที่เข้ารหัสโดยใช้ output_encoding
คุณลักษณะสาธารณะ
งานสาธารณะ
โหนด
::tensorflow::Node * node() const
operator::tensorflow::Input() const
ตัวดำเนินการ::tensorflow::เอาต์พุต
operator::tensorflow::Output() const
ฟังก์ชันคงที่สาธารณะ
ข้อผิดพลาด
Attrs Errors(
StringPiece x
)
แทนที่อักขระควบคุม
Attrs ReplaceControlCharacters(
bool x
)
ถ่านทดแทน
Attrs ReplacementChar(
int64 x
)
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[null,null,["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# tensorflow::ops::UnicodeTranscode Class Reference\n\ntensorflow::ops::UnicodeTranscode\n=================================\n\n`#include \u003cstring_ops.h\u003e`\n\nTranscode the input text from a source encoding to a destination encoding.\n\nSummary\n-------\n\nThe input is a string tensor of any shape. The output is a string tensor of the same shape containing the transcoded strings. [Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) strings are always valid unicode. If the input contains invalid encoding positions, the `errors` attribute sets the policy for how to deal with them. If the default error-handling policy is used, invalid formatting will be substituted in the output by the `replacement_char`. If the errors policy is to `ignore`, any invalid encoding positions in the input are skipped and not included in the output. If it set to `strict` then any invalid formatting will result in an InvalidArgument error.\n\nThis operation can be used with `output_encoding = input_encoding` to enforce correct formatting for inputs even if they are already in the desired encoding.\n\nIf the input is prefixed by a Byte Order Mark needed to determine encoding (e.g. if the encoding is UTF-16 and the BOM indicates big-endian), then that BOM will be consumed and not emitted into the output. If the input encoding is marked with an explicit endianness (e.g. UTF-16-BE), then the BOM is interpreted as a non-breaking-space and is preserved in the output (including always for UTF-8).\n\nThe end result is that if the input is marked as an explicit endianness the transcoding is faithful to all codepoints in the source. If it is not marked with an explicit endianness, the BOM is not considered part of the string itself but as metadata, and so is not preserved in the output.\n\nArguments:\n\n- scope: A [Scope](/versions/r2.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- input: The text to be processed. Can have any shape.\n- input_encoding: Text encoding of the input strings. This is any of the encodings supported by ICU ucnv algorithmic converters. Examples: `\"UTF-16\", \"US ASCII\", \"UTF-8\"`.\n- output_encoding: The unicode encoding to use in the output. Must be one of `\"UTF-8\", \"UTF-16-BE\", \"UTF-32-BE\"`. Multi-byte encodings will be big-endian.\n\n\u003cbr /\u003e\n\nOptional attributes (see [Attrs](/versions/r2.1/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs#structtensorflow_1_1ops_1_1_unicode_transcode_1_1_attrs)):\n\n- errors: Error handling policy when there is invalid formatting found in the input. The value of 'strict' will cause the operation to produce a InvalidArgument error on any invalid input formatting. A value of 'replace' (the default) will cause the operation to replace any invalid formatting in the input with the `replacement_char` codepoint. A value of 'ignore' will cause the operation to skip any invalid formatting in the input and produce no corresponding output character.\n- replacement_char: The replacement character codepoint to be used in place of any invalid formatting in the input when `errors='replace'`. [Any](/versions/r2.1/api_docs/cc/class/tensorflow/ops/any#classtensorflow_1_1ops_1_1_any) valid unicode codepoint may be used. The default value is the default unicode replacement character is 0xFFFD or U+65533.)\n\n\u003cbr /\u003e\n\nNote that for UTF-8, passing a replacement character expressible in 1 byte, such as ' ', will preserve string alignment to the source since invalid bytes will be replaced with a 1-byte replacement. For UTF-16-BE and UTF-16-LE, any 1 or 2 byte replacement character will preserve byte alignment to the source.\n\n- replace_control_characters: Whether to replace the C0 control characters (00-1F) with the `replacement_char`. Default is false.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): A string tensor containing unicode text encoded using `output_encoding`.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [UnicodeTranscode](#classtensorflow_1_1ops_1_1_unicode_transcode_1a7f5400ef43a30cade48ec26babb8d8ac)`(const ::`[tensorflow::Scope](/versions/r2.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, StringPiece input_encoding, StringPiece output_encoding)` ||\n| [UnicodeTranscode](#classtensorflow_1_1ops_1_1_unicode_transcode_1a40d3c0e8ec4a39090a41db687a75e81e)`(const ::`[tensorflow::Scope](/versions/r2.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, StringPiece input_encoding, StringPiece output_encoding, const `[UnicodeTranscode::Attrs](/versions/r2.1/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs#structtensorflow_1_1ops_1_1_unicode_transcode_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_unicode_transcode_1a9121969d40f22188b5468ef3a88c7e85) | [Operation](/versions/r2.1/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_unicode_transcode_1a72ea1928a722003c6a454fb3e4d99cf8) | `::`[tensorflow::Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|-----------------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_unicode_transcode_1a5bd626fd8293b9ba38989e199cb56039)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_unicode_transcode_1aa3ed5d86e608fef6fe501acc1886adc4)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_unicode_transcode_1a228a8c3c53116beb44e18691ba954e40)`() const ` | ` ` ` ` |\n\n| ### Public static functions ||\n|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| [Errors](#classtensorflow_1_1ops_1_1_unicode_transcode_1a4ec0643c5c92c98679d67690e8d6826c)`(StringPiece x)` | [Attrs](/versions/r2.1/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs#structtensorflow_1_1ops_1_1_unicode_transcode_1_1_attrs) |\n| [ReplaceControlCharacters](#classtensorflow_1_1ops_1_1_unicode_transcode_1ac2031f1a1d602c2981d079a72e41ad8b)`(bool x)` | [Attrs](/versions/r2.1/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs#structtensorflow_1_1ops_1_1_unicode_transcode_1_1_attrs) |\n| [ReplacementChar](#classtensorflow_1_1ops_1_1_unicode_transcode_1a006b666456f90b0903bcaea23ee678cd)`(int64 x)` | [Attrs](/versions/r2.1/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs#structtensorflow_1_1ops_1_1_unicode_transcode_1_1_attrs) |\n\n| ### Structs ||\n|----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::UnicodeTranscode::Attrs](/versions/r2.1/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs) | Optional attribute setters for [UnicodeTranscode](/versions/r2.1/api_docs/cc/class/tensorflow/ops/unicode-transcode#classtensorflow_1_1ops_1_1_unicode_transcode). |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### UnicodeTranscode\n\n```gdscript\n UnicodeTranscode(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n StringPiece input_encoding,\n StringPiece output_encoding\n)\n``` \n\n### UnicodeTranscode\n\n```gdscript\n UnicodeTranscode(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n StringPiece input_encoding,\n StringPiece output_encoding,\n const UnicodeTranscode::Attrs & attrs\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n``` \n\nPublic static functions\n-----------------------\n\n### Errors\n\n```text\nAttrs Errors(\n StringPiece x\n)\n``` \n\n### ReplaceControlCharacters\n\n```text\nAttrs ReplaceControlCharacters(\n bool x\n)\n``` \n\n### ReplacementChar\n\n```text\nAttrs ReplacementChar(\n int64 x\n)\n```"]]