Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ It is now possible to use the Epitran class for English, Mandarin Chinese (Simpl

The most useful public method of the Epitran class is `transliterate`:

Epitran.**transliterate**(text, normpunc=False, ligatures=False). Convert `text` (in Unicode-encoded orthography of the language specified in the constructor) to IPA, which is returned. `normpunc` enables punctuation normalization and `ligatures` enables non-standard IPA ligatures like "ʤ" and "ʨ". Usage is illustrated below (Python 2):
Epitran.**transliterate**(text, normpunc=False, ligatures=False). Convert `text` (in Unicode-encoded orthography of the language specified in the constructor) to IPA, which is returned. `normpunc` enables punctuation normalization and `ligatures` enables non-standard IPA ligatures like "ʤ" and "ʨ". Usage is illustrated below:


```python
>>> epi.transliterate(u'Düğün')
u'dy\u0270yn'
>>> print(epi.transliterate(u'Düğün'))
>>> epi.transliterate('Düğün')
'dy\u0270yn'
>>> print(epi.transliterate('Düğün'))
dyɰyn
```

Expand All @@ -71,14 +71,14 @@ The codes for `character_category` are from the initial characters of the two ch
)
```

Here is an example of an interaction with ```word_to_tuples``` (Python 2):
Here is an example of an interaction with ```word_to_tuples```:


```python
>>> import epitran
>>> epi = epitran.Epitran('tur-Latn')
>>> epi.word_to_tuples(u'Düğün')
[(u'L', 1, u'D', u'd', [(u'd', [-1, -1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 0, -1])]), (u'L', 0, u'u\u0308', u'y', [(u'y', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, -1])]), (u'L', 0, u'g\u0306', u'\u0270', [(u'\u0270', [-1, 1, -1, 1, 0, -1, -1, 0, 1, -1, -1, 0, -1, 0, -1, 1, -1, 0, -1, 1, -1])]), (u'L', 0, u'u\u0308', u'y', [(u'y', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, -1])]), (u'L', 0, u'n', u'n', [(u'n', [-1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 0, -1])])]
>>> epi.word_to_tuples('Düğün')
[('L', 1, 'D', 'd', [('d', [-1, -1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 0, -1])]), ('L', 0, ', 'y', [('y', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, -1])]), ('L', 0, ', ', [(', [-1, 1, -1, 1, 0, -1, -1, 0, 1, -1, -1, 0, -1, 0, -1, 1, -1, 0, -1, 1, -1])]), ('L', 0, ', 'y', [('y', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, -1])]), ('L', 0, 'n', 'n', [('n', [-1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 0, -1])])]
```

### The Backoff class
Expand All @@ -87,7 +87,7 @@ Sometimes, when parsing text in more than one script, it is useful to employ a g

Backoff(lang_script_codes, cedict_file=None)

Note that the Backoff class does not currently support parameterized preprocessor and postprocessor application and does not support non-standard ligatures. It also does not support punctuation normalization. `lang_script_codes` is a list of codes like `eng-Latn` or `hin-Deva`. For example, if one was transcribing a Hindi text with many English loanwords and some stray characters of Simplified Chinese, one might use the following code (Python 3):
Note that the Backoff class does not currently support parameterized preprocessor and postprocessor application and does not support non-standard ligatures. It also does not support punctuation normalization. `lang_script_codes` is a list of codes like `eng-Latn` or `hin-Deva`. For example, if one was transcribing a Hindi text with many English loanwords and some stray characters of Simplified Chinese, one might use the following code:

```python
from epitran.backoff import Backoff
Expand All @@ -109,7 +109,7 @@ The Backoff class has the following public methods:
* **xsampa_list**: returns a list of X-SAMPA (ASCII) strings, each of which is
phoneme

Consider the following example (Python 3):
Consider the following example:

```python
>>> backoff.transliterate('हिन्दी')
Expand Down Expand Up @@ -157,13 +157,13 @@ Its principle method is ```word_to_segs```:
VectorWithIPASpace.**word_to_segs**(word, normpunc=False). `word` is a Unicode string. If the keyword argument *normpunc* is set to True, punctuation discovered in `word` is normalized to ASCII equivalents.


A typical interaction with the ```VectorsWithIPASpace``` object via the ```word_to_segs``` method is illustrated here (Python 2):
A typical interaction with the ```VectorsWithIPASpace``` object via the ```word_to_segs``` method is illustrated here:

```python
>>> import epitran.vector
>>> vwis = epitran.vector.VectorsWithIPASpace('uzb-Latn', ['uzb-Latn'])
>>> vwis.word_to_segs(u'darë')
[(u'L', 0, u'd', u'd\u032a', u'40', [-1, -1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 0, -1]), (u'L', 0, u'a', u'a', u'37', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, -1]), (u'L', 0, u'r', u'r', u'54', [-1, 1, 1, 1, 0, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 0, 0, 0, -1, 0, -1]), (u'L', 0, u'e\u0308', u'ja', u'46', [-1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, 0, -1, 1, -1, -1, -1, 0, -1]), (u'L', 0, u'e\u0308', u'ja', u'37', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, -1])]
>>> vwis.word_to_segs('darë')
[('L', 0, 'd', 'd̪', '40', [-1, -1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 0, -1]), ('L', 0, 'a', 'a', '37', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, -1]), ('L', 0, 'r', 'r', '54', [-1, 1, 1, 1, 0, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 0, 0, 0, -1, 0, -1]), ('L', 0, ', 'ja', '46', [-1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, 0, -1, 1, -1, -1, -1, 0, -1]), ('L', 0, ', 'ja', '37', [1, 1, -1, 1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, -1])]
```


Expand Down Expand Up @@ -379,7 +379,7 @@ Note that major languages, including **French**, are missing from this table due

## Installation of Flite (for English G2P)

For use with most languages, Epitran requires no special installation steps. It can be installed as an ordinarary python package, either with `pip` or by running `python setup.py install` in the root of the source directory. However, English G2P in Epitran relies on CMU Flite, a speech synthesis package by Alan Black and other speech researchers at Carnegie Mellon University. For the current version of Epitran, you should follow the installation instructions for `lex_lookup`, which is used as the default G2P interface for Epitran.
For use with most languages, Epitran requires no special installation steps. **Epitran requires Python 3.10 or higher.** It can be installed as an ordinary python package, either with `pip` or by running `python setup.py install` in the root of the source directory. However, English G2P in Epitran relies on CMU Flite, a speech synthesis package by Alan Black and other speech researchers at Carnegie Mellon University. For the current version of Epitran, you should follow the installation instructions for `lex_lookup`, which is used as the default G2P interface for Epitran.

### `t2p`

Expand Down Expand Up @@ -523,7 +523,7 @@ c -> s / _ (i|e)
```


For a complete guide to `regex` regular expressions, see the documentation for [`re`](https://docs.python.org/2/library/re.html) and for [`regex`](https://pypi.python.org/pypi/regex), specifically.
For a complete guide to `regex` regular expressions, see the documentation for [`re`](https://docs.python.org/3/library/re.html) and for [`regex`](https://pypi.org/project/regex/), specifically.

Fragments of regular expressions can be assigned to symbols and reused throughout a file. For example, symbol for the disjunction of vowels in a language can be used in a rule that changes /u/ into /w/ before vowels:

Expand Down
4 changes: 1 addition & 3 deletions epitran/backoff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import (print_function, absolute_import,
unicode_literals)

import regex as re
from . import _epitran
Expand Down Expand Up @@ -35,7 +33,7 @@ def transliterate(self, token):
Args:
token (unicode): orthographic text
Returns:
unicode: transliteration as Unicode IPA string
str: transliteration as Unicode IPA string
"""
tr_list = []
while token:
Expand Down
4 changes: 2 additions & 2 deletions epitran/bin/connl2engipaspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from collections import Counter

import unicodecsv as csv
import csv

import epitran
import epitran.flite
Expand Down Expand Up @@ -56,7 +56,7 @@ def add_file(flite, ft, fn):
def print_space(output, space):
pairs = enumerate(sorted(filter(lambda x: x, space.keys())))
with open(output, 'wb') as f:
writer = csv.writer(f, encoding='utf-8')
writer = csv.writer(f)
for i, char in pairs:
writer.writerow((i, char))

Expand Down
4 changes: 2 additions & 2 deletions epitran/bin/connl2ipaspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import epitran
import panphon
import unicodecsv as csv
import csv

logger = logging.getLogger('epitran')

Expand Down Expand Up @@ -74,7 +74,7 @@ def add_file_op(epi, ft, fn):
def print_space(output, space):
pairs = enumerate(sorted(filter(lambda x: x, space.keys())))
with open(output, 'wb') as f:
writer = csv.writer(f, encoding='utf-8')
writer = csv.writer(f)
for i, char in pairs:
writer.writerow((i, char))

Expand Down
1 change: 0 additions & 1 deletion epitran/bin/detectcaps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

import unicodedata
import fileinput
Expand Down
7 changes: 3 additions & 4 deletions epitran/bin/isbijective.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env pythoh
from __future__ import print_function

import glob

import unicodecsv as csv
import csv


def read_map(fn):
with open(fn, 'rb') as f:
reader = csv.reader(f, encoding='utf-8')
with open(fn, 'r', encoding='utf-8') as f:
reader = csv.reader(f)
next(reader)
return [(a, b) for [a, b] in reader]

Expand Down
5 changes: 2 additions & 3 deletions epitran/bin/ltf2ipaspace.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

import argparse
import glob
import os.path

from lxml import etree
import unicodecsv as csv
import csv

import epitran
import panphon.featuretable
Expand All @@ -34,7 +33,7 @@ def read_input(input_, langscript):

def write_output(output, space):
with open(output, 'wb') as f:
writer = csv.writer(f, encoding='utf-8')
writer = csv.writer(f)
for n, ch in enumerate(sorted(list(space))):
writer.writerow((n, ch))

Expand Down
7 changes: 3 additions & 4 deletions epitran/bin/migraterules.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env Python
# -*- coding: utf-8 -*-

from __future__ import (print_function, unicode_literals, absolute_import)

import glob
import re
import io

Check failure on line 7 in epitran/bin/migraterules.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

epitran/bin/migraterules.py:7:8: F401 `io` imported but unused

import unicodecsv
import csv

Check failure on line 9 in epitran/bin/migraterules.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

epitran/bin/migraterules.py:9:8: F401 `csv` imported but unused


def build_rule(fields):
Expand All @@ -21,10 +20,10 @@


def main():
for csv in glob.glob('*.csv'):

Check failure on line 23 in epitran/bin/migraterules.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F402)

epitran/bin/migraterules.py:23:9: F402 Import `csv` from line 9 shadowed by loop variable
txt = re.match('[A-Za-z-]+', csv).group(0) + '.txt'
with open(csv, 'rb') as f, io.open(txt, 'w', encoding='utf-8') as g:
reader = unicodecsv.reader(f, encoding='utf-8')
with open(csv, 'r', encoding='utf-8') as f, open(txt, 'w', encoding='utf-8') as g:
reader = csv.reader(f)
next(reader)
for fields in reader:
if re.match('\s*%', fields[0]):
Expand Down
3 changes: 1 addition & 2 deletions epitran/bin/reromanize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

from __future__ import print_function

import epitran.reromanize
import argparse
Expand Down
8 changes: 4 additions & 4 deletions epitran/bin/space2punc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import sys
import unicodedata
import unicodecsv as csv
import csv


def main(fns, fnn):
punc = set()
for fn in fns:
with open(fn, 'rb') as f:
reader = csv.reader(f, encoding='utf-8')
with open(fn, 'r', encoding='utf-8') as f:
reader = csv.reader(f)
for _, s in reader:
if len(s) == 1 and unicodedata.category(s)[0] == u'P':
punc.add(s)
with open(fnn, 'wb') as f:
writer = csv.writer(f, encoding='utf-8')
writer = csv.writer(f)
for mark in sorted(list(punc)):
writer.writerow([mark])

Expand Down
1 change: 0 additions & 1 deletion epitran/bin/testvectorgen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

from __future__ import print_function

import argparse
import codecs
Expand Down
1 change: 0 additions & 1 deletion epitran/bin/uigtransliterate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function

import fileinput
import epitran
Expand Down
2 changes: 0 additions & 2 deletions epitran/cedict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import codecs

Expand Down
6 changes: 3 additions & 3 deletions epitran/data/map/count_phones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import epitran.xsampa
import panphon
import unicodecsv as csv
import csv


def main(fn):
ft = panphon.FeatureTable()
xs = epitran.xsampa.XSampa()
with open(fn, 'rb') as f:
reader = csv.reader(f, encoding='utf-8')
with open(fn, 'r', encoding='utf-8') as f:
reader = csv.reader(f)
next(reader)
phones = set()
for orth, phon in reader:
Expand Down
5 changes: 2 additions & 3 deletions epitran/epihan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- utf-8 -*-
from __future__ import print_function, unicode_literals, division, absolute_import

import os.path

Expand Down Expand Up @@ -56,10 +55,10 @@ def normalize_punc(self, text):
"""Normalize punctutation in a string

Args:
text (unicode): an orthographic string
text (str): an orthographic string

Return:
unicode: an orthographic string with punctation normalized to
str: an orthographic string with punctation normalized to
Western equivalents
"""
for a, b in self.punc:
Expand Down
Loading
Loading