Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59967

Re: Automation

References (4 earlier) <5285be70$0$29975$c3e8da3$5496439d@news.astraweb.com> <ben1t6Fd19tU1@mid.individual.net> <Levhu.35560$Mn5.29711@fx25.am4> <WJvhu.111788$qC.80212@fx07.am4> <CALwzidnG63SjvOVEKWN5e7NVHE7v+vJMg-a6Xn9mB3aMAW5wdA@mail.gmail.com>
Date 2013-11-19 20:26 +1100
Subject Re: Automation
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2895.1384853188.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Nov 19, 2013 at 7:53 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> Aoilegpos for aidnoptg a cdocianorttry vwpiienot but, ttoheliacrley
> spkeaing, lgitehnneng the words can mnartafucue an iocnuurgons
> samenttet that is vlrtiauly isbpilechmoenrne.

isbpilechmoenrne. I totally want to find an excuse to use that word
somewhere.. It just looks awesome.

Paradoxically, it's actually more likely that a computer can figure
out what you're saying here. In fact, I could easily write a little
script that reads /usr/share/dict/words (or equivalent) and attempts
to decode your paragraph. Hmm. You know what, I think I will. It's now
0958 UTC, let's see how long this takes me.

Meh. I did something stupid and decided to use a regular expression.
It's not 1020 UTC, so that's 21 minutes of figuring out what I was
doing wrong with the regex and 1 minute solving the original problem.
But here's your translated paragraph:

-- cut --
Interestingly I'm studying this controversial phenomenon at the
Department of Linguistics at Absytrytewh University and my
extraordinary discoveries wholeheartedly contradict the picsbeliud
findings regarding the relative difficulty of instantly translating
sentences. My researchers developed a convenient contraption at
hnasoa/tw.nartswdbvweos/utrtek:p./il that demonstrates that the
hypothesis uniquely warrants credibility if the assumption that the
preponderance of your words is not extended is unquestionable.
Apologies for adopting a contradictory viewpoint but, theoretically
speaking, lengthening the words can manufacture an incongruous
statement that is virtually incomprehensible.
-- cut --

It couldn't figure out "Absytrytewh", "picsbeliud", or
"hnasoa/tw.nartswdbvweos/utrtek:p./il". That's not a bad result. (And
as a human, I'm guessing that the second one isn't an English word -
maybe it's Scots?) Here's the code:

words = {}
for word in open("/usr/share/dict/words"):
    word=word.strip().lower()
    transformed = word if len(word)==1 else
word[0]+''.join(sorted(word[1:-1]))+word[-1]
    words.setdefault(transformed,set()).add(word)
    words.setdefault(transformed.capitalize(),set()).add(word.capitalize())

import re
for line in open("input"):
    line=line.strip()
    for word in re.split("(\W+)",line):
        try:
            transformed = word if len(word)==1 else
word[0]+''.join(sorted(word[1:-1]))+word[-1]
            realword=words[transformed]
            if len(realword)>1: realword=repr(realword)
            else: realword=next(iter(realword))
            line=line.replace(word,realword)
        except LookupError: # catches three errors, all of which mean
we shouldn't translate anything
            pass
    print(line)


Yeah, it's not the greatest code, but it works :)

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Automation Renato Barbosa Pim Pereira <renato.barbosa.pim.pereira@gmail.com> - 2013-11-03 14:19 -0200
  Re: Automation Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-03 23:32 +0000
    Re: Automation Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-04 11:39 +0000
    Re: Automation Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-13 20:18 -0800
  Re: Automation rusi <rustompmody@gmail.com> - 2013-11-03 20:25 -0800
  Re: Automation renato.barbosa.pim.pereira@gmail.com - 2013-11-13 19:56 -0800
    Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-14 17:10 +0000
      Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-14 20:03 +0000
        Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-15 10:04 +1100
        Re: Automation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-15 06:25 +0000
          Re: Automation Neil Cerutti <neilc@norwich.edu> - 2013-11-15 16:53 +0000
            Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-15 20:12 +0000
              Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-15 20:45 +0000
                Re: Automation Ian Kelly <ian.g.kelly@gmail.com> - 2013-11-19 01:53 -0700
                Re: Automation Grant Edwards <invalid@invalid.invalid> - 2013-11-20 16:12 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-19 20:26 +1100
                Re: Automation Ian Kelly <ian.g.kelly@gmail.com> - 2013-11-19 02:37 -0700
                Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-19 09:44 +0000
                Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-19 09:54 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-19 21:48 +1100
                Re: Automation Grant Edwards <invalid@invalid.invalid> - 2013-11-20 16:14 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-21 03:19 +1100
                Re: Automation Tim Golden <mail@timgolden.me.uk> - 2013-11-20 16:28 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-21 03:33 +1100
                Re: Automation Walter Hurry <walterhurry@lavabit.com> - 2013-11-20 16:59 +0000
                Re: Automation Grant Edwards <invalid@invalid.invalid> - 2013-11-20 21:34 +0000
                Re: Automation Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-20 17:58 -0500
                Off-topic: Aussie place names [was Re: Automation] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-21 00:58 +0000
                Re: Off-topic: Aussie place names [was Re: Automation] Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-20 22:22 -0500
                Re: Off-topic: Aussie place names [was Re: Automation] Tim Delaney <timothy.c.delaney@gmail.com> - 2013-11-21 12:18 +1100
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-19 21:50 +1100
                Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-19 13:50 +0000
                Re: Automation Tim Golden <mail@timgolden.me.uk> - 2013-11-19 13:55 +0000
                Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-19 14:07 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-20 01:08 +1100
              Re: Automation Walter Hurry <walterhurry@lavabit.com> - 2013-11-19 11:53 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-19 22:58 +1100
                Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-19 12:36 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-19 23:52 +1100
                Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-19 13:00 +0000
                Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-19 12:59 +0000
                Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-19 12:59 +0000
                Re: Automation MRAB <python@mrabarnett.plus.com> - 2013-11-19 15:06 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-20 02:11 +1100
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-21 02:44 +1100
                Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-19 13:00 +0000
                Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-21 01:52 +1100
      Re: Automation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-15 06:44 +0000
        Re: Automation Paul Rudin <paul.nospam@rudin.co.uk> - 2013-11-15 07:30 +0000
          Re: Automation Grant Edwards <invalid@invalid.invalid> - 2013-11-15 15:02 +0000
            Re: Automation Chris Angelico <rosuav@gmail.com> - 2013-11-16 02:12 +1100
              Re: Automation Alister <alister.ware@ntlworld.com> - 2013-11-15 15:52 +0000
            Re: Automation Larry Hudson <orgnut@yahoo.com> - 2013-11-15 22:17 -0800
              Re: Automation William Ray Wing <wrw@mac.com> - 2013-11-16 09:18 -0500
                Re: Automation Roy Smith <roy@panix.com> - 2013-11-16 10:11 -0500
                grammar (was Re: Automation) Paul Smith <paul@mad-scientist.net> - 2013-11-16 12:02 -0500
                Re: grammar (was Re: Automation) Andrew Berg <robotsondrugs@gmail.com> - 2013-11-16 21:44 -0600
                Re: grammar (was Re: Automation) MRAB <python@mrabarnett.plus.com> - 2013-11-17 04:07 +0000
                Re: grammar (was Re: Automation) Chris Angelico <rosuav@gmail.com> - 2013-11-17 15:16 +1100
                Re: grammar (was Re: Automation) Andrew Berg <robotsondrugs@gmail.com> - 2013-11-16 22:34 -0600
                Re: grammar (was Re: Automation) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-17 12:48 -0500
                Re: grammar (was Re: Automation) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-19 04:13 +0000
              Re: Automation Neil Cerutti <neilc@norwich.edu> - 2013-11-18 12:17 +0000
                Re: Automation Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-19 19:23 +1300
                Re: Automation Steven D'Aprano <steve@pearwood.info> - 2013-11-19 07:09 +0000
              Re: Automation Grant Edwards <invalid@invalid.invalid> - 2013-11-18 16:49 +0000
                Re: Automation David Robinow <drobinow@gmail.com> - 2013-11-18 22:54 -0500
        Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-15 14:23 +0000
        Re: Automation Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-15 18:54 -0500
      Re: Automation Grant Edwards <invalid@invalid.invalid> - 2013-11-15 14:58 +0000
        Re: Automation xDog Walker <thudfoo@gmail.com> - 2013-11-15 13:43 -0800
        Re: Automation Tim Chase <python.list@tim.thechases.com> - 2013-11-15 19:28 -0600
        Re: Automation Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-15 21:01 -0500
        Re: Automation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-16 11:42 +0000

csiph-web