[Tutor] tagging pieces of information

Che M pine508 at hotmail.com
Wed Aug 29 21:55:49 CEST 2007



> > Hi, I am curious about ways in Python to approach the idea of "tagging"
> > pieces of information much in the way that one can tag favorite websites
> > like on the site Del.icio.us.  I'm not sure if tagging is the best term 
>for
> > this (due to confusion with HTML tags), but the idea would be a way to
> > assign one or more words to stored data such that later one might search 
>by
> > those words in order to retrieve the data.  That data might be a chunk 
>of
> > text, a graph, image, whatever...the point would be to be able to search
> > later by tags name.  I know the prorgram GyrFalcon uses tags and is 
>written
> > in Python.  And of course Flickr and many other things.
>
>A simple way to do this in-memory would be to use a dict: keys are
>tags and values are sets (or lists) of objects.  You might need to
>maintain an inverse structure too, mapping object to list/set of tags.
>
>You could use a database (sqlite comes with python 2.5).  I'm not sure
>what the "best practice" strucutre would be, but maybe you could have
>a table with two columns: "object ID" and "tag".  "object ID" would be
>some kind of identifier for your tagged objects.  You could then:
>
>Find tags for an object:
>  select tag from tagTable where objectID = ?
>
>Find objects matching a tag:
>  select objectID from tagTable where tag = ?
>
>--
>John.

Thanks, John, I've fooled around with the database way to do it and
it fits in nicely with other things I'm trying to do and should work well
for me.  Thanks to the others for their suggestions as well.
-Che

_________________________________________________________________
Puzzles, trivia teasers, word scrambles and more. Play for your chance to 
win! http://club.live.com/home.aspx?icid=CLUB_hotmailtextlink



More information about the Tutor mailing list