vitalyvolkov / example-trigram

Generate random sentences with correct grammars
0 stars 1 forks source link

Reduce included letters #2

Open davelab6 opened 11 years ago

davelab6 commented 11 years ago

The output should contain words that contain ONLY the input letters (similar to https://github.com/forcebold/adhesiontext-for-robofont/blob/master/adhesiontext.py and https://github.com/davelab6/libretext/)

Currently output includes all letters:

$ ./gensent.py adhesiongkwu
sleeve of his healthhere is a suspicious attitudeagainst the phantomi dont
discoveredwhat the spectre saidi suffer most illustrious laughthe father is so
notwithstandingwell returned scrooge as to any walkthat anythingcould give is nothingin
oranges and stoppedto bless itthe spirit said immediatelyyour reclamation then said
$

Expected output:

$ ./gensent.py adhesiongwku
he did ask seeking designs and engaged audio sound ideas. the goose 
hooked a wise goddess on the disingenuous duke. indian genies soaked 
hideous geeks and genius denies a diagnosis going nine kinda genuine 
engines.
$
davelab6 commented 11 years ago

(Probably we need a MUCH larger en.txt than the current one for this to work well. :)

davelab6 commented 11 years ago

This is still unresolved

davelab6 commented 11 years ago

can this be resolved? :)

vitalyvolkov commented 11 years ago

now gensent.py produces output

planting, cutting, hoeing, watering, walking amid his terror as well as birds.
gendarme repete:-- the gendarme and his exertions must have been without a
be fatigued than wounded. it was almost always comes too soon. wait
this hollow road of ohain, to grouchy's delay, to blucher's arrival, to

or raising AttemptError if it does not found any words

davelab6 commented 11 years ago

The latest commit is too harsh, as this will not work when all letters except Y and y are not included, but works when all 52 latin letters are included.

$ ./gensent.py abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZ
by change of emotion which was dark, that the ball had traversed
solitude, silence, night, i can surely sell me a sou! my wife
evil. there exist people who are your fifteen hundred years before. m.
on, nevertheless," ejaculated thenardier, and that they alone recognize; he abruptly unmasked
$ ./gensent.py abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXZ
Traceback (most recent call last):
  File "./gensent.py", line 34, in <module>
    main(sys.argv[1:])
  File "./gensent.py", line 31, in main
    print m.random_walk_string(10, start)
  File "/Users/dcrossland/src/example-trigram-davelab6/markov_chain.py", line 196, in random_walk_string
    result = self.random_walk(length, init)
  File "/Users/dcrossland/src/example-trigram-davelab6/markov_chain.py", line 187, in random_walk
    next = self.random_step(prestate)
  File "/Users/dcrossland/src/example-trigram-davelab6/markov_chain.py", line 164, in random_step
    raise AttemptError(u'Unable to find words in {0} attempts'.format(20))
markov_chain.AttemptError: Unable to find words in 20 attempts
$