Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alberto Pettarin
committed
May 13, 2016
0 parents
commit ebe1ba6
Showing
15 changed files
with
1,214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.pyc | ||
__pycache__ | ||
dist | ||
ipapy.egg-info | ||
zzz_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Alberto Pettarin (alberto@albertopettarin.it) | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include LICENSE | ||
include README.md | ||
include README.rst | ||
include VERSION | ||
include bin/ipapy | ||
recursive-include ipapy/data * | ||
include requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# ipapy | ||
|
||
**ipapy** is a Python module to work with IPA strings. | ||
|
||
* Version: 0.0.1 | ||
* Date: 2016-05-13 | ||
* Developer: [Alberto Pettarin](http://www.albertopettarin.it/) | ||
* License: the MIT License (MIT) | ||
* Contact: [click here](http://www.albertopettarin.it/contact.html) | ||
|
||
## Installation | ||
|
||
```bash | ||
$ pip install ipapy | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
$ git clone https://github.com/pettarin/ipapy.git | ||
$ cd ipapy | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
from ipapy.ipastring import IPAString | ||
from ipapy.ipachar import IPADiacritic | ||
|
||
# Unicode string for "Italian style" | ||
s = u"iˈtaljans ˈtail" | ||
|
||
# check if s contains only IPA characters (yes) | ||
if IPAString.is_valid_ipa(s): | ||
print("s is a valid IPA string") | ||
|
||
# create IPA string from Unicode string | ||
s_ipa = IPAString(unicode_string=s) | ||
|
||
# print the IPAString | ||
print(unicode(s_ipa)) # Python 2 | ||
print(s_ipa) # Python 3 | ||
|
||
# print the IPAString (Python 3) | ||
print(s_ipa) | ||
|
||
# new IPAStrings containing only... | ||
s_cv = s.cns_vwl # vowels and consonants | ||
s_cvs = s.cns_vwl_str # + stress marks | ||
s_cvsl = s.cns_vwl_str_len # + lenght marks | ||
s_cvslw = s.cns_vwl_str_len_wb # + word breaks | ||
|
||
# iterate over each IPA char, print it, and, | ||
# if it is a diacritic, print its properties | ||
for c_ipa in s_ipa: | ||
print(c_ipa) | ||
if isinstance(c_ipa, IPADiacritic): | ||
print(c_ipa.properties) | ||
|
||
# print the name and properties of all the vowels in the string | ||
for c_ipa in [c for c in s_ipa if c.is_vowel]: | ||
print(u"%s => %s" % (c_ipa, c_ipa.name)) | ||
|
||
# print the name and properties of all the consonants in the string | ||
for c_ipa in [c for c in s_ipa if c.is_consonant]: | ||
print(u"%s => %s" % (c_ipa, c_ipa.name)) | ||
``` | ||
|
||
## License | ||
|
||
**ipapy** is released under the MIT License. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
ipapy | ||
===== | ||
|
||
**ipapy** is a Python module to work with IPA strings. | ||
|
||
- Version: 0.0.1 | ||
- Date: 2016-05-13 | ||
- Developer: `Alberto Pettarin <http://www.albertopettarin.it/>`__ | ||
- License: the MIT License (MIT) | ||
- Contact: `click here <http://www.albertopettarin.it/contact.html>`__ | ||
|
||
Installation | ||
------------ | ||
|
||
.. code:: bash | ||
$ pip install ipapy | ||
or | ||
|
||
.. code:: bash | ||
$ git clone https://github.com/pettarin/ipapy.git | ||
$ cd ipapy | ||
Usage | ||
----- | ||
|
||
.. code:: python | ||
from ipapy.ipastring import IPAString | ||
from ipapy.ipachar import IPADiacritic | ||
# Unicode string for "Italian style" | ||
s = u"iˈtaljans ˈtail" | ||
# check if s contains only IPA characters (yes) | ||
if IPAString.is_valid_ipa(s): | ||
print("s is a valid IPA string") | ||
# create IPA string from Unicode string | ||
s_ipa = IPAString(unicode_string=s) | ||
# print the IPAString | ||
print(unicode(s_ipa)) # Python 2 | ||
print(s_ipa) # Python 3 | ||
# print the IPAString (Python 3) | ||
print(s_ipa) | ||
# new IPAStrings containing only... | ||
s_cv = s.cns_vwl # vowels and consonants | ||
s_cvs = s.cns_vwl_str # + stress marks | ||
s_cvsl = s.cns_vwl_str_len # + lenght marks | ||
s_cvslw = s.cns_vwl_str_len_wb # + word breaks | ||
# iterate over each IPA char, print it, and, | ||
# if it is a diacritic, print its properties | ||
for c_ipa in s_ipa: | ||
print(c_ipa) | ||
if isinstance(c_ipa, IPADiacritic): | ||
print(c_ipa.properties) | ||
# print the name and properties of all the vowels in the string | ||
for c_ipa in [c for c in s_ipa if c.is_vowel]: | ||
print(u"%s => %s" % (c_ipa, c_ipa.name)) | ||
# print the name and properties of all the consonants in the string | ||
for c_ipa in [c for c in s_ipa if c.is_consonant]: | ||
print(u"%s => %s" % (c_ipa, c_ipa.name)) | ||
License | ||
------- | ||
|
||
**ipapy** is released under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
|
||
""" | ||
ipapy contains data and functions to work with IPA strings. | ||
This is the main script, intended to be run from command line. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from ipapy import main as package_main | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "0.0.1" | ||
__email__ = "alberto@albertopettarin.it" | ||
__status__ = "Development" | ||
|
||
def main(): | ||
package_main() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
|
||
""" | ||
ipapy contains data and functions to work with IPA strings. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "0.0.1" | ||
__email__ = "alberto@albertopettarin.it" | ||
__status__ = "Development" | ||
|
||
from ipapy.__main__ import main | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
|
||
""" | ||
ipapy contains data and functions to work with IPA strings. | ||
This is the main script, intended to be run from command line. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
import argparse | ||
import sys | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "0.0.1" | ||
__email__ = "alberto@albertopettarin.it" | ||
__status__ = "Development" | ||
|
||
DESCRIPTION = "ipapy converts Unicode-IPA to/from ASCII-IPA" | ||
|
||
ARGUMENTS = [ | ||
{ | ||
"long": "command", | ||
"short": None, | ||
"nargs": None, | ||
"type": str, | ||
"default": None, | ||
"help": "[a2u|acheck|u2a|ucheck]" | ||
}, | ||
{ | ||
"long": "string", | ||
"short": None, | ||
"nargs": None, | ||
"type": str, | ||
"default": None, | ||
"help": "String to check or convert" | ||
}, | ||
#{ | ||
# "long": "--quiet", | ||
# "short": "-q", | ||
# "action": "store_true", | ||
# "help": "Do not output" | ||
#}, | ||
] | ||
|
||
def print_error(msg): | ||
""" | ||
Print the given error message and exit. | ||
:param str msg: the error message | ||
""" | ||
print(msg) | ||
sys.exit(1) | ||
|
||
def main(): | ||
""" | ||
Entry point. | ||
""" | ||
parser = argparse.ArgumentParser(description=DESCRIPTION) | ||
for arg in ARGUMENTS: | ||
if "action" in arg: | ||
if arg["short"] is not None: | ||
parser.add_argument(arg["short"], arg["long"], action=arg["action"], help=arg["help"]) | ||
else: | ||
parser.add_argument(arg["long"], action=arg["action"], help=arg["help"]) | ||
else: | ||
if arg["short"] is not None: | ||
parser.add_argument(arg["short"], arg["long"], nargs=arg["nargs"], type=arg["type"], default=arg["default"], help=arg["help"]) | ||
else: | ||
parser.add_argument(arg["long"], nargs=arg["nargs"], type=arg["type"], default=arg["default"], help=arg["help"]) | ||
vargs = vars(parser.parse_args()) | ||
command = vargs["command"] | ||
string = vargs["string"] | ||
if command == "u2a": | ||
print("TODO") | ||
elif command == "a2u": | ||
print("TODO") | ||
elif command == "acheck": | ||
print("TODO") | ||
elif command == "ucheck": | ||
print("TODO") | ||
else: | ||
parser.print_help() | ||
sys.exit(2) | ||
sys.exit(0) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
|
||
""" | ||
ipapy contains data and functions to work with IPA strings. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
import sys | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "0.0.1" | ||
__email__ = "alberto@albertopettarin.it" | ||
__status__ = "Development" | ||
|
||
PY2 = (sys.version_info[0] == 2) | ||
|
||
def is_unicode_string(s): | ||
if PY2: | ||
return isinstance(s, unicode) | ||
return isinstance(s, str) | ||
|
||
def int2unichr(n): | ||
if PY2: | ||
return unichr(n) | ||
return chr(n) | ||
|
||
def hex2unichr(s): | ||
return int2unichr(int(s, base=16)) | ||
|
||
|
||
|
Oops, something went wrong.