unicodedata --- پایگاه داده یونیکد


This module provides access to the Unicode Character Database (UCD) which defines character properties for all Unicode characters. The data contained in this database is compiled from the UCD version 17.0.0.

The module uses the same names and symbols as defined by Unicode Standard Annex #44, "Unicode Character Database".

همچنین ملاحظه نمائید

برای اطلاعات بیشتر درباره‌ی یونیکد و چگونگی استفاده از این ماژول، راهنمای عملی یونیکد را ببینید.

Lookup

lookup(name)

Look up character by name

name(chr)

Return the name assigned to a character

Numeric values

decimal(chr)

Decimal value of a character

digit(chr)

Digit value of a character

numeric(chr)

Numeric value of a character

Properties

bidirectional(chr)

Bidirectional class of a character

block(chr)

Unicode block of a character

category(chr)

General category of a character

combining(chr)

Canonical combining class of a character

decomposition(chr)

Character decomposition mapping

east_asian_width(chr)

East Asian width of a character

extended_pictographic(chr)

Check if a character has the Extended_Pictographic property

grapheme_cluster_break(chr)

Grapheme_Cluster_Break property of a character

indic_conjunct_break(chr)

Indic_Conjunct_Break property of a character

isxidcontinue(chr)

Check if a character is a valid identifier continuation

isxidstart(chr)

Check if a character is a valid identifier start

mirrored(chr)

Mirrored property of a character

Normalization

normalize(form, unistr)

Return the normalized form of a string

is_normalized(form, unistr)

Check if a Unicode string is normalized

Text segmentation

iter_graphemes(unistr)

Iterate over grapheme clusters in a string

unicodedata.lookup(name, /)

جست‌وجوی نویسه بر اساس نام. اگر نویسه‌ای با نام داده‌شده پیدا شود، نویسه متناظر برگردانده می‌شود. اگر پیدا نشود، KeyError پرتاب می‌شود. برای مثال:

>>> unicodedata.lookup('LEFT CURLY BRACKET')
'{'

نویسه‌های برگردانده‌شده توسط این تابع همان نویسه‌هایی هستند که توسط دنباله خنثی‌سازی \N در رشته‌های لفظی تولید می‌شوند. برای مثال:

>>> unicodedata.lookup('MIDDLE DOT') == '\N{MIDDLE DOT}'
True

تغییر یافته در نسخه‌ی 3.3: پشتیبانی از نام‌های مستعار [1] و دنباله‌های نام‌دار [2] اضافه شده است.

unicodedata.name(chr, default=None, /)

نام اختصاص‌یافته به نویسه chr را به‌صورت یک رشته برمی‌گرداند. اگر هیچ نامی تعریف نشده باشد، default برگردانده می‌شود، یا اگر داده نشده باشد، ValueError پرتاب می‌شود. برای مثال:

>>> unicodedata.name('½')
'VULGAR FRACTION ONE HALF'
>>> unicodedata.name('\uFFFF', 'fallback')
'fallback'
unicodedata.decimal(chr, default=None, /)

مقدار ده‌دهی تعیین‌شده برای نویسه chr را به‌صورت عدد صحیح برمی‌گرداند. اگر چنین مقداری تعریف‌نشده باشد، default بازگردانده می‌شود، یا، اگر داده نشده باشد، ValueError پرتاب می‌شود. برای مثال:

>>> unicodedata.decimal('\N{ARABIC-INDIC DIGIT NINE}')
9
>>> unicodedata.decimal('\N{SUPERSCRIPT NINE}', -1)
-1
unicodedata.digit(chr, default=None, /)

مقدار رقمی اختصاص‌یافته به نویسه chr را به‌صورت عدد صحیح برمی‌گرداند. اگر چنین مقداری تعریف نشده باشد، default برگردانده می‌شود، یا اگر داده نشده باشد، ValueError پرتاب می‌شود:

