Skip to content

Commit

Permalink
Generic data loading. Ready v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Pettarin committed May 21, 2016
1 parent ad12e4e commit 3bd0698
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

**ipapy** is a Python module to work with IPA strings.

* Version: 0.0.1
* Date: 2016-05-19
* Version: 0.0.2
* Date: 2016-05-21
* Developer: [Alberto Pettarin](http://www.albertopettarin.it/)
* License: the MIT License (MIT)
* Contact: [click here](http://www.albertopettarin.it/contact.html)
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ipapy

**ipapy** is a Python module to work with IPA strings.

- Version: 0.0.1
- Date: 2016-05-19
- Version: 0.0.2
- Date: 2016-05-21
- Developer: `Alberto Pettarin <http://www.albertopettarin.it/>`__
- License: the MIT License (MIT)
- Contact: `click here <http://www.albertopettarin.it/contact.html>`__
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
2 changes: 1 addition & 1 deletion bin/ipapy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from ipapy.__main__ import main as package_main
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
2 changes: 1 addition & 1 deletion ipapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
2 changes: 1 addition & 1 deletion ipapy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
17 changes: 14 additions & 3 deletions ipapy/asciiipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
from __future__ import print_function

from ipapy.compatibility import hex_to_unichr
from ipapy.data import load_csv_file
from ipapy.data import load_data_file
from ipapy.ipastring import IPAString

__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

ASCII_IPA_DATA_FILE_FIELD_SEPARATOR = u","
""" Field separator for the data file """

ASCII_IPA_DATA_FILE_COMMENT = u"#"
""" Ignore lines starting with this character """

ASCII_IPA_DATA_FILE_PATH = "asciiipa.dat"
"""
Path of the built-in IPA database,
Expand All @@ -34,7 +40,12 @@ def load_ascii_ipa_data():
"""
ascii_ipa_signs = []
ipa_descriptors_to_ascii_ipa = {}
for line in load_csv_file(ASCII_IPA_DATA_FILE_PATH, 4):
for line in load_data_file(
relative_file_path=ASCII_IPA_DATA_FILE_PATH,
comment_string=ASCII_IPA_DATA_FILE_COMMENT,
field_separator=ASCII_IPA_DATA_FILE_FIELD_SEPARATOR,
values_per_line=4
):
# unpack line
i_type, i_desc, i_unicode, i_ascii = line
# if i_ascii is given as 4 hex chars (e.g., 00A1), convert it to unicode
Expand Down
2 changes: 1 addition & 1 deletion ipapy/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
27 changes: 16 additions & 11 deletions ipapy/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

DATA_FILE_FIELD_SEPARATOR = u","
""" Field separator for the data file """

DATA_FILE_COMMENT = u"#"
""" Ignore lines starting with this character """

IPA_DATA_FILE_CODEPOINT_SEPARATOR = u" "
"""
Separator between Unicode codepoints or
Unicode compound strings for a given IPAChar
"""

IPA_DATA_FILE_COMMENT = u"#"
""" Ignore lines starting with this character """

IPA_DATA_FILE_COMPOUND_OPERATOR = u"+"
"""
Operator to specify Unicode compound strings,
e.g. 0070+032A = LATIN SMALL LETTER P + COMBINING BRIDGE BELOW
"""

IPA_DATA_FILE_FIELD_SEPARATOR = u","
""" Field separator for the data file """

IPA_DATA_FILE_NOT_AVAILABLE = u"N/A"
""" Placeholder for an IPAChar not encoded in Unicode """

Expand All @@ -54,7 +54,7 @@
relative to the ``data/`` directory
"""

def load_csv_file(relative_file_path, values_per_line=None):
def load_data_file(relative_file_path, comment_string, field_separator, values_per_line=None):
"""
Load a comma-separated file, returning a list of tuples.
Expand All @@ -73,9 +73,9 @@ def load_csv_file(relative_file_path, values_per_line=None):
with io.open(file_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if (len(line) > 0) and (not line.startswith(DATA_FILE_COMMENT)):
if (len(line) > 0) and (not line.startswith(comment_string)):
# unpack line
values = line.split(DATA_FILE_FIELD_SEPARATOR)
values = line.split(field_separator)
if (values_per_line is not None) and (len(values) != values_per_line):
raise ValueError("Data file '%s' contains a bad line: '%s'" % (file_path, line))
tuples.append(tuple(values))
Expand All @@ -94,7 +94,12 @@ def load_ipa_data():
unicode_to_ipa = {}
ipa_to_unicode = {}
max_key_length = 0
for line in load_csv_file(IPA_DATA_FILE_PATH, 3):
for line in load_data_file(
relative_file_path=IPA_DATA_FILE_PATH,
comment_string=IPA_DATA_FILE_COMMENT,
field_separator=IPA_DATA_FILE_FIELD_SEPARATOR,
values_per_line=3
):
# unpack data
i_type, i_desc, i_unicode = line

Expand Down
2 changes: 1 addition & 1 deletion ipapy/ipachar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
2 changes: 1 addition & 1 deletion ipapy/ipastring.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
2 changes: 1 addition & 1 deletion ipapy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
__author__ = "Alberto Pettarin"
__copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__version__ = "0.0.1"
__version__ = "0.0.2"
__email__ = "[email protected]"
__status__ = "Production"

setup(
name="ipapy",
packages=["ipapy", "ipapy.data"],
package_data={"ipapy.data": ["*.dat"]},
version="0.0.1.0",
version="0.0.2.0",
description="ipapy is a Python module to work with IPA strings",
author="Alberto Pettarin",
author_email="[email protected]",
Expand Down

0 comments on commit 3bd0698

Please sign in to comment.