From: <tan...@us...> - 2009-07-30 16:57:13
|
Revision: 907 http://cishell.svn.sourceforge.net/cishell/?rev=907&view=rev Author: tankchintan Date: 2009-07-30 16:57:02 +0000 (Thu, 30 Jul 2009) Log Message: ----------- Converted the plugin to use jung/graph instead of nwb to resolve the dependency issue, since converter graph is inside the org.cishell package. Modified Paths: -------------- trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithm.java trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java Removed Paths: ------------- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphOutputGenerator.java trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Edge.java trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Node.java Modified: trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF 2009-07-30 16:57:02 UTC (rev 907) @@ -5,8 +5,14 @@ Bundle-Version: 1.0.0 Bundle-ClassPath: . Bundle-Localization: plugin -Import-Package: edu.iu.nwb.converter.nwb.common, - edu.iu.nwb.util.nwbfile, +Import-Package: edu.uci.ics.jung.graph, + edu.uci.ics.jung.graph.decorators, + edu.uci.ics.jung.graph.event, + edu.uci.ics.jung.graph.filters, + edu.uci.ics.jung.graph.filters.impl, + edu.uci.ics.jung.graph.impl, + edu.uci.ics.jung.graph.predicates, + edu.uci.ics.jung.utils, org.cishell.framework, org.cishell.framework.algorithm, org.cishell.framework.data, Modified: trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties 2009-07-30 16:57:02 UTC (rev 907) @@ -2,7 +2,7 @@ label=Converter Graph description=Provides graph of all the converters in the tool. in_data=null -out_data=file:text/nwb +out_data=edu.uci.ics.jung.graph.Graph service.pid=org.cishell.algorithm.convertergraph.ConverterGraphAlgorithm remoteable=true written_in=Java Modified: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithm.java =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithm.java 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithm.java 2009-07-30 16:57:02 UTC (rev 907) @@ -1,13 +1,6 @@ package org.cishell.algorithm.convertergraph; -import java.io.File; -import java.io.IOException; import java.util.Dictionary; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; @@ -21,9 +14,11 @@ import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; +import edu.uci.ics.jung.graph.Graph; + /** * This plugin collects information about all the active converters in the tool and - * outputs a NWB file having this Directed network. Also nodes corresponding to each + * outputs a JUNG Graph having this Directed network. Also nodes corresponding to each * MIME/TYPE are weighted depending upon how many times they participate in a converter * relationship. * @@ -35,7 +30,9 @@ private LogService logger; private BundleContext bundleContext; - private int nodeCount, edgeCount; + private Graph outputGraph; + + private int nodeCount = 0, edgeCount = 0; /** * Construct with the appropriate parameters. @@ -51,123 +48,25 @@ public Data[] execute() throws AlgorithmExecutionException { - try { - - /* - * Get all the converter service references currently in service. - * */ - ServiceReference[] allConverterServices = getAllConverters(); - - /* - * Process the references to create a network of weighted nodes & directed edges. - * */ - ConverterGraphComputation converterGraphComputation = - new ConverterGraphComputation(allConverterServices, logger); - - /* - * Used to generate the output file containing the network. - * */ - File outputNWBFile = createOutputGraphFile(converterGraphComputation); - - return prepareOutputMetadata(new BasicData(outputNWBFile, "file:text/nwb")); + /* + * Get all the converter service references currently in service. + * */ + ServiceReference[] allConverterServices = getAllConverters(); - } catch (IOException e) { - throw new AlgorithmExecutionException(e); - } - } - - /** - * Call all the NWB File Handler processes in order to create a NWB file. - * @param converterGraphComputation - * @return - * @throws IOException - */ - private File createOutputGraphFile( - ConverterGraphComputation converterGraphComputation) - throws IOException { - - File outputNWBFile = File.createTempFile("nwb-", ".nwb"); - - ConverterGraphOutputGenerator outputGenerator = new ConverterGraphOutputGenerator( - converterGraphComputation, outputNWBFile); - - outputGenerator.addComment("Graph of all Converters in the Tool."); - - nodeCount = converterGraphComputation.nodes.size(); - outputGenerator.setNodeCount(nodeCount); - - outputGenerator.setNodeSchema(converterGraphComputation.nodeSchema); - - /* - * Print all the node rows to the output file. - * */ - setNodeTuples(converterGraphComputation, outputGenerator); - - edgeCount = converterGraphComputation.edges.size(); - outputGenerator.setDirectedEdgeCount(edgeCount); - - outputGenerator.setDirectedEdgeSchema(converterGraphComputation.edgeSchema); - - /* - * Print all the edge rows to the output file. - * */ - setDirectedEdgeTuples(converterGraphComputation, outputGenerator); - - outputGenerator.finishedParsing(); - outputGenerator.haltParsingNow(); - return outputNWBFile; - } - - /** - * Iterate through the nodes and print it into the output file. - * @param converterGraphComputation - * @param outputGenerator - */ - private void setDirectedEdgeTuples( - ConverterGraphComputation converterGraphComputation, - ConverterGraphOutputGenerator outputGenerator) { - - for (Iterator edgeIterator = converterGraphComputation.edges.iterator(); - edgeIterator.hasNext();) { + /* + * Process the references to create a network of weighted nodes & directed edges. + * */ + ConverterGraphComputation converterGraphComputation = + new ConverterGraphComputation(allConverterServices, logger); - Edge edge = (Edge) edgeIterator.next(); - int sourceNode = edge.source; - int targetNode = edge.target; - final String converterName = edge.serviceShortPID; - final String servicePID = edge.serviceCompletePID; - - outputGenerator.addDirectedEdge(sourceNode, targetNode, new HashMap() {{ - put("converter_name", converterName); - put("service_pid", servicePID); - }}); - } + /* + * Used to generate the output reference for graph containing the network. + * */ + return prepareOutputMetadata(new BasicData(converterGraphComputation.getOutputGraph(), + Graph.class.getName())); } /** - * @param converterGraphComputation - * @param outputGenerator - */ - private void setNodeTuples( - ConverterGraphComputation converterGraphComputation, - ConverterGraphOutputGenerator outputGenerator) { - - for (Iterator nodeIterator = converterGraphComputation.nodes.entrySet().iterator(); - nodeIterator.hasNext();) { - - Map.Entry node = (Entry) nodeIterator.next(); - - int nodeID = ((Node) node.getValue()).id; - final int strength = ((Node) node.getValue()).strength; - String label = node.getKey().toString(); - - outputGenerator.addNode(nodeID, label, new HashMap() {{ - put("strength", strength); - }}); - } - } - - - /** * Gets all the converter service references based on the LDAP query. * @return */ @@ -199,8 +98,10 @@ * @param outNWBData */ private Data[] prepareOutputMetadata(Data outNWBData) { + outNWBData.getMetadata().put(DataProperty.LABEL, "Converter Graph having " - + nodeCount + " nodes & " + edgeCount + " edges."); + + ((Graph) outNWBData.getData()).numVertices() + " nodes & " + + ((Graph) outNWBData.getData()).numEdges() + " edges."); outNWBData.getMetadata().put(DataProperty.TYPE, DataProperty.NETWORK_TYPE); return new Data[]{outNWBData}; } Modified: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java 2009-07-30 16:57:02 UTC (rev 907) @@ -3,41 +3,44 @@ */ package org.cishell.algorithm.convertergraph; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -import edu.iu.nwb.util.nwbfile.NWBFileProperty; +import edu.uci.ics.jung.graph.Edge; +import edu.uci.ics.jung.graph.Graph; +import edu.uci.ics.jung.graph.Vertex; +import edu.uci.ics.jung.graph.impl.DirectedSparseEdge; +import edu.uci.ics.jung.graph.impl.DirectedSparseGraph; +import edu.uci.ics.jung.graph.impl.DirectedSparseVertex; +import edu.uci.ics.jung.utils.UserDataContainer; /** * The algorithm is used for getting information about current converters is, * 1. Get all the service references for converters in the system. - * 2. Create Node Schema to be used when constructing the NWB file. In this case - * it will be, + * 2. Node Schema to be used is, * id*int, label*string, strength*int - * 3. Create Edge Schema to be used when constructing the NWB file. In this case - * it will be, + * 3. Edge Schema to be used is, * source*int, target*int, converter_name*string, service_pid*string * 4. Iterate over all the converter service reference one at a time. * 5. For collecting information for Nodes do, * (a). Get node label using service properties in_data & out_data. - * (b). Check to see if this node is already present in the nodes map. + * (b). Check to see if this node is already present in the nodeLabels set. * (c). If it is present then just update the strength of node by incrementing * that node's strength by 1. * (d). Else create a new node. Provide it a default strength of 1 and update - * the node count. + * the node count. Also create an entry in the nodeLabels for future + * reference. * 6. For collecting information about Edges do, - * (a). Get the respective source & target node ids from the recently updates - * respective nodes. + * (a). Get the respective source & target node references from the recently updated + * nodes. * (b). Get the service_pid by using service property service.pid. * (c). Get the converter_name by extracting the last block from service_pid. - * 7. These information is then passed on to {@link ConverterGraphOutputGenerator} - * for printing it into a NWB file. + * 7. Since the graph is being created during the processing of each node & edge + * it just needs to be referenced on the UI. This is done by outputting the metadata. * * @author cdtank * @@ -47,12 +50,17 @@ private LogService logger; private ServiceReference[] allConverterServices; - public Map nodes = new HashMap(); - public LinkedHashMap nodeSchema = new LinkedHashMap(); + private Set nodeLabels = new HashSet(); - public List edges = new ArrayList(); - public LinkedHashMap edgeSchema = new LinkedHashMap(); + private Graph outputGraph; + /** + * @return the outputGraph + */ + public Graph getOutputGraph() { + return outputGraph; + } + private int nodeCount; public ConverterGraphComputation(ServiceReference[] allConverterServices, @@ -61,38 +69,14 @@ this.nodeCount = 0; this.logger = logger; this.allConverterServices = allConverterServices; + this.outputGraph = new DirectedSparseGraph(); /* - * Side affects nodeSchema - * */ - createNodeSchema(); - - /* - * Side affects edgeSchema - * */ - createEdgeSchema(); - - /* * Side affects nodes & edges * */ processServiceReferences(); } - private void createNodeSchema() { - nodeSchema.put("id", NWBFileProperty.TYPE_INT); - nodeSchema.put("label", NWBFileProperty.TYPE_STRING); - nodeSchema.put("strength", NWBFileProperty.TYPE_INT); - } - - private void createEdgeSchema() { - edgeSchema.put("source", NWBFileProperty.TYPE_INT); - edgeSchema.put("target", NWBFileProperty.TYPE_INT); - edgeSchema.put("converter_name", NWBFileProperty.TYPE_STRING); - edgeSchema.put("service_pid", NWBFileProperty.TYPE_STRING); - } - - - /* * Iterate over all the converter service references and process the * information to get nodes & edges. @@ -103,7 +87,7 @@ converterCount < allConverterServices.length; converterCount++) { - int sourceNodeID, targetNodeID; + Vertex sourceNode, targetNode; ServiceReference currentConverterServiceReference = allConverterServices[converterCount]; @@ -113,47 +97,61 @@ String targetNodeKey = (String) currentConverterServiceReference.getProperty("out_data"); - if (nodes.containsKey(sourceNodeKey)) { - sourceNodeID = updateNode(sourceNodeKey); + if (nodeLabels.contains(sourceNodeKey)) { + sourceNode = updateNode(sourceNodeKey); } else { - sourceNodeID = createNode(sourceNodeKey); + sourceNode = createNode(sourceNodeKey); } - if (nodes.containsKey(targetNodeKey)) { - targetNodeID = updateNode(targetNodeKey); + if (nodeLabels.contains(targetNodeKey)) { + targetNode = updateNode(targetNodeKey); } else { - targetNodeID = createNode(targetNodeKey); + targetNode = createNode(targetNodeKey); } - createEdge(sourceNodeID, targetNodeID, currentConverterServiceReference); + createEdge(sourceNode, targetNode, currentConverterServiceReference); } } - private int updateNode(String currentNodeKey) { - int sourceNodeID; - Node sourceNodeValue = (Node) nodes.get(currentNodeKey); - sourceNodeID = sourceNodeValue.id; - sourceNodeValue.strength += 1; - return sourceNodeID; + private Vertex updateNode(String currentNodeKey) { + + for (Iterator nodeIterator = outputGraph.getVertices().iterator(); + nodeIterator.hasNext();) { + Vertex currentVertex = (Vertex) nodeIterator.next(); + if (currentVertex.getUserDatum("label").toString() + .equalsIgnoreCase(currentNodeKey)) { + int currentVertexStrength = + ((Integer) currentVertex.getUserDatum("strength")).intValue(); + currentVertex.setUserDatum("strength", ++currentVertexStrength, + new UserDataContainer.CopyAction.Shared()); + return currentVertex; + } + } + return new DirectedSparseVertex(); } - private int createNode(String nodeKey) { + private Vertex createNode(String nodeKey) { nodeCount++; - Node nodeValue = new Node(); - nodeValue.id = nodeCount; - nodeValue.strength = 1; - nodes.put(nodeKey, nodeValue); - return nodeCount; + Vertex node = new DirectedSparseVertex(); + + node.addUserDatum("id", nodeCount, new UserDataContainer.CopyAction.Shared()); + node.addUserDatum("strength", 1, new UserDataContainer.CopyAction.Shared()); + node.addUserDatum("label", nodeKey, new UserDataContainer.CopyAction.Shared()); + + outputGraph.addVertex(node); + nodeLabels.add(nodeKey); + + return node; } /** * Create an edge based on source id, target id & other information. - * @param sourceNodeID - * @param targetNodeID + * @param sourceNode + * @param targetNode * @param currentConverterServiceReference */ - private void createEdge(int sourceNodeID, int targetNodeID, + private void createEdge(Vertex sourceNode, Vertex targetNode, ServiceReference currentConverterServiceReference) { String serviceCompletePID = (String) currentConverterServiceReference.getProperty("service.pid"); @@ -166,15 +164,16 @@ String serviceShortPID = serviceCompletePID.substring(startIndexForConverterName); /* - * Build the actual edge tuple. + * Build the actual edge & attach it to the graph. * */ - Edge edge = new Edge(); - edge.source = sourceNodeID; - edge.target = targetNodeID; - edge.serviceShortPID = serviceShortPID; - edge.serviceCompletePID = serviceCompletePID; + Edge edge = new DirectedSparseEdge(sourceNode, targetNode); - edges.add(edge); + edge.addUserDatum("converter_name", serviceShortPID, + new UserDataContainer.CopyAction.Shared()); + edge.addUserDatum("service_pid", serviceCompletePID, + new UserDataContainer.CopyAction.Shared()); + + outputGraph.addEdge(edge); } } Deleted: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphOutputGenerator.java =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphOutputGenerator.java 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphOutputGenerator.java 2009-07-30 16:57:02 UTC (rev 907) @@ -1,62 +0,0 @@ -package org.cishell.algorithm.convertergraph; - -import java.io.File; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; - -import edu.iu.nwb.util.nwbfile.NWBFileParserHandler; -import edu.iu.nwb.util.nwbfile.NWBFileWriter; - -public class ConverterGraphOutputGenerator implements NWBFileParserHandler { - - private NWBFileWriter output; - - public ConverterGraphOutputGenerator(ConverterGraphComputation converterGraphComputation, - File outputNWBFile) throws IOException { - output = new NWBFileWriter(outputNWBFile); - } - - public void setNodeCount(int numberOfNodes) { - output.setNodeCount(numberOfNodes); - } - - public void setNodeSchema(LinkedHashMap schema) { - output.setNodeSchema(schema); - } - - public void addNode(int id, String label, Map attributes) { - output.addNode(id, label, attributes); - } - - public void addDirectedEdge(int sourceNode, int targetNode, Map attributes) { - output.addDirectedEdge(sourceNode, targetNode, attributes); - } - public void addUndirectedEdge(int node1, int node2, Map attributes) { - output.addUndirectedEdge(node1, node2, attributes); - } - public void setDirectedEdgeCount(int numberOfEdges) { - output.setDirectedEdgeCount(numberOfEdges); - } - public void setDirectedEdgeSchema(LinkedHashMap schema) { - output.setDirectedEdgeSchema(schema); - } - public void setUndirectedEdgeCount(int numberOfEdges) { - output.setUndirectedEdgeCount(numberOfEdges); - } - public void setUndirectedEdgeSchema(LinkedHashMap schema) { - output.setUndirectedEdgeSchema(schema); - } - - public void addComment(String comment) { - output.addComment(comment); - } - - public void finishedParsing() { - output.finishedParsing(); - } - - public boolean haltParsingNow() { - return false; - } -} Deleted: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Edge.java =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Edge.java 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Edge.java 2009-07-30 16:57:02 UTC (rev 907) @@ -1,8 +0,0 @@ -package org.cishell.algorithm.convertergraph; - -public class Edge { - public int source; - public int target; - public String serviceShortPID; - public String serviceCompletePID; -} \ No newline at end of file Deleted: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Node.java =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Node.java 2009-07-30 14:48:59 UTC (rev 906) +++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Node.java 2009-07-30 16:57:02 UTC (rev 907) @@ -1,13 +0,0 @@ -/** - * - */ -package org.cishell.algorithm.convertergraph; - -/** - * @author cdtank - * - */ -public class Node { - public int id; - public int strength; -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |