Package: cs.tags
OverviewThis package provides an engine that allows users to assign tags to items.Clouds EngineUse this package if you want to draw tag clouds or want to retrieve othe info related to tagging.>>> from cs.tags.clouds import CloudsEngineThe clouds engine stores the tags that each user assigns to an item. Tags, users and items info is stored according a model in order to speed up retrieval. This mean that the data structures will conteins precalculated tag clouds prepeared to be drawed as fast as possible.>>> clouds_engine = CloudsEngine()
>>> clouds_engine
<CloudsEngine tags=0>In the beggining, the clouds engine doesn’t contain anything:>>> clouds_engine.getCloud()
([], 0, 0)Each user can add to the engine his set of tags assignated to a given item. For this proposal, theupdate()method mantains the user-centric relations between items and tags:>>> clouds_engine.update(item=1, user='Nando Quintana', tags=['simple','green','energy'])
>>> clouds_engine.update(item=2, user='Nando Quintana', tags=['complex','energy'])
>>> clouds_engine.update(item=3, user='Erral', tags=['mineral','sources'])
>>> clouds_engine.update(item=3, user='Nando Quintana', tags=['nuclear','power'])The engine is now able of returning a tag cloud information, based on the updates mades until this moment:>>> clouds_engine.getCloud()
([('energy', 2), ('complex', 1), ('green', 1), ('mineral', 1), ('nuclear', 1), ('power', 1), ('simple', 1), ('sources', 1)], 9, 8)ThegetCloud()method returns this peculiar data structure. Showed info is composed by a tag lists and two numbers. The tag list is indeed a list of tuples, that contains the string tag and the weight in the cloud. Second number means the number of tagged items, and third, the number of tags in the clouds.Optionally, you can give a maximum number of tag you want to include in your tag cloud:>>> clouds_engine.getCloud(n=5)
([('energy', 2), ('complex', 1), ('green', 1), ('mineral', 1), ('nuclear', 1)], 9, 5)If you want to draw a clouds of tags, posted by a single user, you can tell thegetCloud()method which is the user you want to use as filter:>>> clouds_engine.getCloud(users='Nando Quintana')
([('energy', 2), ('complex', 1), ('green', 1), ('nuclear', 1), ('power', 1), ('simple', 1)], 7, 6)You can also filter the cloud by item:>>> clouds_engine.getCloud(items=3, users='Nando Quintana', n=5)
([('nuclear', 1), ('power', 1)], 2, 2)Or ask the engine a tag cloud in relation to a single item:>>> clouds_engine.getCloud(items=3, n=5)
([('mineral', 1), ('nuclear', 1), ('power', 1), ('sources', 1)], 4, 4)Implicit knowledgeThere is more information you can extract from the engine. For example, you can draw a cloud with the tags that have been inserted in common items. Doing this, you can build implicit knowledge from the users tagging habits.>>> clouds_engine.update(item=4, user='Nando Quintana', tags=['nuclear','power'])
>>> clouds_engine.update(item=5, user='Nando Quintana', tags=['nuclear','flower','power'])
>>> clouds_engine.update(item=5, user='Erral', tags=['black','power'])>>> clouds_engine.getRelatedTags(tag='power')
([('nuclear', 3)], 3, 1)Other info you can build from the tagging behaviour is the relation between items:>>> clouds_engine.getRelatedItems(item=3)
([(4, 2), (5, 2)], 4, 2)So in this example, item3has2tags in common wiht item4, and other2wich item5.As in the case of tags and items, you can also discover the implicit relations between users, according to the tagging history:>>> clouds_engine.getRelatedUsers(user='Erral')
([('Nando Quintana', 1)], 1, 1)The results show thatErralandNando Quintanahave a tag in common.