Using Python for a demonstration in historical linguistics

Dax Bloom bloom.dax at gmail.com
Sat Nov 27 01:58:04 EST 2010


On Nov 6, 6:18 am, Peter Otten <__pete... at web.de> wrote:
> Peter Otten wrote:
> >>>> s = """
> > ... In the framework of a project onevolutionarylinguisticsI 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])
> > ...
>
> Warning: this simple-minded approach somewhat limits the possible rules.
> E. g. it fails for
>
> a --> b
> b --> a
>
> >>> "abba".replace("a", "b").replace("b", "a")
>
> 'aaaa'
>
> while unicode.translate() can deal with it:
>
> >>> u"abba".translate({ord(u"a"): u"b", ord(u"b"): u"a"})
>
> u'baab'
>
> Or, if you are using Python 3.x as Steven suggested:
>
> >>> "abba".translate({ord("a"): "b", ord("b"): "a"})
>
> 'baab'
>
> Peter

Hi Peter,

I read your interesting replies 20 days ago and after several exams
and a university semester, I would like to address more fully your
answers to my post. However could you please clarify some of the code
inputs that you suggested and in what order to insert them in the
script?

>>>> s = """
> > ... In the framework of a project onevolutionarylinguisticsI 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])
> > ...

Best regards,

Dax Bloom



More information about the Python-list mailing list