Package: panphon
PanPhonCiting PanPhonIf you use PanPhon in research, please cite thefollowing paper:David R. Mortensen, Patrick Littell, Akash Bharadwaj, Kartik Goyal, Chris Dyer, Lori Levin (2016). "PanPhon: A Resource for Mapping IPA Segments to Articulatory Feature Vectors."Proceedings of COLING 2016, the 26th International Conference on Computational Linguistics: Technical Papers, pages 3475–3484, Osaka, Japan, December 11-17 2016.Or in BibTeX:@inproceedings{Mortensen-et-al:2016,
  author    = {David R. Mortensen and
               Patrick Littell and
               Akash Bharadwaj and
               Kartik Goyal and
               Chris Dyer and
               Lori S. Levin},
  title     = {PanPhon: {A} Resource for Mapping {IPA} Segments to Articulatory Feature Vectors},
  booktitle = {Proceedings of {COLING} 2016, the 26th International Conference on Computational Linguistics: Technical Papers},
  pages     = {3475--3484},
  publisher = {{ACL}},
  year      = {2016}
}This package constitutes a database of segments in the International Phonetic Alphabet (IPA) and their equivalents in terms of (articulatory) phonological features. They include both data files and the toolgenerate_ipa_all.py, which allows the application of rules for diacritics and modifiers to collections of IPA characters, data files, and configuration/rule files and well as the toolvalidate_ipa.py, which checks Unicode IPA text from STDIN for well-formedness.Python API for Accessing Phonological Features of IPA SegmentsTheFeatureTableclass in thepanphonmodule provides a straightforward API that allows users and developers to access the segment-feature relationships encoded in the IPA database consisting of the filespanphon/data/ipa_bases.csvanddiacritic_definitions.yml.Note that a new API using faster, more rational, data structures (see theSegmentclass inpanphon.segment) has been introduced. The old API is still available in the module_panphon.>>>importpanphon>>>ft=panphon.FeatureTable()>>>ft.word_fts(u'swit')[<Segment[-syl,-son,+cons,+cont,-delrel,-lat,-nas,0strid,-voi,-sg,-cg,+ant,+cor,-distr,-lab,-hi,-lo,-back,-round,-velaric,0tense,-long]>,<Segment[-syl,+son,-cons,+cont,-delrel,-lat,-nas,0strid,+voi,-sg,-cg,-ant,-cor,0distr,+lab,+hi,-lo,+back,+round,-velaric,0tense,-long]>,<Segment[+syl,+son,-cons,+cont,-delrel,-lat,-nas,0strid,+voi,-sg,-cg,0ant,-cor,0distr,-lab,+hi,-lo,-back,-round,-velaric,+tense,-long]>,<Segment[-syl,-son,+cons,-cont,-delrel,-lat,-nas,0strid,-voi,-sg,-cg,+ant,+cor,-distr,-lab,-hi,-lo,-back,-round,-velaric,0tense,-long]>]>>>ft.word_fts(u'swit')[0].match({'cor':1})True>>>ft.word_fts(u'swit')[0]>={'cor':1}True>>>ft.word_fts(u'swit')[1]>={'cor':1}False>>>ft.word_to_vector_list(u'sauɹ',numeric=False)[[u'-',u'-',u'+',u'+',u'-',u'-',u'-',u'0',u'-',u'-',u'-',u'+',u'+',u'-',u'-',u'-',u'-',u'-',u'-',u'-',u'0',u'-'],[u'+',u'+',u'-',u'+',u'-',u'-',u'-',u'0',u'+',u'-',u'-',u'0',u'-',u'0',u'-',u'-',u'+',u'+',u'-',u'-',u'+',u'-'],[u'+',u'+',u'-',u'+',u'-',u'-',u'-',u'0',u'+',u'-',u'-',u'0',u'-',u'0',u'+',u'+',u'-',u'+',u'+',u'-',u'+',u'-'],[u'-',u'+',u'-',u'+',u'-',u'-',u'-',u'0',u'+',u'-',u'-',u'+',u'+',u'-',u'-',u'+',u'-',u'+',u'+',u'-',u'0',u'-']]Summary of FunctionalityOperations on feature sets and segmentsTheFeatureTableclass includes a broad range of operations on features and segments (consonants and vowels).Converting words to feature arraysThepanphonclass includes the function word2array which takes a list of feature names (as a list of strings) and a panphon word (from FeatureTable().word_fts()) and returns a NumPy array where each row corresponds to a segment in the word and each column corresponds to one of the specified features. Basic usage is illustrated in the following example:>>>importpanphon>>>ft=panphon.FeatureTable()>>>ft.word_array(['syl','son','cont'],u'sɑlti')array([[-1,-1,1],[1,1,1],[-1,1,1],[-1,-1,-1],[1,1,1]])Segment manipulationsTheSegmentclass, defined in thepanphon.segmentmodule, is used to represent analyzed segments in the newpanphon.FeatureTableclass (code found inpanphon.featuretable). It provides performance advantages over the old list-of-tuples representation, is more Pythonic, and provides additional functionality.ConstructionThere are two main ways to construct aSegmentobject:>>>frompanphon.segmentimportSegment>>>Segment(['syl','son','cont'],{'syl':-1,'son':-1,'cont':1})<Segment[-syl,-son,+cont]>>>>Segment(['syl','son','cont'],ftstr='[-syl, -son, +cont]')<Segment[-syl,-son,+cont]>In both cases, the first argument passed to the constructor is a list of feature names. This specifies what features a segment has as well as their canonical ordering (used, for example, when a feature vector for a segment is returned as a list). The second argument is a dictionary of feature name-feature value pairs. The feature values are integers from the set {-1, 0 1} (equivalent to {-, 0, +}). This dictionary can be omitted if the keyword argumentftstris included. This string is scanned for sequences of (-|0|+)(\w+), which are interpreted as name-value (really value-name) pairs.Basic querying and updatingSegmentobjects implement a dictionary-like interface for manipulating key-value pairs:>>>a=Segment(['syl','son','cont'],{'syl':-1,'son':-1,'cont':1})>>>a<Segment[-syl,-son,+cont]>>>>a['syl']-1>>>a['son']=1>>>a<Segment[-syl,+son,+cont]>>>>a.update({'son':-1,'cont':-1})>>>a<Segment[-syl,-son,-cont]>Set operationsThematchmethod asks whether theSegmentobject on which it is called has a superset of the features contained in the dictionary passed to it as an argument. The >= operator is an alias for thematchmethod:>>>a=Segment(['syl','son','cont'],{'syl':-1,'son':-1,'cont':1})>>>a.match({'son':-1,'cont':1})True>>>a.match({'son':-1,'cont':-1})False>>>a>={'son':-1,'cont':1}True>>>a>={'son':1,'cont':1}FalseTheintersectionmethod asks which features theSegmentobject on which it is called and the dictionary orSegmentobject that is passed to it as an argument share. The & operator is an alias for theintersectionmethod:>>>a=Segment(['syl','son','cont'],{'syl':-1,'son':-1,'cont':1})>>>a.intersection({'syl':-1,'son':1,'cont':-1})<Segment[-syl]>>>>a&{'syl':-1,'son':1,'cont':-1}<Segment[-syl]>Vector representationsSegmentobjects can return their vector representations, either as a list of integers or as a list of strings, using thenumericandstringmethods:>>>a=Segment(['syl','son','cont'],{'syl':-1,'son':-1,'cont':1})>>>a.numeric()[-1,-1,1]>>>a.strings()[u'-',u'-',u'+']Fixed-width pattern matchingTheFeatureTableclasses also allows matching of fixed-width, feature-based patterns.Sonority calculationsTheSonorityclass has methods for computing sonority scores for segments.Feature edit distanceTheDistanceclass includes methods for calculating edit distance, both in which the cost of substitutions is based upon Hamming distance between the feature vectors and in which the cost of substitutions are based upon edit weights for individual features.Thepanphon.distanceModuleThis module includes theDistanceclass, which includes various methods for computing the distance between Unicode IPA strings, including convenience methods (really "inconvenience methods") for computing Levenshtein distance, but--more importantly--methods for computing similarity metrics related to articulatory features. The methods include the following:panphon.distance.Distance.levenshtein_distanceA Python implementation of Levenshtein's string edit distance.panphon.distance.Distance.fast_levenshtein_distanceA C implementation of Levenshtein's string edit distance. Unsurprisingly, must faster than the former.panphon.distance.Distance.dogol_prime_distanceFast Levenshtein distance after collapsing segments into an enhanced version of Dogolpolsky's equivalence classes.panphon.distance.Distance.feature_edit_distanceEdit distance where each feature-edit has cost 1/22. Edits from unspecified to specified cost 1/44.panphon.distance.Distance.hamming_feature_edit_distanceEdit distance where each feature-edit has cost 1/22. Edits from unspecified to specified also cost 1/22. Insertions and substitutions each cost 1.panphon.distance.Distance.weighted_feature_edit_distanceEdit distance where costs of feature edits are differently weighted depending on their class and subjective variability. All of these methods have the same interface and patterns of usage, demonstrated below:>>>importpanphon.distance>>>dst=panphon.distance.Distance()>>>dst.dogol_prime_distance(u'pops',u'bobz')0>>>dst.dogol_prime_distance(u'pops',u'bobo')1ScriptsThegenerate_ipa_all.pyScriptSummaryThis small Python program allows the user to apply sets of rules, defined in YAML, for adding diacritics and modifiers to IPA segments based upon their phonological features.UsageTo generate a segment features file (ipa_all.csv), use the followingin the panphon data directory:$generate_ipa_all.pyipa_bases.csv-ddiacritic_definitions.yml-ssort_order.ymlipa_all.csvNote that this will overwrite your existingipa_all.csvfile, which is often what you want.Data FilesThis package also includes multiple data files. The most important of these is ipa_bases.csv, a CSV table of IPA characters with definitions in terms of phonological features. From it, and thediacritics_definitions.ymlfile, the comprehensiveipa_all.csvis generated.IPA Character Databases:ipa_bases.csvandipa_all.csvThe IPA Character Table is a CSV file in which the first column contains an IPA segment and each subsequent column contains a phonological feature, coded as +, -, or 0. The features are as follows:syl: syllabicson: sonorantcons: consonantalcont: continuantdelrel: delayed releaselat: lateralnas: nasalstrid: stridentvoi: voicesg: spread glottiscg: constricted glottisant: anteriorcor: coronaldistr: distributedlab: labialhi: high (vowel/consonant, not tone)lo: low (vowel/consonant, not tone)back: backround: roundvelaric: velaric airstream mechanism (click)tense: tenselong: longInspiration for the data in these tables is drawn primarily from two sources: the data files forHsSPEand Bruce Hayes'sfeature spreadsheet. It has since be re-rationalizeds based on evidence from a wide range of sources. As such, any special relationship to these prior inspirations has been eliminated.The IPA Character Tableipa_bases.csvis intended to contain all of the unmodified segmental symbols in IPA, as well as all common affricates and dually-articulated segments. It is meant to be augmented by the rule-driven application of diacritics and modifiers.Configuration and Rule FilesThis package includes two files that control the behavior ofgenerate_ipa_all.py. These are intended to be edited by the end user. Both are written inYAML, a standardized, human-readable and human-editable data serialization language.Sort Order Specification: sort_order.ymlThe filesort_order.ymlcontrols the ordering of segments in the output of the Diacritic Application Tool. It is a sequence of maps, each with two fields:nameThe name of a feature.reverseA boolean value (True or False) specifying whether sorting on the named feature will be reversed or not.The order of the features determines the priority of sorting.The filesort_order_schema_.ymlis aKwalifyschema that defines a syntactically valid sort order file.Diacritic and Modifier Rules: diacritic_definitions.ymlThe most important file for controlling the Diacritic Application Tool isdiacritic_definitions.yml, a list of rules for applying diacritics and modifiers to IPA segments based on their phonological features. It has two sections,diacriticsandcombinations. Each of these is the key to an item in the top-level map.DiacriticsThe keydiacriticspoints to a list of rules for applying diacritics/modifiers to bases. Each rule is a map with the following fields:marker.The Unicode diacritic or modifier.name.The name of the series derived from applying the diacritic or modifier.postion.The position of the diacritic relative to the base (pre or post).conditions.A list of conditions, each of them consisting of an associative array of feature specifications, under which the diacritic or modifier will be applied to a base.exclude.A sequence of segments to be excluded from the application of the diacritic/modifier even if they match the conditions.content.The feature specifications that will be set if the diacritic or modifier is applied, given as a map of feature specifications.CombinationsThe keycombinationslikewise points to a list of rules for combining the rules indiacritics. These rules are very simple, and include only the following fields:name.The name of the combined category.combines.A sequence of the names of the rules fromdiacriticsthat are to be combined.The filediacritic_definitions_schema.ymlis aKwalifyschema that defines a syntactically valid diacritics definition file.