Simple implementation of a tag cloud for xwiki
Hi! Tag clouds (http://en.wikipedia.org/wiki/Tag_cloud) seem so in these days, so I made a simple implementation using the Main.Tags in xwiki. The styling isn't too sexy, but that should be easy to configure. Here is the code for use in a panel or similar place: #panelheader('Tag cloud') #set($query = "select elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'") #set( $allTags = $xwiki.sort($xwiki.search($query))) #set( $tagsWithCount = $xwiki.metawiki.getTagsWithCount($allTags)) #set($query = "select distinct elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'") #set( $tagsDistinct = $xwiki.sort($xwiki.search($query))) #foreach($tag in $tagsDistinct) <span style="#getStyle($tagsWithCount.get($tag))"><a href="$xwiki.getURL("Main.Tags", "view", "tag=$tag")")>$tag</a></span> #end #panelfooter() #macro( getStyle $count ) #if ($count < 2) "font-size: 0.80em;" #elseif ($count < 3) font-size: 1.00em; } #elseif ($count < 4) font-size: 1.20em; } #elseif ($count < 5) font-size: 1.40em; } #elseif ($count < 6) font-size: 1.60em; } #elseif ($count < 7) font-size: 1.80em; } #elseif ($count < 8) font-size: 2.00em; } #else font-size: 2.50em; } #end #end And here's the java code invoked: public static HashMap<String, Integer> getTagsWithCount(ArrayList<String> allTags) { String tag = null; String previousTag = null; HashMap<String, Integer> tagsWithCount = new HashMap<String, Integer>(); int count = 1; for (int i = 0; i < allTags.size(); i++) { previousTag = tag; tag = allTags.get(i); if (tag.equals(previousTag)) { count++; } else { count = 1; previousTag = null; } tagsWithCount.put(tag, new Integer(count)); } return tagsWithCount; } Is this anything you would want to include in xwiki, or is it too trivial to bother with? See the attached file for a sample screenshot. best regards :-) Thomas Drevon
Hi Thomas, this looks quite cool! There is a place on XWiki.org for this kind of contributions ( http://www.xwiki.org/xwiki/bin/view/Code/), it would be very cool if you could add it there with a step by step explanation of how to use it (for instance in my case I have no idea where I am supposed to put the Java code - though I'm not actually a developer). Even better would be to export the XAR of your XWiki, customize it to keep only the Main.TagCloud , Panels.TagCloud (and other pages required to make it work) and then upload it to XWiki.orglike it is done for other applications already. To do so easily you can even download first the Packager Application here: http://www.xwiki.org/xwiki/bin/view/Code/PackagerApplication and use it to generate your XAR (which at the same time gives you an example of the page you could create for yours :-) Funny thing is that I was wondering about tag cluds this afternoon but had no idea how to implement one :-) Thanks! Guillaume On 30/05/07, Thomas Drevon <thomas.drevon@intermedia.uio.no> wrote:
Hi!
Tag clouds (http://en.wikipedia.org/wiki/Tag_cloud) seem so in these days, so I made a simple implementation using the Main.Tags in xwiki. The styling isn't too sexy, but that should be easy to configure.
Here is the code for use in a panel or similar place:
#panelheader('Tag cloud')
#set($query = "select elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $allTags = $xwiki.sort($xwiki.search($query)))
#set( $tagsWithCount = $xwiki.metawiki.getTagsWithCount($allTags))
#set($query = "select distinct elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $tagsDistinct = $xwiki.sort($xwiki.search($query)))
#foreach($tag in $tagsDistinct) <span style="#getStyle($tagsWithCount.get($tag))"><a href="$xwiki.getURL("Main.Tags", "view", "tag=$tag")")>$tag</a></span> #end
#panelfooter()
#macro( getStyle $count ) #if ($count < 2) "font-size: 0.80em;" #elseif ($count < 3) font-size: 1.00em; } #elseif ($count < 4) font-size: 1.20em; } #elseif ($count < 5) font-size: 1.40em; } #elseif ($count < 6) font-size: 1.60em; } #elseif ($count < 7) font-size: 1.80em; } #elseif ($count < 8) font-size: 2.00em; } #else font-size: 2.50em; } #end #end
And here's the java code invoked:
public static HashMap<String, Integer> getTagsWithCount(ArrayList<String> allTags) { String tag = null; String previousTag = null; HashMap<String, Integer> tagsWithCount = new HashMap<String, Integer>(); int count = 1; for (int i = 0; i < allTags.size(); i++) { previousTag = tag; tag = allTags.get(i); if (tag.equals(previousTag)) { count++; } else { count = 1; previousTag = null; } tagsWithCount.put(tag, new Integer(count)); } return tagsWithCount; }
Is this anything you would want to include in xwiki, or is it too trivial to bother with? See the attached file for a sample screenshot.
best regards :-) Thomas Drevon
-- You receive this message as a subscriber of the xwiki-dev@objectweb.orgmailing list. To unsubscribe: mailto:xwiki-dev-unsubscribe@objectweb.org For general help: mailto:sympa@objectweb.org?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Hi Thomas, I've just finished an alternative tag display page (you can see it here: http://www.xwiki.org/xwiki/bin/view/Code/TagsAlternativeDisplay). I thought it could be cool to add your tagcloud effect to it, having bigger text and boxes (why not different colors too) for "heavier" tags. Would you be interested in trying to do something with this? Guillaume On 31/05/07, Guillaume Lerouge <guillaume@xwiki.com> wrote:
Hi Thomas,
this looks quite cool!
There is a place on XWiki.org for this kind of contributions ( http://www.xwiki.org/xwiki/bin/view/Code/), it would be very cool if you could add it there with a step by step explanation of how to use it (for instance in my case I have no idea where I am supposed to put the Java code - though I'm not actually a developer).
Even better would be to export the XAR of your XWiki, customize it to keep only the Main.TagCloud , Panels.TagCloud (and other pages required to make it work) and then upload it to XWiki.orglike it is done for other applications already. To do so easily you can even download first the Packager Application here: http://www.xwiki.org/xwiki/bin/view/Code/PackagerApplication and use it to generate your XAR (which at the same time gives you an example of the page you could create for yours :-)
Funny thing is that I was wondering about tag cluds this afternoon but had no idea how to implement one :-) Thanks!
Guillaume
On 30/05/07, Thomas Drevon <thomas.drevon@intermedia.uio.no> wrote:
Hi!
Tag clouds (http://en.wikipedia.org/wiki/Tag_cloud ) seem so in these days, so I made a simple implementation using the Main.Tags in xwiki. The styling isn't too sexy, but that should be easy to configure.
Here is the code for use in a panel or similar place:
#panelheader('Tag cloud')
#set($query = "select elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $allTags = $xwiki.sort($xwiki.search($query)))
#set( $tagsWithCount = $xwiki.metawiki.getTagsWithCount($allTags))
#set($query = "select distinct elements( prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $tagsDistinct = $xwiki.sort($xwiki.search($query)))
#foreach($tag in $tagsDistinct) <span style="#getStyle($tagsWithCount.get($tag))"><a href="$xwiki.getURL("Main.Tags", "view", "tag=$tag")")>$tag</a></span> #end
#panelfooter()
#macro( getStyle $count ) #if ($count < 2) "font-size: 0.80em;" #elseif ($count < 3) font-size: 1.00em; } #elseif ($count < 4) font-size: 1.20em; } #elseif ($count < 5) font-size: 1.40em; } #elseif ($count < 6) font-size: 1.60em; } #elseif ($count < 7) font-size: 1.80em; } #elseif ($count < 8) font-size: 2.00em; } #else font-size: 2.50em; } #end #end
And here's the java code invoked:
public static HashMap<String, Integer> getTagsWithCount(ArrayList<String> allTags) { String tag = null; String previousTag = null; HashMap<String, Integer> tagsWithCount = new HashMap<String, Integer>(); int count = 1; for (int i = 0; i < allTags.size(); i++) { previousTag = tag; tag = allTags.get(i); if ( tag.equals(previousTag)) { count++; } else { count = 1; previousTag = null; } tagsWithCount.put(tag, new Integer(count)); } return tagsWithCount; }
Is this anything you would want to include in xwiki, or is it too trivial to bother with? See the attached file for a sample screenshot.
best regards :-) Thomas Drevon
-- You receive this message as a subscriber of the xwiki-dev@objectweb.orgmailing list. To unsubscribe: mailto:xwiki-dev-unsubscribe@objectweb.org For general help: mailto: sympa@objectweb.org?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Hi Thomas, I didn't see your email below (was it sent to the list?). I'm all for offering a default tag cloud page/panel. The notion of tag is not something known to XWiki core. Currently tags are only known at the level of the default wiki so we should probably put the tag cloud code there. As your code below requires some logic, maybe the best is to use Groovy to replace the Java part. You could then have everything located on a single page. The next question is: a Panel or a Page? I'm tempted to say both. I think we should include the tag cloud in the Main.Tags page and we could provide a Panel too. WDYT? I have created a jira issue for this: http://jira.xwiki.org/jira/browse/XWIKI-1311 Would you be interested in working on this and finishing this? If so, could you please attach the result to that JIRA issue for inclusion in SVN? Thanks a lot -Vincent On May 31, 2007, at 1:42 AM, Guillaume Lerouge wrote:
Hi Thomas,
this looks quite cool!
There is a place on XWiki.org for this kind of contributions (http://www.xwiki.org/xwiki/bin/view/Code/), it would be very cool if you could add it there with a step by step explanation of how to use it (for instance in my case I have no idea where I am supposed to put the Java code - though I'm not actually a developer).
Even better would be to export the XAR of your XWiki, customize it to keep only the Main.TagCloud , Panels.TagCloud (and other pages required to make it work) and then upload it to XWiki.org like it is done for other applications already. To do so easily you can even download first the Packager Application here: http://www.xwiki.org/xwiki/bin/view/Code/PackagerApplication and use it to generate your XAR (which at the same time gives you an example of the page you could create for yours :-)
Funny thing is that I was wondering about tag cluds this afternoon but had no idea how to implement one :-) Thanks!
Guillaume
On 30/05/07, Thomas Drevon <thomas.drevon@intermedia.uio.no> wrote: Hi!
Tag clouds (http://en.wikipedia.org/wiki/Tag_cloud ) seem so in these days, so I made a simple implementation using the Main.Tags in xwiki. The styling isn't too sexy, but that should be easy to configure.
Here is the code for use in a panel or similar place:
#panelheader('Tag cloud')
#set($query = "select elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $allTags = $xwiki.sort($xwiki.search($query)))
#set( $tagsWithCount = $xwiki.metawiki.getTagsWithCount($allTags))
#set($query = "select distinct elements( prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $tagsDistinct = $xwiki.sort($xwiki.search($query)))
#foreach($tag in $tagsDistinct) <span style="#getStyle($tagsWithCount.get($tag))"><a href="$xwiki.getURL("Main.Tags", "view", "tag=$tag")")>$tag</a></span> #end
#panelfooter()
#macro( getStyle $count ) #if ($count < 2) "font-size: 0.80em;" #elseif ($count < 3) font-size: 1.00em; } #elseif ($count < 4) font-size: 1.20em; } #elseif ($count < 5) font-size: 1.40em; } #elseif ($count < 6) font-size: 1.60em; } #elseif ($count < 7) font-size: 1.80em; } #elseif ($count < 8) font-size: 2.00em; } #else font-size: 2.50em; } #end #end
And here's the java code invoked:
public static HashMap<String, Integer> getTagsWithCount(ArrayList<String> allTags) { String tag = null; String previousTag = null; HashMap<String, Integer> tagsWithCount = new HashMap<String, Integer>(); int count = 1; for (int i = 0; i < allTags.size(); i++) { previousTag = tag; tag = allTags.get(i); if ( tag.equals(previousTag)) { count++; } else { count = 1; previousTag = null; } tagsWithCount.put(tag, new Integer(count)); } return tagsWithCount; }
Is this anything you would want to include in xwiki, or is it too trivial to bother with? See the attached file for a sample screenshot.
best regards :-) Thomas Drevon
-- You receive this message as a subscriber of the xwiki- dev@objectweb.org mailing list. To unsubscribe: mailto:xwiki-dev-unsubscribe@objectweb.org For general help: mailto: sympa@objectweb.org?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/ wws
-- http://wikibc.blogspot.com/
-- You receive this message as a subscriber of the xwiki- dev@objectweb.org mailing list. To unsubscribe: mailto:xwiki-dev-unsubscribe@objectweb.org For general help: mailto:sympa@objectweb.org?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/ wws
Hi, I have some observations: - The java code can be transformed into a velocity macro. You can create a hashmap with $xwiki.getHashMap(), and you have #foreach, #if and #set. So there's no need for java or groovy code - The style isn't that extensible (1..8 as possible repetitions). You could also compute the maximum occurance count, and then use relative importance expressed as relative font size. For example, set font-size for the surrounding div to 3em, and for each tag font-size=<crtTagCount>*100/<maxTagCount> %. I think this should work. - Something I was saying just yesterday when discussing tag suggest, we need a cache for the tags, as the query is resource hungry when you have a large wiki (think flickr size...). This is something a bit harder, and you don't have to do it. It will have to be integrated later. Anyway, great initiative, and good job! Sergiu On 5/31/07, Vincent Massol <vincent@massol.net> wrote:
Hi Thomas,
I didn't see your email below (was it sent to the list?).
I'm all for offering a default tag cloud page/panel.
The notion of tag is not something known to XWiki core. Currently tags are only known at the level of the default wiki so we should probably put the tag cloud code there. As your code below requires some logic, maybe the best is to use Groovy to replace the Java part. You could then have everything located on a single page.
The next question is: a Panel or a Page?
I'm tempted to say both. I think we should include the tag cloud in the Main.Tags page and we could provide a Panel too.
WDYT?
I have created a jira issue for this: http://jira.xwiki.org/jira/browse/XWIKI-1311
Would you be interested in working on this and finishing this?
If so, could you please attach the result to that JIRA issue for inclusion in SVN?
Thanks a lot -Vincent
On May 31, 2007, at 1:42 AM, Guillaume Lerouge wrote:
Hi Thomas,
this looks quite cool!
There is a place on XWiki.org for this kind of contributions (http://www.xwiki.org/xwiki/bin/view/Code/), it would be very cool if you could add it there with a step by step explanation of how to use it (for instance in my case I have no idea where I am supposed to put the Java code - though I'm not actually a developer).
Even better would be to export the XAR of your XWiki, customize it to keep only the Main.TagCloud , Panels.TagCloud (and other pages required to make it work) and then upload it to XWiki.org like it is done for other applications already. To do so easily you can even download first the Packager Application here: http://www.xwiki.org/xwiki/bin/view/Code/PackagerApplication and use it to generate your XAR (which at the same time gives you an example of the page you could create for yours :-)
Funny thing is that I was wondering about tag cluds this afternoon but had no idea how to implement one :-) Thanks!
Guillaume
On 30/05/07, Thomas Drevon <thomas.drevon@intermedia.uio.no> wrote:
Hi!
Tag clouds (http://en.wikipedia.org/wiki/Tag_cloud ) seem so in these days, so I made a simple implementation using the Main.Tags in xwiki. The styling isn't too sexy, but that should be easy to configure.
Here is the code for use in a panel or similar place:
#panelheader('Tag cloud')
#set($query = "select elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $allTags = $xwiki.sort($xwiki.search($query)))
#set( $tagsWithCount = $xwiki.metawiki.getTagsWithCount($allTags))
#set($query = "select distinct elements( prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")
#set( $tagsDistinct = $xwiki.sort($xwiki.search($query)))
#foreach($tag in $tagsDistinct) <span style="#getStyle($tagsWithCount.get($tag))"><a href="$xwiki.getURL("Main.Tags", "view", "tag=$tag")")>$tag</a></span> #end
#panelfooter()
#macro( getStyle $count ) #if ($count < 2) "font-size: 0.80em;" #elseif ($count < 3) font-size: 1.00em; } #elseif ($count < 4) font-size: 1.20em; } #elseif ($count < 5) font-size: 1.40em; } #elseif ($count < 6) font-size: 1.60em; } #elseif ($count < 7) font-size: 1.80em; } #elseif ($count < 8) font-size: 2.00em; } #else font-size: 2.50em; } #end #end
And here's the java code invoked:
public static HashMap<String, Integer> getTagsWithCount(ArrayList<String> allTags) { String tag = null; String previousTag = null; HashMap<String, Integer> tagsWithCount = new HashMap<String, Integer>(); int count = 1; for (int i = 0; i < allTags.size(); i++) { previousTag = tag; tag = allTags.get(i); if ( tag.equals(previousTag)) { count++; } else { count = 1; previousTag = null; } tagsWithCount.put(tag, new Integer(count)); } return tagsWithCount; }
Is this anything you would want to include in xwiki, or is it too trivial to bother with? See the attached file for a sample screenshot.
best regards :-) Thomas Drevon
Vincent Massol wrote:
I didn't see your email below (was it sent to the list?).
Yup!
The notion of tag is not something known to XWiki core. Currently tags are only known at the level of the default wiki so we should probably put the tag cloud code there. As your code below requires some logic, maybe the best is to use Groovy to replace the Java part. You could then have everything located on a single page.
Mmm. Okay, I went with what Guillaume suggested, and made a xar and jar out of it, and contributed it as a plugin: http://www.xwiki.org/xwiki/bin/view/Code/TagCloud But I do see your point about eliminating the java-side of this. The logic isn't that hard to implement as a groovy script or velocity macro, I guess.
The next question is: a Panel or a Page?
I'm tempted to say both. I think we should include the tag cloud in the Main.Tags page and we could provide a Panel too.
WDYT?
Well, if it were only a page (or a "snippet"?) it might be easier for people to include it wherever they want, including in panels? But you guys more familiar with the level of expertise and mode of use amongst the xwiki masses, so I leave this for you to decide :-) Also, I agree with Sergiu that it would be better if the font size would be calculated relatively to the number of ocurrences. Good thinking!
I have created a jira issue for this: http://jira.xwiki.org/jira/browse/XWIKI-1311
I just did an update there.
Would you be interested in working on this and finishing this?
Sure!
If so, could you please attach the result to that JIRA issue for inclusion in SVN?
I'm not sure I understood this. Do you want me to commit stuff to svn, or attach stuff to the JIRA issue? Thanks for the enthusiasm on this! I have a couple of thoughts on how tags currently behave in xwiki, but I'll try to write a separate email on that subject a bit later. cheers :-) Thomas Drevon
On May 31, 2007, at 1:14 PM, Thomas Drevon wrote:
Vincent Massol wrote:
I didn't see your email below (was it sent to the list?).
Yup!
The notion of tag is not something known to XWiki core. Currently tags are only known at the level of the default wiki so we should probably put the tag cloud code there. As your code below requires some logic, maybe the best is to use Groovy to replace the Java part. You could then have everything located on a single page.
Mmm. Okay, I went with what Guillaume suggested, and made a xar and jar out of it, and contributed it as a plugin: http://www.xwiki.org/ xwiki/bin/view/Code/TagCloud
But I do see your point about eliminating the java-side of this. The logic isn't that hard to implement as a groovy script or velocity macro, I guess.
Yes that would be great and would allow to package it in xwiki's distribution.
The next question is: a Panel or a Page? I'm tempted to say both. I think we should include the tag cloud in the Main.Tags page and we could provide a Panel too. WDYT?
Well, if it were only a page (or a "snippet"?) it might be easier for people to include it wherever they want, including in panels? But you guys more familiar with the level of expertise and mode of use amongst the xwiki masses, so I leave this for you to decide :-)
Also, I agree with Sergiu that it would be better if the font size would be calculated relatively to the number of ocurrences. Good thinking!
I have created a jira issue for this: http://jira.xwiki.org/jira/browse/XWIKI-1311
I just did an update there.
cool. It looks like it still requires some java code though.
Would you be interested in working on this and finishing this?
Sure!
Excellent! Thanks for this.
If so, could you please attach the result to that JIRA issue for inclusion in SVN?
I'm not sure I understood this. Do you want me to commit stuff to svn, or attach stuff to the JIRA issue?
Attach stuff to JIRA (as you don't have commit access to SVN ... yet....).
Thanks for the enthusiasm on this! I have a couple of thoughts on how tags currently behave in xwiki, but I'll try to write a separate email on that subject a bit later.
Thanks to you. We do need to improve tagging in xwiki. One thing we need is the ability to tag a page without having to go in edit mode. There are also some ideas here: http://jira.xwiki.org/jira/browse/ XWIKI-523 Cheers, -Vincent
Vincent Massol wrote:
http://jira.xwiki.org/jira/browse/XWIKI-1311 Attach stuff to JIRA (as you don't have commit access to SVN ... yet....).
Ok, done! I re-wrote the whole thing only using velocity code. It seems to work fine. I also implemented the relative font size that Sergiu suggested, but I'm not completely satisfied with the result. Feel very free to tweak the formula that calculates the font-size :) I updated the JIRA issue, this time including all the velocity code. I couldn't find a way to mark the issue as resolved, but I guess that function's reserved for an admin of some sort. BTW: I'm having trouble deleting the plugin (http://www.xwiki.org/xwiki/bin/view/Code/TagCloud ) I created on xwiki.org, and I need to do that in order to creat a snippet with the same name.
Thanks for the enthusiasm on this! I have a couple of thoughts on how tags currently behave in xwiki, but I'll try to write a separate email on that subject a bit later.
Thanks to you. We do need to improve tagging in xwiki. One thing we need is the ability to tag a page without having to go in edit mode. There are also some ideas here: http://jira.xwiki.org/jira/browse/XWIKI-523
Ah, yes this would be really sweet. One of the reasons why we chose to use xwiki was because we thought it had good support for tags. Right now, it seems that tags can be added to a page that doesn't have a parent, but blog entries (for instance) won't handle even if the appropriate input field is on the page. At least until the servlet engine is restarted. /Then/ a customized input fields for tags will work. Am I right? At least this seems to be my experience, but I'm not positive that I've considered all the facets of this issue. cheers :-) Thomas
participants (4)
-
Guillaume Lerouge -
Sergiu Dumitriu -
Thomas Drevon -
Vincent Massol