
timeBench.action.analytical.TreeDebundlingAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timebench Show documentation
Show all versions of timebench Show documentation
TimeBench, a flexible, easy-to-use, and reusable software library written in Java that provides foundational data structures and algorithms for time- oriented data in Visual Analytics.
The newest version!
package timeBench.action.analytical;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Iterator;
import prefuse.data.tuple.TableTuple;
import timeBench.data.TemporalDataException;
import timeBench.data.TemporalDataset;
import timeBench.data.TemporalDatasetProvider;
import timeBench.data.TemporalObject;
/**
*
*
*
* Added: / TL
* Modifications:
*
*
* @author Tim Lammarsch
*
*/
public class TreeDebundlingAction extends prefuse.action.Action implements TemporalDatasetProvider {
TemporalDataset sourceDataset;
TemporalDataset workingDataset;
Hashtable classes = null;
ArrayList workingClasses = null;
public TreeDebundlingAction(TemporalDataset sourceDataset) {
this.sourceDataset = sourceDataset;
}
/* (non-Javadoc)
* @see prefuse.action.Action#run(double)
*/
@Override
public void run(double frac) {
try {
workingDataset = new TemporalDataset();
workingDataset.addDataColumn("label", String.class, "");
workingDataset.addDataColumn("class", int.class, -1);
for(TemporalObject root : sourceDataset.roots()) {
ArrayList leafList = new ArrayList();
ArrayList stringsToLeaf = new ArrayList();
String currentStringState = root.getString("label");
findLeaves(root,leafList,stringsToLeaf,currentStringState);
for(int i=0; i();
for(TemporalObject iTo : workingDataset.temporalObjects()) {
String label = iTo.getString("label");
int thisclass = workingClasses.indexOf(label);
if (thisclass == -1) {
workingClasses.add(label);
thisclass = workingClasses.size()-1;
}
iTo.setInt("class", thisclass);
}
classes = new Hashtable();
String[] sortedClasses = (String[])workingClasses.toArray(new String[workingClasses.size()]);
Arrays.sort(sortedClasses);
double addPerStep = 12.0/(double)sortedClasses.length;
double val=0;
for(String iStr : sortedClasses) {
classes.put(iStr, (int)Math.round(val));
val += addPerStep;
}
} catch (TemporalDataException e) {
throw new RuntimeException(e.getMessage());
}
}
private void findLeaves(TemporalObject temporalObject,ArrayList leafList,
ArrayList stringsToLeaf, String currentStringState) {
if (temporalObject.getChildCount() == 0) {
leafList.add(temporalObject);
stringsToLeaf.add(currentStringState);
} else {
for(TemporalObject iChild : temporalObject.childObjects()) {
Iterator edges = iChild.outEdges();
String addedStringState = currentStringState + "p" +
((TableTuple)edges.next()).getLong(MultiPredicatePatternDiscovery.predicateColumn) +
iChild.getString("label");
findLeaves(iChild,leafList,stringsToLeaf,addedStringState);
}
}
}
public Hashtable getClasses() {
return classes;
}
/* (non-Javadoc)
* @see timeBench.data.TemporalDatasetProvider#getTemporalDataset()
*/
@Override
public TemporalDataset getTemporalDataset() {
return workingDataset;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy