Skip to content

Commit

Permalink
Added can_map_ipa_string to Mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Pettarin committed May 26, 2016
1 parent 15b50a1 commit a9b1be2
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

v0.0.5 (2016-05-25)
-------------------

#. Added can_map_ipa_string to Mapper
#. Fixed a bug in ASCIIMapper


v0.0.4 (2016-05-24)
-------------------

Expand Down
6 changes: 4 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.4
* Date: 2016-05-24
* Version: 0.0.5
* Date: 2016-05-26
* Developer: [Alberto Pettarin](http://www.albertopettarin.it/)
* License: the MIT License (MIT)
* Contact: [click here](http://www.albertopettarin.it/contact.html)
Expand Down Expand Up @@ -163,6 +163,8 @@ s_ipa.consonants # "knknθld͡ʒ" (consona
s_ipa.vowels # "əiææɑəi" (vowels)
s_ipa.letters # "əkinækænθɑləd͡ʒi" (vowels and consonants)
s_ipa.cns_vwl # "əkinækænθɑləd͡ʒi" (vowels and consonants)
s_ipa.cns_vwl_pstr # "əˈkinækænˈθɑləd͡ʒi" ( + primary stress marks)
s_ipa.cns_vwl_pstr_long # "əˈkiːnækænˈθɑləd͡ʒi" ( + long marks)
s_ipa.cns_vwl_str # "əˈkinæˌkænˈθɑləd͡ʒi" ( + stress marks)
s_ipa.cns_vwl_str_len # "əˈkiːnæˌkænˈθɑləd͡ʒi" ( + length marks)
s_ipa.cns_vwl_str_len_wb # "əˈkiːn æˌkænˈθɑləd͡ʒi" ( + word breaks)
Expand Down
6 changes: 4 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.4
- Date: 2016-05-24
- Version: 0.0.5
- Date: 2016-05-26
- Developer: `Alberto Pettarin <http://www.albertopettarin.it/>`__
- License: the MIT License (MIT)
- Contact: `click here <http://www.albertopettarin.it/contact.html>`__
Expand Down Expand Up @@ -168,6 +168,8 @@ As A Python Module
s_ipa.vowels # "əiææɑəi" (vowels)
s_ipa.letters # "əkinækænθɑləd͡ʒi" (vowels and consonants)
s_ipa.cns_vwl # "əkinækænθɑləd͡ʒi" (vowels and consonants)
s_ipa.cns_vwl_pstr # "əˈkinækænˈθɑləd͡ʒi" ( + primary stress marks)
s_ipa.cns_vwl_pstr_long # "əˈkiːnækænˈθɑləd͡ʒi" ( + long marks)
s_ipa.cns_vwl_str # "əˈkinæˌkænˈθɑləd͡ʒi" ( + stress marks)
s_ipa.cns_vwl_str_len # "əˈkiːnæˌkænˈθɑləd͡ʒi" ( + length marks)
s_ipa.cns_vwl_str_len_wb # "əˈkiːn æˌkænˈθɑləd͡ʒi" ( + word breaks)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.4
0.0.5
2 changes: 1 addition & 1 deletion bin/ipapy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ __copyright__ = "Copyright 2016, Alberto Pettarin (www.albertopettarin.it)"
__license__ = "MIT"
__email__ = "alberto@albertopettarin.it"

__version__ = "0.0.4"
__version__ = "0.0.5"
__status__ = "Production"

def main():
Expand Down
2 changes: 1 addition & 1 deletion ipapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
__license__ = "MIT"
__email__ = "alberto@albertopettarin.it"

__version__ = "0.0.4"
__version__ = "0.0.5"
__status__ = "Production"

def ipa_substrings(unicode_string, single_char_parsing=False):
Expand Down
6 changes: 4 additions & 2 deletions ipapy/asciimapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

class ASCIIMapper(Mapper):

DATA_FILE_PATH = u"asciiipa.dat"

def __init__(self):
super(ASCIIMapper, self).__init__(self._load_data())

Expand All @@ -29,15 +31,15 @@ def _load_data(self):
"""
ipadesc_to_ascii_str = dict()
for line in load_data_file(
file_path=u"asciiipa.dat",
file_path=self.DATA_FILE_PATH,
file_path_is_relative=True,
line_format=u"ssxA"
):
i_type, i_desc, i_ascii = line
name = "%s %s" % (i_desc, i_type)
descriptors = frozenset([p for p in name.split() if len(p) > 0])
if len(i_ascii) == 0:
raise ValueError("Data file '%s' contains a bad line: '%s'" % (ASCII_IPA_DATA_FILE_PATH, line))
raise ValueError("Data file '%s' contains a bad line: '%s'" % (self.DATA_FILE_PATH, line))
ipadesc_to_ascii_str[descriptors] = i_ascii[0]
return ipadesc_to_ascii_str

Expand Down
14 changes: 14 additions & 0 deletions ipapy/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ def ipa_descriptors(self):
"""
return list(self.ipadescriptors_to_str.keys())

def can_map_ipa_string(self, ipa_string):
"""
Return ``True`` if the mapper can map all the IPA characters
in the given IPA string.
:param IPAString ipa_string: the IPAString to be parsed
:rtype: bool
"""
for ipa_char in ipa_string:
canonical = ipa_char.canonical_representation
if not canonical in self.ipadescriptors_to_str:
return False
return True

def map_ipa_string(self, ipa_string, ignore=False, return_as_list=False):
"""
Convert the given IPAString to a string
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
__license__ = "MIT"
__email__ = "alberto@albertopettarin.it"

__version__ = "0.0.4"
__version__ = "0.0.5"
__status__ = "Production"

setup(
name="ipapy",
packages=["ipapy", "ipapy.data"],
package_data={"ipapy.data": ["*.dat"]},
version="0.0.4.0",
version="0.0.5.0",
description="ipapy is a Python module to work with IPA strings",
author="Alberto Pettarin",
author_email="alberto@albertopettarin.it",
Expand Down

0 comments on commit a9b1be2

Please sign in to comment.