>>> unicodedata.digit('\N{SUPERSCRIPT NINE}')
9
unicodedata.numeric(chr, default=None, /)

مقدار عددی اختصاص‌یافته به نویسه chr را به‌صورت float برمی‌گرداند. اگر چنین مقداری تعریف‌نشده باشد، default برگردانده می‌شود، یا اگر داده نشده باشد، ValueError پرتاب می‌شود:

>>> unicodedata.numeric('½')
0.5
unicodedata.category(chr, /)

Returns the general category assigned to the character chr as string. General category names consist of two letters. See the General Category Values section of the Unicode Character Database documentation for a list of category codes. For example:

>>> unicodedata.category('A')  # 'L'etter, 'u'ppercase
'Lu'
unicodedata.bidirectional(chr, /)

Returns the bidirectional class assigned to the character chr as string. If no such value is defined, an empty string is returned. See the Bidirectional Class Values section of the Unicode Character Database documentation for a list of bidirectional codes. For example:

>>> unicodedata.bidirectional('\N{ARABIC-INDIC DIGIT SEVEN}') # 'A'rabic, 'N'umber
'AN'
unicodedata.combining(chr, /)

Returns the canonical combining class assigned to the character chr as integer. Returns 0 if no combining class is defined. See the Canonical Combining Class Values section of the Unicode Character Database for more information.

unicodedata.east_asian_width(chr, /)

Returns the east asian width assigned to the character chr as string. For a list of widths and or more information, see the Unicode Standard Annex #11.

unicodedata.block(chr, /)

Returns the block assigned to the character chr. For example:

>>> unicodedata.block('S')
'Basic Latin'

اضافه شده در نسخه‌ی 3.15.

unicodedata.mirrored(chr, /)

ویژگی آینه‌ای اختصاص‌یافته به نویسه‌ی chr را به‌صورت عدد صحیح بازمی‌گرداند. اگر نویسه به‌عنوان نویسه‌ی «آینه‌ای» در متن دوجهته شناسایی شده باشد، 1 و در غیر این صورت 0 بازمی‌گرداند. برای مثال:

>>> unicodedata.mirrored('>')
1
unicodedata.isxidstart(chr, /)

Return True if chr is a valid identifier start per the Unicode Standard Annex #31, that is, it has the XID_Start property. Return False otherwise. For example:

>>> unicodedata.isxidstart('S')
True
>>> unicodedata.isxidstart('0')
False

اضافه شده در نسخه‌ی 3.15.

unicodedata.isxidcontinue(chr, /)

Return True if chr is a valid identifier character per the Unicode Standard Annex #31, that is, it has the XID_Continue property. Return False otherwise. For example:

>>> unicodedata.isxidcontinue('S')
True
>>> unicodedata.isxidcontinue(' ')
False

اضافه شده در نسخه‌ی 3.15.

unicodedata.decomposition(chr, /)

نگاشت تجزیه‌ی نویسه‌ای را که به نویسه‌ی chr اختصاص‌یافته است، به‌صورت رشته برمی‌گرداند. در صورتی که چنین نگاشتی تعریف‌نشده باشد، یک رشته‌ی خالی برگردانده می‌شود. برای مثال:

>>> unicodedata.decomposition('Ã')
'0041 0303'
unicodedata.grapheme_cluster_break(chr, /)

Returns the Grapheme_Cluster_Break property assigned to the character.

اضافه شده در نسخه‌ی 3.15.

unicodedata.indic_conjunct_break(chr, /)

Returns the Indic_Conjunct_Break property assigned to the character.

اضافه شده در نسخه‌ی 3.15.

unicodedata.extended_pictographic(chr, /)

Returns True if the character has the Extended_Pictographic property, False otherwise.

اضافه شده در نسخه‌ی 3.15.

unicodedata.normalize(form, unistr, /)

