Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python and kanji

Name: Anonymous 2012-02-03 3:07

I need your help to separate characters from a Japanese string. For example if my string was "飛行機", I'd like to get 飛, 行 and 機 individually.

Name: Anonymous 2012-02-03 3:33

Oh I actually got it to work. Needed to add u in front of the string first.

Name: Anonymous 2012-02-03 4:11

Back to /jp/, faggot.

Name: Anonymous 2012-02-03 16:56

Python

Lisp DSL

Grammar = split "|" \(sentence    = (noun_phrase verb_phrase)
                     |noun_phrase = (Article Noun)
                     |verb_phrase = (Verb noun_phrase)
                     |Article     = the a
                     |Noun        = man ball woman table
                     |Verb        = hit took saw liked)

generate [@P]=mapc r P; P:rewrites=P,pick,r; P=P
rewrites Category = Grammar,<[@_ [!Category "=" @RHS] @_]=RHS>


Python:

from random import choice

def Dict(**args): return args

grammar = Dict(
        S = [['NP','VP']],
        NP = [['Art', 'N']],
        VP = [['V', 'NP']],
        Art = ['the', 'a'],
        N = ['man', 'ball', 'woman', 'table'],
        V = ['hit', 'took', 'saw', 'liked']
        )

def generate(phrase):
    "Generate a random sentence or phrase"
    if isinstance(phrase, list):
        return mappend(generate, phrase)
    elif phrase in grammar:
        return generate(choice(grammar[phrase]))
    else: return [phrase]
   
def generate_tree(phrase):
    """Generate a random sentence or phrase,
     with a complete parse tree."""
    if isinstance(phrase, list):
        return map(generate_tree, phrase)
    elif phrase in grammar:
        return [phrase] + generate_tree(choice(grammar[phrase]))
    else: return [phrase]

def mappend(fn, list):
    "Append the results of calling fn on each element of list."
    return reduce(lambda x,y: x+y, map(fn, list))

>>> generate('S')
['the', 'man', 'saw', 'the', 'table']

>>> ' '.join(generate('S'))
'the man saw the table'

Name: Anonymous 2012-02-03 16:58

Also, Guido is jewish.

Name: Anonymous 2012-02-03 17:58

lol y wud they name a proglanguage after a snake? that is way out there man

Name: Anonymous 2012-02-03 18:33

>>5
Is that true?

Name: Anonymous 2012-02-03 18:38

>>5
Forced indentation of Jews.

Name: Anonymous 2012-02-03 19:20

>>8
Forced circumcision of code!

Name: Anonymous 2012-02-04 3:37

>>7
Look at his mother's photo.

Name: Anonymous 2012-02-04 4:32

>>6
most of you hate python, despise you're mascot is a giant black snake

Name: Anonymous 2012-02-04 4:46

>>11
in yiddish snake (schlong) means penis.

Name: Anonymous 2012-02-04 6:53

>>1
list(u"飛行機")

Name: Anonymous 2012-02-04 7:12

And that's why Python3 isn't used.

Name: Anonymous 2012-02-04 8:25

>>13
Well that was easier than I thought.

Don't change these.
Name: Email:
Entire Thread Thread List