May 12th, 2006 at 9:36 pm
Tags: AI, Dictionary, Games, Javascript, Python, Web
In my sidebar, under Mini Projects is one called Silent Boggle. When my daughter was born, my wifed Daniela and I like to play Boggle a lot, but we worried about the noise waking the baby, so I coded up a quick CGI script to create a web page listing the letters with the same frequency as the game. That worked OK, and now we could play without rattling the box, but of course a project never stops where you thought it would. I kept thinking that it would be cool if I could list all the words available, making it useful for learning new vocabulary, or just checking your score. It turns out that Peter Norvig covered solving Boggle as an AI problem in his book AI: A Modern Approach. And he also provides the code from the book, in both Lisp and Python. So, armed with a standard linux word list, munged to remove words illegal or impossible in Boggle (and to handly my funky hack involving the Qu face of the Boggle dice) and the AIMA python libarary, I was able to get something going. A little slow, and resource intensive, but it works (if that project ever starts getting much traffic, I’ll have to stick the wordlist in a seperate, long-running process).
The thing is, the linux word list has a lot of words I don’t recognize and cannot find in any dictionary. At first I wanted to create links from the “answers” to a site with their definitions, but for many of the words there don’t appear to be definitions. I’d like to use this as a vocabulary building tool for my kids (my newborn daughter at the start of this project is now nine, and my son is now five and both are avid readers), but I can find two types of resources on the web: word lists suitable for use with the AIMA library, and dictionaries that don’t have associated word lists. I suppose I can dowload an open-source dictionary and extract the word-list myself, but it seems like with all the work that’s been done out there on wordlists and dictionaries, that there should be one that combines them both, that I just haven’t found yet.
So, lazyweb, I invoke thee! Please help me to find the wordlist + dictionary that I have overlooked in my searching.
3 Comments
May 9th, 2006 at 9:46 pm
Tags: Java, Metaphor, Python, Unix, XML, XML Matters
My latest article for David Mertz’s column XML Matters on IBM’s developerWorks site has been up for over a week now, but I’m finally coming up for air long enough to post about it. The title is Pipestreaming Microformats and it is a survey of attempts to apply the Unix pipe metaphor to XML content, then some blue-sky dreaming of how to apply that to microformats.
One thing I mention in the article is that Norm Walsh’s SXPipe would be cool to re-implement in Python using lxml. While I was writing the article and in the time since, lxml has been undergoing a flurry of activity the results of which (among other cool things) are that it now has Python eggs for easy install on Windows, OS X, and Linux. So I think it’s ready, I just need to find time to spend with that project. If there is interest in such a thing, let me know so I can bump the priority up.
Comments
March 10th, 2006 at 7:58 pm
Tags: Cocoa, OS X, Python
I noticed that jwz is trying to take a screenshot in Cocoa and having trouble. I’m happy to see that he’s porting his awesome collection of screensavers to OS X, that’s great news. As for taking screen shots, I’m amazed it is as hard as it seems to be–heck even the new Nokia Series 60 give you the ability to take screeenshots from Python now. In any case, here is a method that works for me under PyObjC. It assumes it is part of a Cocoa object and that you’ve done a from AppKit import * already. Since I can’t comment on jwz’s blog (whether it’s because I don’t use LiveJournal or because I do use Safari, I don’t know), I’ll post it here instead.
def screenShot(self):
rect = NSScreen.mainScreen().frame()
image = NSImage.alloc().initWithSize_((rect.size.width, rect.size.height))
window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
rect,
NSBorderlessWindowMask,
NSBackingStoreNonretained,
False)
view = NSView.alloc().initWithFrame_(rect)
window.setLevel_(NSScreenSaverWindowLevel + 100)
window.setHasShadow_(False)
window.setAlphaValue_(0.0)
window.setContentView_(view)
window.orderFront_(self)
view.lockFocus()
screenRep= NSBitmapImageRep.alloc().initWithFocusedViewRect_(rect)
image.addRepresentation_(screenRep)
view.unlockFocus()
window.orderOut_(self)
window.close()
return image
I cribbed this several months ago from some example Cocoa code, but forgot to make a note of where I got it. If anyone recognizes this pattern, please let me know so I can attribute it.
[Update 2006-03-10]
Nils Soffer pointed out:
A simpler solution:
try:
screenshot = 'screenshort.pdf'
os.system('screencapture -i %s' % screenshot)
image = NSImage.alloc().initWithContentsOfFile_(screenshot)
finally:
os.remove(screenshot)
:-)
Which reminds me, you can also use the command-line screencapture -c to go to the clipboard instead of a file. This might be faster, but I haven’t tested it yet. I still think there should be a Cocoa method to grab the underlying framebuffer of the screen. Besides the -c flag to send the image to the clipboard there is also a -C flag to capture the cursor as well.
[Update 2008-01-22]
Digging through old mail as I move this entry from my custom blog setup to Wordpress, I found where I got this code from originally. It’s from the Irate Scotsman’s Screen Sharing code. Thanks, Matt!
Comments
March 3rd, 2006 at 10:31 pm
Tags: Cocoa, OS X, Python
Yes, I’ve been quiet for awhile. No, I’m not going to apologize, and I wish more bloggers would stop apologizing when they take time off. One of the great things about Atom/RSS feeds is that I can keep up with blogs that are posted to infrequently, which includes some of my favorites. Don’t feel like you need to post all the time–we’ve all got plenty of other things to read!
My quiet time is going to continue for a bit longer, but while I won’t apologize, I will at least explain. Here’s what I’m doing instead with the couple of hours I have between putting the kids to bed and going to bed myself.
- Writing the OS X version of the file uploader for The Conversation Network. At some point this will be made public, and the idea is to open source it. I’ll be sure to point that out when it happens. It’s been really great to have this opportunity to work with Doug Kaye and the rest of the gang from ITConversations, after being an admirer (and consumer) of their work for some time.
- Attended the Northern Voice and Moose Camp conference, where I was fortunate enough to co-moderate a session on community and blogs with Nancy White
- Writing my own weblog software. Blogger has a better interface than manilasites, but that’s not saying much. I’m also trying to port my old content from manilasites, plus my pre-blog-era work, plus my paper journal. All of this will be hosted at livingcode.org in the near future.
- Writing more articles for IBM developerWorks, I hope to have more to say about that Real Soon Now
- Generally organizing the livingcode site better, getting projects their own pages, putting code into SVN. Trying to use Sourceforge was a huge failure, their interface is just too crufty and they still don’t support Subversion. But Dreamhost (where livingcode.org is hosted) does support Subversion now, so I’m going to be moving all my public code over there.
- I wrote a screensaver using PyObjC which I’m hoping to get included in their distribution as an example, but I need to do some refactoring first (in the time leftover from other projects). I want to write that up too, it was pretty interesting to work on.
- I periodically take a stab at porting VPython to the Aqua environment. I have some ideas for this (some of them probably heretical to the VPython folks), but need time to work on them. Notice a pattern emerging?
- Porting Apple’s Sketch demo application from ObjectiveC to PyObjC.
- Several of these things are just precursors to DrawingBoard, my animation program for kids. I really, really want to be working on that, but need to get some of the smaller projects finished and out of my head so I can concentrate.
- Exploring programming environments for my kids. My nine-year-old daughter and I will try competing in the PyWeek game challenge later this month.
- I’m sure I’ve forgotten several significant things.
More news as it happens.
Comments
May 3rd, 2005 at 9:51 pm
Tags: OS X, PyObjC, Python
My copy of Mac OS 10.4 arrived Friday, right on schedule. I spent the weekend backing up my laptop, doing a clean install, and then restoring my data, which also fixed the problem I’ve been having where applications take a really long time to launch. No problems so far and performance is noticeably faster. You gotta love an OS where each update makes your existing hardware faster.
First impressions: Spotlight searching really is as fast as they claim, Dashboard is neat in a gee-whiz sort of way, but I’m not sure how much I’ll actually use it. The built-in dictionary and thesaurus are welcome additions. I’m sure with time I will come to use smart folders in both the Finder and Mail. But for me the real juice in this version is underneath the hood in the development tools.
I’ve had a few secret hopes for Tiger, for things which have not been announced, but might be slipped under the door. Three of them were: NSOutlineView gaining support for varying row height (to make it easier to write applications like OmniOutline), improved Cocoa support for QuickTime, and being able to round-trip Nibs to text format and back via nibtool. Well, two out of three ain’t bad. The NSOutline now supports row height via it’s delegate method heightOfRow:ofItem:, the QTKit framework provides excellent support for QuickTime media from Cocoa (and thus from PyObjC), but alas, nibs cannot be created from text input via nibtool (or any other tool that I’m aware of), although the nibtool man page does at least list this deficiency as a known bug.
But there is more good news in the Core Image, Core Audio, and Core Data frameworks. Core Image gives fast, powerful graphic processing and pipelining tools for both still images and video. Core Audio does the same for sound. And while Mac development in the Model-View-Controller (MVC) has been supported via Interface Builder (View), NSArrayController and NSObjectController (Controller), now with Core Data the Model portion is fully supported as well. Bill Bumgarner has a welcome example on his blog of how to use CoreData from Python.
But wait, there’s more! There’s an NSTreeController to go along with the NSArrayController and friends. There are hooks and documentation for many more of the Apple-supplied applications, including the new Sync Services. And PyObjC now has wrappers for Core Data, Automator, XGrid, and Sync Services. And that’s not to mention the improved WebKit, new features of NSTextView, and much more. It’s a great time to be a Mac developer, and being able to do all this from Python really ices the cake for me.
Comments