Author: laylaoesper
Date: 2010-06-28 10:05:45 -0700 (Mon, 28 Jun 2010)
New Revision: 20678
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SingleWordCluster.java
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryClusterBuilder.java
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordClusters.java
Log:
Adding specific sorted order to clusters for SemanticSummary Plugin.
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryClusterBuilder.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryClusterBuilder.java
2010-06-28 15:01:19 UTC (rev 20677)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryClusterBuilder.java
2010-06-28 17:05:45 UTC (rev 20678)
@@ -108,6 +108,9 @@
curPair = queue.remove();
clusters.combineClusters(curPair);
}//end while
+
+ //Sort Clusters
+ clusters.orderClusters();
}
/**
@@ -150,13 +153,14 @@
for(int i = 0; i < clusters.getClusters().size(); i++)
{
- ArrayList<String> curCluster =
clusters.getClusters().get(i);
+ SingleWordCluster curCluster =
clusters.getClusters().get(i);
+ ArrayList<String> curList = curCluster.getWordList();
Color clusterColor = getClusterColor(i);
//Iterate through the words
- for (int j = 0; j < curCluster.size(); j++)
+ for (int j = 0; j < curList.size(); j++)
{
- String curWord = curCluster.get(j);
+ String curWord = curList.get(j);
Integer fontSize =
params.calculateFontSize(curWord);
CloudWordInfo curInfo = new
CloudWordInfo(curWord, fontSize);
curInfo.setCloudParameters(params);
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SingleWordCluster.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SingleWordCluster.java
(rev 0)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SingleWordCluster.java
2010-06-28 17:05:45 UTC (rev 20678)
@@ -0,0 +1,140 @@
+/*
+ File: SingleWordCluster.java
+
+ Copyright 2010 - The Cytoscape Consortium (www.cytoscape.org)
+
+ Code written by: Layla Oesper
+ Authors: Layla Oesper, Ruth Isserlin, Daniele Merico
+
+ This library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this project. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package cytoscape.csplugins.semanticsummary;
+
+import java.util.ArrayList;
+
+/**
+ * The SingleWordCluster class contains information about a single set of
+ * clustered words for a CloudParameters object. These objects can be
+ * sorted / compared based on the total size of the fonts that would
+ * be used to represent them in a CloudParameters.
+ * @author Layla Oesper
+ * @version 1.0
+ */
+
+public class SingleWordCluster implements Comparable<SingleWordCluster>
+{
+
+ //VARIABLES
+ private ArrayList<String> wordList;
+ private Integer totalSum;
+ private CloudParameters params;
+ private boolean initialized;
+
+ //CONSTRUCTOR
+
+ /**
+ * Creates a fresh instance of the SingleWordCluster.
+ */
+ public SingleWordCluster()
+ {
+ wordList = new ArrayList<String>();
+ totalSum = 0;
+ params = new CloudParameters();
+ initialized = false;
+ }
+
+
+ //METHODS
+
+ /**
+ * Initializes the SingleWordCluster for the given CloudParameters.
+ * @param CloudParameters this SingleWordCluster is for.
+ */
+ public void initialize(CloudParameters cloudParams)
+ {
+ params = cloudParams;
+ initialized = true;
+ }
+
+ /**
+ * Adds an element to the WordList and updates the totalSum.
+ * @param String - word to add to the SingleWordCluster
+ */
+ public void add(String aWord)
+ {
+ //Do nothing if not initialized
+ if(!initialized)
+ return;
+
+ Integer fontSize = params.calculateFontSize(aWord);
+ totalSum = totalSum + fontSize;
+ wordList.add(aWord);
+ }
+
+ /**
+ * Removes a word from the WordList and updates the totalSum.
+ * @param String - word to remove from the SingleWordCluster
+ * @return String - word that was removed from the list
+ */
+ public String remove(String aWord)
+ {
+ if (!wordList.contains(aWord))
+ return null;
+
+ Integer fontSize = params.calculateFontSize(aWord);
+ totalSum = totalSum - fontSize;
+ wordList.remove(aWord);
+
+ return aWord;
+ }
+
+
+ /**
+ * Compares two SingleWordClusters based on the totalSum of the font
sizes,
+ * and then breaks ties based upon alphabetical sorting of the words
+ * in the list.
+ */
+ public int compareTo(SingleWordCluster o)
+ {
+ Integer thisCount = this.getTotalSum();
+ Integer compareCount = o.getTotalSum();
+
+ if (thisCount < compareCount)
+ {return -1;}
+ else if (thisCount > compareCount)
+ {return 1;}
+ else
+ {
+ //In case of ties, break alphabetically by first word
+ String thisWord = this.getWordList().get(0);
+ String compareWord = this.getWordList().get(0);
+
+ return thisWord.compareTo(compareWord);
+ }
+ }
+
+ //Getters and Setters
+
+ public ArrayList<String> getWordList()
+ {
+ return wordList;
+ }
+
+ public Integer getTotalSum()
+ {
+ return totalSum;
+ }
+
+}
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordClusters.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordClusters.java
2010-06-28 15:01:19 UTC (rev 20677)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WordClusters.java
2010-06-28 17:05:45 UTC (rev 20678)
@@ -23,6 +23,7 @@
package cytoscape.csplugins.semanticsummary;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
@@ -39,7 +40,7 @@
public class WordClusters
{
//VARIABLES
- private ArrayList<ArrayList<String>> clusters;
+ private ArrayList<SingleWordCluster> clusters;
private CloudParameters params;
boolean initialized;
@@ -50,7 +51,7 @@
*/
public WordClusters()
{
- clusters = new ArrayList<ArrayList<String>>();
+ clusters = new ArrayList<SingleWordCluster>();
params = new CloudParameters();
initialized = false;
}
@@ -72,12 +73,13 @@
Set<String> words = params.getSelectedCounts().keySet();
//Initialize as singletons
- clusters = new ArrayList<ArrayList<String>>();
+ clusters = new ArrayList<SingleWordCluster>();
for (Iterator<String> iter = words.iterator(); iter.hasNext();)
{
//Create a list for each word and add to main list
String curWord = iter.next();
- ArrayList<String> curList = new ArrayList<String>();
+ SingleWordCluster curList = new SingleWordCluster();
+ curList.initialize(cloudParams);
curList.add(curWord);
clusters.add(curList);
}
@@ -97,46 +99,51 @@
String firstWord = aPair.getFirstWord();
String secondWord = aPair.getSecondWord();
- ArrayList<String> firstList = null;
- ArrayList<String> secondList = null;
+ SingleWordCluster firstCluster = null;
+ SingleWordCluster secondCluster = null;
- for(Iterator<ArrayList<String>> iter = clusters.iterator();
iter.hasNext();)
+ for(Iterator<SingleWordCluster> iter = clusters.iterator();
iter.hasNext();)
{
- ArrayList<String> curList = iter.next();
- if (curList != null)
+ SingleWordCluster curCluster = iter.next();
+ if (curCluster != null)
{
//Find the Lists that have the first word at
the end, and the second word at
//the beginning
+ ArrayList<String> curList =
curCluster.getWordList();
int size = curList.size();
String firstItem = curList.get(0);
String lastItem = curList.get(size - 1);
if(firstItem.equals(secondWord))
- secondList = curList;
+ secondCluster = curCluster;
if(lastItem.equals(firstWord))
- firstList = curList;
+ firstCluster = curCluster;
}//end non null
}//end iterator
- ArrayList<String> newList = new ArrayList<String>();
+ SingleWordCluster newCluster = new SingleWordCluster();
+ newCluster.initialize(params);
+ ArrayList<String> firstList = firstCluster.getWordList();
+ ArrayList<String> secondList = secondCluster.getWordList();
+
for (int i = 0; i< firstList.size(); i++)
{
String curWord = firstList.get(i);
- newList.add(curWord);
+ newCluster.add(curWord);
}
for (int i = 0; i< secondList.size(); i++)
{
String curWord = secondList.get(i);
- newList.add(curWord);
+ newCluster.add(curWord);
}
//Remove old lists and add new
- clusters.remove(firstList);
- clusters.remove(secondList);
- clusters.add(newList);
+ clusters.remove(firstCluster);
+ clusters.remove(secondCluster);
+ clusters.add(newCluster);
}
/**
@@ -150,42 +157,54 @@
boolean isValid = false;
String firstWord = aPair.getFirstWord();
String secondWord = aPair.getSecondWord();
- ArrayList<String> firstList = null;
- ArrayList<String> secondList = null;
+ SingleWordCluster firstCluster = null;
+ SingleWordCluster secondCluster = null;
- for(Iterator<ArrayList<String>> iter = clusters.iterator();
iter.hasNext();)
+ for(Iterator<SingleWordCluster> iter = clusters.iterator();
iter.hasNext();)
{
- ArrayList<String> curList = iter.next();
- if (curList != null)
+ SingleWordCluster curCluster = iter.next();
+ if (curCluster != null)
{
//Find the Lists that have the first word at
the end, and the second word at
//the beginning
+ ArrayList<String> curList =
curCluster.getWordList();
int size = curList.size();
String firstItem = curList.get(0);
String lastItem = curList.get(size - 1);
if(firstItem.equals(secondWord))
- secondList = curList;
+ secondCluster = curCluster;
if(lastItem.equals(firstWord))
- firstList = curList;
+ firstCluster = curCluster;
}//end non null
}//end iterator
- if (firstList != null && secondList != null &&
(!firstList.equals(secondList)))
+ if (firstCluster != null && secondCluster != null &&
(!firstCluster.equals(secondCluster)))
isValid = true;
return isValid;
}
+ /**
+ * Sorts the clusters in decreasing size of the sum of the font sizes
+ * for each cluster.
+ * @return
+ */
+ public void orderClusters()
+ {
+ Collections.sort(clusters);
+ Collections.reverse(clusters);
+ }
+
//Getters and Setters
- public ArrayList<ArrayList<String>> getClusters()
+ public ArrayList<SingleWordCluster> getClusters()
{
return clusters;
}
- public void setClusters(ArrayList<ArrayList<String>> clusterSet)
+ public void setClusters(ArrayList<SingleWordCluster> clusterSet)
{
clusters = clusterSet;
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.