Tuesday, January 13, 2009

PPUG 2009.1.13

I took a break from my spartan cube (Kermit), to join PPUG, and later OS Bridge in Roman (a room) -- long day at the office, with a lunch break at Rams Head.

Announcement: Northwest Python Day, January 31st, 9 am - 5 pm (lots of lightning talks!).

On tonight's menu: meta classes, deque, stupid dict tricks (Jason), Natural Language Processing, except John isn't here, so no meta classes, dang! We're about 30 strong.

Women are pretty much running these meetings (not always overtly), which is encouraging, especially after all that disappointing news on the Math Forum, about declining enrollment in some dying (as in withering) academic programs.

A deque (pronounced "deck" -- or "dee que" by some) is a double-ended queue, found in collections. It has a rotate method which is kinda cool. Jason also showed extendleft with rotate, "wildly faster" than extendleft with reversed.

dict.__missing__: collections.defaultdict lets you specify the type of the default "nothing" you'd like as a value -- could even be a function (any callable with no args). A newer approach is to subclass dict to gain access to __missing__, which will be called whenever __getitem__ fails.

OK, John Melesky is here (bus problems).

Python Metaclasses: never use them (opening joke). "There are parts of Python where thar be monsters." Decorators might fall into this category, descriptors... "They're not actually that bad" (pretty coherent, but unpythonic, non-obvious). Hmmmm, I'd not heard of "class decorators" before.

[ long convoluted example goes here, originally involving exec, with an environment at least -- reminds me of Foxpro's "&" i.e. macro substitution -- made less crufty by our group process, enhancing the lambdas (we rock) ]

John: "we're getting almost Perlish" (too clever by half?). I'm fairly persuaded I don't want to use metaclasses very often.

The natural language toolkit (NLTK) looks fascinating. Monica Toth knows her stuff. Here's some of what you get:

Corpus: a database of speech or writing samples intended to demonstrate how language is actually used. from ntlk.corpus import brown will give you access to the 1,161,192 words and 57,240 sentences in that collection. You can do probabilistic and statistical work against a corpus.

Wordnet: a lexical database of words and "synonym sets", or synsets. from nltk.wordnet import * gives you a relations() method on a word like "door". Get all hyponyms for door using door[0][HYPONYM] e.g. car_door, double_door...

from nltk.chat.suntsu import * gives you access to suntsu_chat(), your own personal chat buddy (a chat bot -- Eliza is there too as eliza_chat(), also nltk.chat.rude() -- fun for kids).

NLTK
: The documentation lags the reality in this academic, research-oriented package. Linguists have a language all their own.

I asked a stupid question about Wsgi. Maybe we'll hear about Orange next time? We might also learn about RDF, an alternative to SQL for defining models. I signed up to yak about Vpython.

Produce Row: yes John, you're correct that "NATO professor" and "nutty professor" don't rhyme so much as alliterate. Thanks for the more detailed background on RDF, and Illinois politics.