فرم نرمال form را برای رشته‌ی یونیکدی unistr برمی‌گرداند. مقادیر معتبر برای form عبارت‌اند از 'NFC'، 'NFKC'، 'NFD' و 'NFKD'.

استاندارد یونیکد اشکال مختلف نرمال‌سازی برای یک رشته‌ی یونیکد را بر پایه‌ی تعریف هم‌ارزی کانونیکال و هم‌ارزی سازگاری تعریف می‌کند. در یونیکد، می‌توان چندین نویسه را به روش‌های مختلفی بیان کرد. برای مثال، نویسه‌ی U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) همچنین می‌تواند به‌صورت دنباله‌ی U+0043 (LATIN CAPITAL LETTER C) U+0327 (COMBINING CEDILLA) بیان شود.

برای هر نویسه، دو فرم عادی وجود دارد: فرم عادی C و فرم عادی D. فرم عادی D (NFD) همچنین با عنوان تجزیه‌ی کانونیکال (canonical decomposition) شناخته می‌شود و هر نویسه را به فرم تجزیه‌شده‌ی آن تبدیل می‌کند. فرم عادی C (NFC) ابتدا یک تجزیه‌ی کانونیکال (canonical decomposition) اعمال می‌کند، سپس نویسه‌های از پیش ترکیب‌شده را دوباره ترکیب می‌کند.

علاوه بر این دو صورت، دو صورت نرمال دیگر نیز بر پایه‌ی هم‌ارزی سازگاری وجود دارد. در یونیکد، از برخی نویسه‌ها پشتیبانی می‌شود که به‌طور معمول با نویسه‌های دیگر یکسان‌سازی می‌شدند. برای مثال، U+2160 (ROMAN NUMERAL ONE) در واقع همان U+0049 (LATIN CAPITAL LETTER I) است. با این حال، این نویسه در یونیکد برای سازگاری با مجموعه‌نویسه‌های موجود (برای مثال، gb2312) پشتیبانی می‌شود.

فرم نرمال KD (NFKD) تجزیه‌ی سازگاری (compatibility decomposition) را اعمال می‌کند، یعنی همه‌ی نویسه‌های سازگاری را با معادل‌هایشان جایگزین می‌کند. فرم نرمال KC (NFKC) ابتدا تجزیه‌ی سازگاری را اعمال می‌کند و سپس ترکیب کانونیکال (canonical composition) را انجام می‌دهد.

حتی اگر دو رشته‌ی یونیکد نرمال‌شده باشند و برای خواننده‌ی انسانی یکسان به نظر برسند، اگر یکی دارای نویسه‌های ترکیبی باشد و دیگری نداشته باشد، ممکن است مقایسه‌ی آن‌ها برابر نباشد.

unicodedata.is_normalized(form, unistr, /)

بازمی‌گرداند که آیا رشته‌ی یونیکد unistr در فرم نرمال form قرار دارد یا خیر. مقادیر معتبر برای form عبارت‌اند از 'NFC'، 'NFKC'، 'NFD' و 'NFKD'.

اضافه شده در نسخه‌ی 3.8.

unicodedata.iter_graphemes(unistr, start=0, end=sys.maxsize, /)

Returns an iterator to iterate over grapheme clusters. With optional start, iteration begins at that position. With optional end, iteration stops at that position.

Converting an emitted item to string returns a substring corresponding to the grapheme cluster. Its start and end attributes denote the start and end of the grapheme cluster.

It uses extended grapheme cluster rules defined by Unicode Standard Annex #29, "Unicode Text Segmentation".

اضافه شده در نسخه‌ی 3.15.

In addition, the module exposes the following constants:

unicodedata.unidata_version

نسخه‌ی پایگاه داده‌ی یونیکد استفاده‌شده در این ماژول.

unicodedata.ucd_3_2_0

This is an object that has most of the methods of the entire module, but uses the Unicode database version 3.2 instead, for applications that require this specific version of the Unicode database (such as IDNA).

پانویس‌ها