جریان تنسور:: عملیات:: Unicode Transcode
#include <string_ops.h>
متن ورودی را از کدگذاری منبع به رمزگذاری مقصد تبدیل کنید.
خلاصه
ورودی یک تانسور رشته ای از هر شکلی است. خروجی یک تانسور رشته ای به همان شکل است که رشته های رمزگذاری شده را در خود دارد. رشته های خروجی همیشه یونیکد معتبر هستند. اگر ورودی حاوی موقعیت های رمزگذاری نامعتبر باشد، ویژگی errors
خط مشی نحوه برخورد با آنها را تعیین می کند. اگر از خطمشی پیشفرض مدیریت خطا استفاده شود، قالببندی نامعتبر در خروجی با replacement_char
جایگزین میشود. اگر خط مشی خطاها ignore
گرفته شود، هر موقعیت رمزگذاری نامعتبر در ورودی نادیده گرفته می شود و در خروجی گنجانده نمی شود. اگر روی strict
تنظیم شود، هر قالب بندی نامعتبر منجر به خطای InvalidArgument می شود.
این عملیات را می توان با output_encoding = input_encoding
برای اعمال قالب بندی صحیح برای ورودی ها حتی اگر آنها در حال حاضر در رمزگذاری مورد نظر هستند استفاده کرد.
اگر ورودی با علامت ترتیب بایتی که برای تعیین رمزگذاری لازم است پیشوند شود (مثلاً اگر رمزگذاری UTF-16 باشد و BOM نشان دهنده big-endian باشد)، آن BOM مصرف می شود و به خروجی گسیل نمی شود. اگر رمزگذاری ورودی با یک endianness صریح مشخص شده باشد (مثلا UTF-16-BE)، آنگاه BOM به عنوان یک فضای بدون شکست تفسیر می شود و در خروجی حفظ می شود (از جمله همیشه برای UTF-8).
نتیجه نهایی این است که اگر ورودی بهعنوان یک endianness صریح علامتگذاری شود، رمزگذاری به همه کدهای منبع وفادار است. اگر با endianness صریح مشخص نشده باشد، BOM بخشی از خود رشته در نظر گرفته نمی شود، بلکه به عنوان ابرداده در نظر گرفته می شود، و بنابراین در خروجی حفظ نمی شود.
استدلال ها:
- scope: یک شی Scope
- ورودی: متنی که باید پردازش شود. می تواند هر شکلی داشته باشد.
- input_encoding: رمزگذاری متن رشته های ورودی. این هر یک از رمزگذاری های پشتیبانی شده توسط مبدل های الگوریتمی ICU ucnv است. مثالها:
"UTF-16", "US ASCII", "UTF-8"
. - output_encoding: رمزگذاری یونیکد برای استفاده در خروجی. باید یکی از
"UTF-8", "UTF-16-BE", "UTF-32-BE"
باشد. رمزگذاری های چند بایتی بزرگ اندیان خواهند بود.
ویژگی های اختیاری (به Attrs
مراجعه کنید):
- خطاها: خط مشی رسیدگی به خطا زمانی که قالب بندی نامعتبر در ورودی یافت می شود. مقدار 'strict' باعث می شود که عملیات خطای InvalidArgument در هر قالب بندی ورودی نامعتبر ایجاد کند. مقدار «replace» (پیشفرض) باعث میشود که عملیات هر قالببندی نامعتبر در ورودی را با نقطه کد
replacement_char
جایگزین کند. مقدار "نادیده گرفتن" باعث می شود عملیات از هر قالب بندی نامعتبر در ورودی صرف نظر کند و هیچ کاراکتر خروجی مربوطه تولید نکند. - placement_char: نقطه کد کاراکتر جایگزینی که باید به جای هر قالب بندی نامعتبر در ورودی در هنگام
errors='replace'
استفاده شود. ممکن است از هر کد یونیکد معتبر استفاده شود. مقدار پیشفرض این است که کاراکتر جایگزین یونیکد پیشفرض 0xFFFD یا U+65533 است.)
توجه داشته باشید که برای UTF-8، ارسال یک کاراکتر جایگزین قابل بیان در 1 بایت، مانند " "، تراز رشته را با منبع حفظ می کند زیرا بایت های نامعتبر با یک جایگزین 1 بایتی جایگزین می شوند. برای UTF-16-BE و UTF-16-LE، هر نویسه جایگزین 1 یا 2 بایت، تراز بایت را با منبع حفظ می کند.
- replace_control_characters: آیا باید نویسه های کنترلی C0 (00-1F) را با
replacement_char
جایگزین کرد. پیش فرض نادرست است.
برمیگرداند:
-
Output
: یک تانسور رشته ای حاوی متن یونیکد که با استفاده از output_encoding
کدگذاری شده است.
صفات عمومی
عملیات
Operation operation
خروجی
::tensorflow::Output output
توابع عمومی
Unicode Transcode
UnicodeTranscode(
const ::tensorflow::Scope & scope,
::tensorflow::Input input,
StringPiece input_encoding,
StringPiece output_encoding
)
Unicode Transcode
UnicodeTranscode(
const ::tensorflow::Scope & scope,
::tensorflow::Input input,
StringPiece input_encoding,
StringPiece output_encoding,
const UnicodeTranscode::Attrs & attrs
)
گره
::tensorflow::Node * node() const
operator::tensorflow::Input() const
عملگر::tensorflow::خروجی
operator::tensorflow::Output() const
توابع استاتیک عمومی
خطاها
Attrs Errors(
StringPiece x
)
ReplaceControl Characters
Attrs ReplaceControlCharacters(
bool x
)
Replacement Char
Attrs ReplacementChar(
int64 x
)
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-26 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-26 بهوقت ساعت هماهنگ جهانی."],[],[],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/r1.15/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/r1.15/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/r1.15/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/r1.15/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/r1.15/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/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r1.15/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/r1.15/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r1.15/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, StringPiece input_encoding, StringPiece output_encoding, const `[UnicodeTranscode::Attrs](/versions/r1.15/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/r1.15/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_unicode_transcode_1a72ea1928a722003c6a454fb3e4d99cf8) | `::`[tensorflow::Output](/versions/r1.15/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/r1.15/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/r1.15/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/r1.15/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/r1.15/api_docs/cc/struct/tensorflow/ops/unicode-transcode/attrs) | Optional attribute setters for [UnicodeTranscode](/versions/r1.15/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```"]]