Tuesday, June 27, 2006

Haystack

Haystack is a product for Plone used to do auto-classification of content. I've talked about it a little bit before but never given much of an introduction to it before.

Haystack is built around libots which is available for many platforms. ots is a set of Python bindings to the library and I've made it available on cheeseshop. This means you can ez_install its

easy_install ots

or you can grab it yourself from either:

cheeseshop or from svn

After that you'll want to get Haystack, the product for Plone that will get you started.

Once that is installed you'll have access to a new portlet that will show you the interrelationships between content on the system and a tool that will give you more control over the analysis of content.

Of interest:

haystack_tool.summarize(unicode, asHTML=False, ...)
return either a unicode or html highlited summary of the text you passed in

haystack_tool.topics(unicode, count=5, ...)
return a list of topics extracted from the content

Its pretty simple to things like auto suggest keywords/subjects with this tool and Bling in conjunction. Topic maps and other fun things are pretty simple as well. As it gets more use there are many options to expand on the kind of classification and clustering that are available.

Have Fun

Friday, June 23, 2006

PeeJays

PJS (pronounced PeeJays) is the Python equivlent to RJS done in Rails. Its still a little wet behind the ears but is already quite useful.

The intention is to have a language native way to get at the Javascript code your client is running. In this case the language is Python and we expose the underlying Prototype primitives, but it would be possible to re-target this whole deal for something like Dojo or MochiKit.

So what does it do? How do you use it? Pretty simple really. Now just to disclaim again, not everything you might want to do works but enough does that I am still going to show this. All the tests and runtime are pure Python with no Zope dependencies, but in the context of these examples I use a handy FSJavascript object which means we have a file in your Plone skin path with a .pjs extension that will render itself as text/javascript. There is an implicit page object available to FSJavascript objects, but if you were doing this by hand if would just be:

page = pjs.JavascriptPage()
...
print page

Ok, now for a real example, or what goes in the ...



There are a number of very standard things we want to do from PJS.

Access an element of the page by its id.

page[id]

Refer to a Javascript variable directly

page.jsvar

and then call methods on those and pass them around.

page['portlet-news'].highlight(delay=1.0)

which might highlight the news portlet for one second when triggered.

We can also do slightly more complex things. For example suppose we have a Tree widget in Javascript and we want to add elements to it that result from doing a query. An AJAX callback to the server might trigger a .pjs file that looks
as follows.



##parameters=of
catalog = context.portal_catalog
ob = catalog(UID=of)[0].getObject()

files = page.files
files.clear()
for title, data in ob.treeFolderContents():
files.addItem(title, data)




Looks just like a regular Python Script in Zope. Parameters tells Zope what to demand from the caller (in this case the AJAX request) and then runs as normal.
This produces the proper Javascript which is returned to the client. All in all its pretty simple. You'd have to understand that files is a Tree object and has a addItem methodand you didn't have to worry about marshalling arguments, or escaping code in some strange cross language way (if you don't know what I mean count your blessings).

There are unit and doc tests for this stuff and its still evolving. Its fun to play with, give it a try.

Update:
This is checked into Bling which can still be had from

http://svn.plone.org/svn/collective/Bling/trunk/

Wednesday, June 14, 2006

For your pleasure...

Its been a long time since I've posted. I pushed out releases of some software in the hopes that it will be useful to people.

skeletor 0.4.0.dev-r23725chimera 0.4.0rbtree 0.7

ots-0.4.2-py2.4-linux-i686.egg

Skeletor is the zope products and cluster generator.

Chimera is the image generation and manipulation tool. Reco did some install docs. Which are helpful, there are a lot of dependencies. There is also an EGG on cheeseshop but this doesn't track the system level deps.

OTS is the wrapper around libots (which is now included) and is used to power haystack, the auto text summarizer. There is so much that can be done here beyond what is currently shown.

rbtree is generally useful. If you need a datastructre that offers the best of lists and dicts and allows things like key driven slices and so on in Python, this is for you.

Followers