-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,469 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
...project.iccs.graph.kde/src/main/java/eu/alertproject/iccs/graph/kde/api/GraphHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package eu.alertproject.iccs.graph.kde.api; | ||
|
||
import edu.uci.ics.jung.algorithms.filters.EdgePredicateFilter; | ||
import edu.uci.ics.jung.algorithms.filters.VertexPredicateFilter; | ||
import edu.uci.ics.jung.algorithms.scoring.BetweennessCentrality; | ||
import edu.uci.ics.jung.graph.Graph; | ||
import edu.uci.ics.jung.graph.UndirectedGraph; | ||
import edu.uci.ics.jung.graph.UndirectedSparseGraph; | ||
import org.apache.commons.collections15.Predicate; | ||
import org.apache.commons.collections15.TransformerUtils; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.io.LineIterator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.*; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* User: fotis | ||
* Date: 27/12/11 | ||
* Time: 19:35 | ||
*/ | ||
public class GraphHandler { | ||
|
||
private Logger logger = LoggerFactory.getLogger(GraphHandler.class); | ||
private Map<String,Number> weights =null; | ||
private BetweennessCentrality<Integer,String> bc; | ||
|
||
|
||
public Graph<Integer, String> create(File inputFile,File outputFile){ | ||
|
||
Graph<Integer,String> graph = null; | ||
|
||
LineIterator it = null; | ||
|
||
int max = 106000; | ||
BufferedWriter fw = null; | ||
OutputStreamWriter osw = null; | ||
FileOutputStream fos = null; | ||
try { | ||
it = FileUtils.lineIterator(inputFile, "UTF-8"); | ||
|
||
|
||
Integer previousFile = null; | ||
Integer previousAuthor = null; | ||
|
||
graph = new UndirectedSparseGraph<Integer, String>(); | ||
weights = new HashMap<String, Number>(); | ||
|
||
while (it.hasNext() || max > 0) { | ||
String next = String.valueOf(it.next()); | ||
|
||
|
||
String[] split = next.split(","); | ||
|
||
Integer fileId = Integer.valueOf(split[0]); | ||
Integer authorId = Integer.valueOf(split[1]); | ||
|
||
if (previousFile != null && previousFile.equals(fileId)) { | ||
|
||
|
||
String edge = previousFile + "_" + previousAuthor + "_" + authorId; | ||
|
||
//already added | ||
if (!graph.containsEdge(edge)) { | ||
graph.addEdge(edge, previousAuthor, authorId); | ||
weights.put(edge, 1); | ||
} else { | ||
weights.put(edge, weights.get(edge).intValue() + 1); | ||
} | ||
|
||
previousAuthor = authorId; | ||
|
||
} else { | ||
|
||
previousAuthor = authorId; | ||
previousFile = fileId; | ||
} | ||
|
||
max--; | ||
|
||
|
||
} | ||
|
||
|
||
|
||
logger.trace("void main(args) Vertex Count: {} ", graph.getVertexCount()); | ||
|
||
bc = new BetweennessCentrality<Integer, String>(graph, TransformerUtils.mapTransformer(weights)); | ||
logger.trace("void main(args) Betweeness calculated"); | ||
|
||
|
||
fos = new FileOutputStream(outputFile); | ||
osw = new OutputStreamWriter(fos, "UTF-8"); | ||
fw = new BufferedWriter(osw); | ||
|
||
for (Integer vertex : graph.getVertices()) { | ||
fw.write(vertex + "\t" + bc.getVertexScore(vertex) + "\n"); | ||
} | ||
|
||
|
||
logger.trace("void main(args) File created {}",outputFile); | ||
|
||
|
||
|
||
} catch (IOException e) { | ||
logger.error("IO Error ", e); | ||
} catch (NumberFormatException e) { | ||
logger.error("Wrong data", e); | ||
} finally { | ||
LineIterator.closeQuietly(it); | ||
IOUtils.closeQuietly(fw); | ||
IOUtils.closeQuietly(osw); | ||
IOUtils.closeQuietly(fos); | ||
|
||
} | ||
|
||
return graph; | ||
|
||
} | ||
|
||
public Map<String, Number> getWeights() { | ||
return weights; | ||
} | ||
|
||
public BetweennessCentrality<Integer, String> getBc() { | ||
return bc; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...u.alert-project.iccs.graph.kde/src/main/java/eu/alertproject/iccs/graph/kde/api/Init.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package eu.alertproject.iccs.graph.kde.api; | ||
|
||
import eu.alertproject.iccs.graph.kde.swing.GraphViewerController; | ||
import eu.alertproject.iccs.graph.kde.swing.GraphViewerPanel; | ||
|
||
import javax.swing.*; | ||
|
||
/** | ||
* User: fotis | ||
* Date: 27/12/11 | ||
* Time: 19:00 | ||
*/ | ||
public class Init { | ||
|
||
public static void main(String[] args) { | ||
|
||
|
||
SwingUtilities.invokeLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
|
||
|
||
GraphViewerPanel graphViewerPanel = new GraphViewerPanel(); | ||
|
||
JFrame frame = new JFrame("KDE Solid Betweenness"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.getContentPane().add(graphViewerPanel); | ||
frame.pack(); | ||
|
||
GraphViewerController controller = new GraphViewerController(graphViewerPanel); | ||
frame.setVisible(true); | ||
|
||
|
||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.