Name | graphemeu JSON |
Version |
0.7.0
JSON |
| download |
home_page | None |
Summary | Unicode grapheme helpers |
upload_time | 2024-10-15 09:43:15 |
maintainer | Timendum |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | Copyright (c) 2017 The Python Packaging Authority (PyPA) Copyright (c) 2014 Mapbox Copyright (c) 2017 Alvin Lindstam Copyright (c) 2024 Timendum Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
grapheme
unicode
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
grapheme
========
A Python package for working with user perceived characters. More specifically,
string manipulation and calculation functions for working with grapheme cluster
groups (graphemes) as defined by the `Unicode Standard Annex #29 <http://unicode.org/reports/tr29/>`_.
`documentation <https://graphemeu.readthedocs.io/>`_
.. code-block:: console
pip install graphemeu
Or similar.
The currently supported version of Unicode: 16.0.0.
This package is a fork of `grapheme <https://github.com/alvinlindstam/grapheme>`_ by Alvin Lindstam.
What? Why?
==========
Unicode strings are made up of a series of unicode characters, but a unicode character does not
always map to a user perceived character. Some human perceived characters are represented as two
or more unicode characters.
However, all built in python string functions and string methods work with single unicode characters
without considering their connection to each other.
.. code-block:: python
>>> string = 'u̲n̲d̲e̲r̲l̲i̲n̲e̲d̲'
>>> len(string)
20
>>> grapheme.length(string)
10
>>> string[:3]
'u̲n'
>>> grapheme.slice(string, 0, 3)
'u̲n̲d̲'
This library implements the unicode default rules for extended grapheme clusters, and provides
a set of functions for string manipulation based on graphemes.
Documentation
=============
See `<https://graphemeu.readthedocs.io/en/latest/>`_.
When should I consider graphemes instead of unicode characters?
===============================================================
You should consider working with graphemes over unicode code points when:
* You wish to count characters as perceived by users.
* You wish to split or truncate text at some user perceived lengths.
* You wish to split or truncate text without risk of corrupting the characters.
* Formatting text by length, such as creating text based tables in monospaced fonts
You should work with normal python string functions when:
* You wish to count or split by unicode codepoints for compliance with storage
limitations (such as database maximum length)
* When working with systems that put limits on strings by unicode character
lengths
* When you prioritize performance over correctness (see performance notes below)
* When working with very long strings (see performance notes below)
* If simplicity is more important than accuracy
Performance
===========
Calculating graphemes require traversing the string and checking each character
against a set of rules and the previous character(s). Because of this, all
functions in this module will scale linearly to the string length.
Whenever possible, they will only traverse the string for as long as needed and return
early as soon as the requested output is generated. For example, the `grapheme.slice`
function only has to traverse the string until the last requested grapheme is found, and
does not care about the rest of the string.
You should probably only use this package for testing/manipulating fairly short strings
or with the beginning of long strings.
When testing with a string of 10 000 ascii characters, and a 3.1 GHz processor, the execution
time for some possible calls is roughly:
================================================================ ==========================
Code Approximate execution time
================================================================ ==========================
`len(long_ascii_string)` 8.1e-10 seconds
`grapheme.length(long_ascii_string)` 1.5e-04 seconds
`grapheme.length(long_ascii_string, 500)` 8.7e-06 seconds
`long_ascii_string[0:100]` 1.3e-09 seconds
`grapheme.slice(long_ascii_string, 0, 100)` 2.5e-06 seconds
`long_ascii_string[:100] in long_ascii_string` 4.0e-09 seconds
`grapheme.contains(long_ascii_string, long_ascii_string[:100])` 3.9e-06 seconds
`long_ascii_string[-100:] in long_ascii_string` 2.1e-07 seconds
`grapheme.contains(long_ascii_string, long_ascii_string[-100:])` 1.9e-04 seconds
================================================================ ==========================
Execution times may improve in later releases, but calculating graphemes is and will continue
to be notably slower than just counting unicode code points.
Examples of grapheme cluster groups
===================================
This is not a complete list, but a some examples of when graphemes use multiple
characters:
* CR+LF
* Hangul (korean)
* Emoji with modifiers
* Combining marks
* Zero Width Join
Development quick start
=======================
If you wish to contribute or edit this package, create a fork and clone it.
Then install and run the tests.
.. code-block:: console
uv run --extra dev -m pytest
For the documentation, use:
.. code-block:: console
uv run --extra docs sphinx-autobuild docs dist/www
Unicode version upgrade
-----------------------
The library will issue a new release for each new unicode version.
The steps necessary for this:
1. Verify that there has been no material changes to the rulesets in Unicode
`Annex #29 <http://unicode.org/reports/tr29/>`_ (see modifications).
2. Download the `data files <http://www.unicode.org/Public/>`_ from unicode into the unicode-data folder.
For the given version, some are in `ucd` and some are in `ucd/auxiliary`.
3. Run `make process-data-files` to parse those files (will update the
`grapheme_break_property.json` and `derived_core_property.json` files).
4. Update the unicode version in the documentation and in the source code.
5. Bump the version.
Raw data
{
"_id": null,
"home_page": null,
"name": "graphemeu",
"maintainer": "Timendum",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "grapheme, unicode",
"author": null,
"author_email": "Alvin Lindstam <alvin.lindstam@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/16/58/d75ec8afc93af2181f774883cc5efdd264c20a323e51a2ff836d5ca247b6/graphemeu-0.7.0.tar.gz",
"platform": null,
"description": "grapheme\n========\n\nA Python package for working with user perceived characters. More specifically,\nstring manipulation and calculation functions for working with grapheme cluster\ngroups (graphemes) as defined by the `Unicode Standard Annex #29 <http://unicode.org/reports/tr29/>`_.\n\n`documentation <https://graphemeu.readthedocs.io/>`_\n\n.. code-block:: console\n\n pip install graphemeu\n\nOr similar.\n\nThe currently supported version of Unicode: 16.0.0.\n\nThis package is a fork of `grapheme <https://github.com/alvinlindstam/grapheme>`_ by Alvin Lindstam.\n\nWhat? Why?\n==========\n\nUnicode strings are made up of a series of unicode characters, but a unicode character does not\nalways map to a user perceived character. Some human perceived characters are represented as two\nor more unicode characters.\n\nHowever, all built in python string functions and string methods work with single unicode characters\nwithout considering their connection to each other.\n\n.. code-block:: python\n\n >>> string = 'u\u0332n\u0332d\u0332e\u0332r\u0332l\u0332i\u0332n\u0332e\u0332d\u0332'\n >>> len(string)\n 20\n >>> grapheme.length(string)\n 10\n >>> string[:3]\n 'u\u0332n'\n >>> grapheme.slice(string, 0, 3)\n 'u\u0332n\u0332d\u0332'\n\nThis library implements the unicode default rules for extended grapheme clusters, and provides\na set of functions for string manipulation based on graphemes.\n\nDocumentation\n=============\n\nSee `<https://graphemeu.readthedocs.io/en/latest/>`_.\n\nWhen should I consider graphemes instead of unicode characters?\n===============================================================\n\nYou should consider working with graphemes over unicode code points when:\n\n* You wish to count characters as perceived by users.\n* You wish to split or truncate text at some user perceived lengths.\n* You wish to split or truncate text without risk of corrupting the characters.\n* Formatting text by length, such as creating text based tables in monospaced fonts\n\nYou should work with normal python string functions when:\n\n* You wish to count or split by unicode codepoints for compliance with storage\n limitations (such as database maximum length)\n* When working with systems that put limits on strings by unicode character\n lengths\n* When you prioritize performance over correctness (see performance notes below)\n* When working with very long strings (see performance notes below)\n* If simplicity is more important than accuracy\n\nPerformance\n===========\n\nCalculating graphemes require traversing the string and checking each character\nagainst a set of rules and the previous character(s). Because of this, all\nfunctions in this module will scale linearly to the string length.\n\nWhenever possible, they will only traverse the string for as long as needed and return\nearly as soon as the requested output is generated. For example, the `grapheme.slice`\nfunction only has to traverse the string until the last requested grapheme is found, and\ndoes not care about the rest of the string.\n\nYou should probably only use this package for testing/manipulating fairly short strings\nor with the beginning of long strings.\n\nWhen testing with a string of 10 000 ascii characters, and a 3.1 GHz processor, the execution\ntime for some possible calls is roughly:\n\n================================================================ ==========================\nCode Approximate execution time\n================================================================ ==========================\n`len(long_ascii_string)` 8.1e-10 seconds\n`grapheme.length(long_ascii_string)` 1.5e-04 seconds\n`grapheme.length(long_ascii_string, 500)` 8.7e-06 seconds\n`long_ascii_string[0:100]` 1.3e-09 seconds\n`grapheme.slice(long_ascii_string, 0, 100)` 2.5e-06 seconds\n`long_ascii_string[:100] in long_ascii_string` 4.0e-09 seconds\n`grapheme.contains(long_ascii_string, long_ascii_string[:100])` 3.9e-06 seconds\n`long_ascii_string[-100:] in long_ascii_string` 2.1e-07 seconds\n`grapheme.contains(long_ascii_string, long_ascii_string[-100:])` 1.9e-04 seconds\n================================================================ ==========================\n\nExecution times may improve in later releases, but calculating graphemes is and will continue\nto be notably slower than just counting unicode code points.\n\nExamples of grapheme cluster groups\n===================================\n\nThis is not a complete list, but a some examples of when graphemes use multiple\ncharacters:\n\n* CR+LF\n* Hangul (korean)\n* Emoji with modifiers\n* Combining marks\n* Zero Width Join\n\nDevelopment quick start\n=======================\n\nIf you wish to contribute or edit this package, create a fork and clone it.\n\nThen install and run the tests.\n\n.. code-block:: console\n\n uv run --extra dev -m pytest\n\nFor the documentation, use:\n\n.. code-block:: console\n\n uv run --extra docs sphinx-autobuild docs dist/www\n\nUnicode version upgrade\n-----------------------\n\nThe library will issue a new release for each new unicode version.\n\nThe steps necessary for this:\n\n1. Verify that there has been no material changes to the rulesets in Unicode\n `Annex #29 <http://unicode.org/reports/tr29/>`_ (see modifications).\n2. Download the `data files <http://www.unicode.org/Public/>`_ from unicode into the unicode-data folder.\n For the given version, some are in `ucd` and some are in `ucd/auxiliary`.\n3. Run `make process-data-files` to parse those files (will update the\n `grapheme_break_property.json` and `derived_core_property.json` files).\n4. Update the unicode version in the documentation and in the source code.\n5. Bump the version.\n",
"bugtrack_url": null,
"license": "Copyright (c) 2017 The Python Packaging Authority (PyPA) Copyright (c) 2014 Mapbox Copyright (c) 2017 Alvin Lindstam Copyright (c) 2024 Timendum Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Unicode grapheme helpers",
"version": "0.7.0",
"project_urls": {
"Documentation": "https://graphemeu.readthedocs.io/",
"Homepage": "https://github.com/timendum/grapheme"
},
"split_keywords": [
"grapheme",
" unicode"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a12bb3a8e64f402eb065e51a9c3609c56b4ff8879d6613fc26cd68f488a9a969",
"md5": "68e11b71c413d652717d1187f5d69358",
"sha256": "32e8df7ab413f9046bda9738f0801aac5212f968f1fcba0758437ce247d6523d"
},
"downloads": -1,
"filename": "graphemeu-0.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "68e11b71c413d652717d1187f5d69358",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 22652,
"upload_time": "2024-10-15T09:43:12",
"upload_time_iso_8601": "2024-10-15T09:43:12.971266Z",
"url": "https://files.pythonhosted.org/packages/a1/2b/b3a8e64f402eb065e51a9c3609c56b4ff8879d6613fc26cd68f488a9a969/graphemeu-0.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1658d75ec8afc93af2181f774883cc5efdd264c20a323e51a2ff836d5ca247b6",
"md5": "007f91b109c9170d8bf27f3e40c06bf8",
"sha256": "b184183734854c2772b5a9cae471d7a9a116dba879282f7940cc8cae853e73f6"
},
"downloads": -1,
"filename": "graphemeu-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "007f91b109c9170d8bf27f3e40c06bf8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 308229,
"upload_time": "2024-10-15T09:43:15",
"upload_time_iso_8601": "2024-10-15T09:43:15.514459Z",
"url": "https://files.pythonhosted.org/packages/16/58/d75ec8afc93af2181f774883cc5efdd264c20a323e51a2ff836d5ca247b6/graphemeu-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 09:43:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "timendum",
"github_project": "grapheme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "graphemeu"
}