Using Python for a demonstration in historical linguistics

Peter Otten __peter__ at web.de
Sat Nov 6 11:09:34 CET 2010


Dax Bloom wrote:

> Hello,
> 
> In the framework of a project on evolutionary linguistics I wish to
> have a program to process words and simulate the effect of sound
> shift, for instance following the Rask's-Grimm's rule. I look to have
> python take a dictionary file or a string input and replace the
> consonants in it with the Grimm rule equivalent. For example:
> bʰ → b → p → f
> dʰ → d → t → θ
> gʰ → g → k → x
> gʷʰ → gʷ → kʷ → xʷ
> If the dictionary file has the word "Abe" I want the program to
> replace the letter b with f forming the word "Afe" and write the
> result in a tabular file. How easy is it to find the python functions
> to do that?
> 
> Best regards,
> 
> Dax Bloom

>>> s = """
... In the framework of a project on evolutionary linguistics I wish to
... have a program to process words and simulate the effect of sound
... shift, for instance following the Rask's-Grimm's rule. I look to have
... python take a dictionary file or a string input and replace the
... consonants in it with the Grimm rule equivalent. For example:
... """
>>> rules = ["bpf", ("d", "t", "th"), "gkx"]
>>> for rule in rules:
...     rule = rule[::-1] # go back in time
...     for i in range(len(rule)-1):
...             s = s.replace(rule[i], rule[i+1])
...
>>> print s

In de brameworg ob a brojecd on evoludionary linguisdics I wish do
have a brogram do brocess words and simulade de ebbecd ob sound
shibd, bor insdance bollowing de Rasg's-Grimm's rule. I loog do have
bydon dage a dicdionary bile or a sdring inbud and reblace de
consonands in id wid de Grimm rule equivalend. For egamble:

;) 

If you are using nonascii characters like θ you should use unicode instead 
of str. Basically this means writing string constants as u"..." instead of 
"..." and opening your files with 

f = codecs.open(filename, encoding="utf-8")

instead of

f = open(filename)

Peter



More information about the Python-list mailing list