# Skeleton version of an object-oriented approach to segmental phonology to illustrate OO concepts # Phone object class # A phone here is not any particular type of class, just a general object class phone(object): # Used when creating a new phone object # Assign the symbol to represent the phone def __init__(self, symbol='a'): self.symbol = symbol # How to print a symbol object def __str__(self): return self.symbol # Retrieve the symbol from the object def getSymbol(self): return self.symbol # Compare two phones on the basis of the ASCII value of their representations # This is merely for illustrative purposes def __cmp__(self, other): if self.symbol < other.symbol: return -1 elif self.symbol > other.symbol: return 1 else: return 0 # A consonant is a type of phone and thus inherits from it # It thus has all behavior of phones (plus anything new) class consonant(phone): # Change the voicing on a consonant if it's in /ptkbdg/ # Only consonants will be able to do this as defined def changeVoicing(self): if self.symbol == 't': self.symbol = 'd' elif self.symbol == 'd': self.symbol = 't' elif self.symbol == 'p': self.symbol = 'b' elif self.symbol == 'b': self.symbol = 'p' elif self.symbol == 'k': self.symbol = 'g' elif self.symbol == 'g': self.symbol = 'k' # Another inheritor of phone class vowel(phone): # We don't define any useful additional functionality, so just use a placeholder pass