net.clementlevallois.utils.CooccurrencesAnalyzer Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.clementlevallois.utils;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
*
* @author C. Levallois
* @param
* @param
*/
public class CooccurrencesAnalyzer, R extends Comparable> implements Serializable {
private Map> inputUndirected;
private Map> inputDirected;
/**
*
*/
public CooccurrencesAnalyzer() {
}
/**
*
* @param inputUndirected
*/
public void setInputUndirected(Map> inputUndirected) {
this.inputUndirected = inputUndirected;
}
/**
*
* @param inputDirected
*/
public void setInputDirected(Map> inputDirected) {
this.inputDirected = inputDirected;
}
// public CooccurrencesAnalyzer(Map> input) {
// this.input = input;
// }
/**
*
* @return
*/
public Set returnSetNodes() {
Set setNodes = new HashSet();
Set set;
UnDirectedPair pair;
Iterator setIterator;
if (inputUndirected == null) {
Iterator> inputValuesIterator = inputDirected.values().iterator();
while (inputValuesIterator.hasNext()) {
pair = inputValuesIterator.next();
set = new HashSet();
set.addAll((Set) pair.getLeft());
set.addAll((Set) pair.getRight());
setIterator = set.iterator();
while (setIterator.hasNext()) {
L l = setIterator.next();
setNodes.add(new Node((String) l, (String) l));
}
}
} else {
Iterator> inputValuesIterator = inputUndirected.values().iterator();
while (inputValuesIterator.hasNext()) {
set = inputValuesIterator.next();
setIterator = set.iterator();
while (setIterator.hasNext()) {
L l = setIterator.next();
setNodes.add(new Node((String) l, (String) l));
}
}
}
return setNodes;
}
/**
*
* @return
*/
public Set returnSetEdges() {
Set setEdges;
// if (inputUndirected == null) {
// setEdges = returnSetEdgesDirected();
//
// }
// else {
setEdges = returnSetEdgesUndirected();
//
// }
return setEdges;
}
// public Set returnSetEdgesDirected() {
// Clock getAllDirectedPairsClock = new Clock("getting all directed pairs of mentions");
// Set setEdges = new HashSet();
// Set currSetEdges;
// Iterator> inputValuesIterator = inputDirected.values().iterator();
// Iterator currSetEdgesIterator;
// UnDirectedPair pairSetsNodes;
// DirectedPair pair;
// Set setSources;
// Set setTargets;
// while (inputValuesIterator.hasNext()) {
// pairSetsNodes = inputValuesIterator.next();
// setSources = (Set) pairSetsNodes.getLeft();
// setTargets = (Set) pairSetsNodes.getRight();
// currSetEdges = new FindAllPairs().getAllDirectedPairsFromTwoSets(setSources, setTargets);
// currSetEdgesIterator = currSetEdges.iterator();
// while (currSetEdgesIterator.hasNext()) {
// pair = currSetEdgesIterator.next();
// Edge edge = new Edge((String) pair.getLeft(), (String) pair.getRight(), true);
// multisetEdges.addOne();
// }
// }
// Iterator multisetEdgesIterator = multisetEdges.getElementSet().iterator();
// Edge edge;
// while (multisetEdgesIterator.hasNext()) {
// edge = multisetEdgesIterator.next();
// edge.setWeight(multisetEdges.getCount(edge));
// setEdges.add(edge);
// }
//
//
//
// getAllDirectedPairsClock.closeAndPrintClock();
//
// return setEdges;
// }
/**
*
* @return
*/
public Set returnSetEdgesUndirected() {
Set setEdges = new HashSet();
Set set;
Set currSetEdges;
Iterator> inputValuesIterator = inputUndirected.values().iterator();
Iterator currSetEdgesIterator;
while (inputValuesIterator.hasNext()) {
set = inputValuesIterator.next();
currSetEdges = new FindAllPairs().getAllUndirectedPairs(set);
currSetEdgesIterator = currSetEdges.iterator();
while (currSetEdgesIterator.hasNext()) {
UnDirectedPair pair = currSetEdgesIterator.next();
setEdges.add(new Edge((String) pair.getLeft(), (String) pair.getRight(), false));
}
}
return setEdges;
}
}