#!/usr/bin/python # Time-stamp: <2005-03-12 05:56:34 poser> # # Translate "North American IPA" to standard IPA. # # Copyright (C) 2004, 2005 William J. Poser (billposer@alum.mit.edu) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or go to the web page: http://www.gnu.org/licenses/gpl.txt. import sys import codecs AsciiP = 0 CntP = 1 #Handle command line arguments argc = len(sys.argv) if argc > 1: if sys.argv[1] == "-h": sys.stdout.write("Filter to translate North American IPA to standard IPA.\n") sys.stdout.write("Input should be in UTF-8 Unicode.\n") sys.exit(1) if sys.argv[1] == "-v": sys.stdout.write("StandardizeIPA 1.1\n") sys.exit(1) #Now do main work (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup('utf-8') infile = utf8_reader(sys.stdin) outfile = utf8_writer(sys.stdout) while 1: try: ch = infile.read(1) if not ch: sys.exit(0) c = ord(ch) if c == 0x0079: # high front glide outfile.write(unichr(0x006A)) elif c == 0x00FC: # high front rounded vowel outfile.write(unichr(0x0079)) elif c == 0x0161: # voiceless palatal fricative outfile.write(unichr(0x0283)) elif c == 0x017E: # voiced palatal fricative outfile.write(unichr(0x0292)) elif c == 0x010D: # voiceless palatal affricate outfile.write(unichr(0x0074)) outfile.write(unichr(0x0283)) elif c == 0x01F0: #voiced palatal affricate outfile.write(unichr(0x0064)) outfile.write(unichr(0x0292)) elif c == 0x006A: #voiced palatal affricate outfile.write(unichr(0x0064)) outfile.write(unichr(0x0292)) elif c == 0x00F1: #palatal nasal outfile.write(unichr(0x0272)) elif c == 0x00F6: #mid front rounded vowel outfile.write(unichr(0x0153)) else: outfile.write(ch) except IOError: sys.exit(0) except SystemExit: sys.exit(0)