|
From: <tan...@us...> - 2009-07-24 18:09:46
|
Revision: 900
http://cishell.svn.sourceforge.net/cishell/?rev=900&view=rev
Author: tankchintan
Date: 2009-07-24 18:09:35 +0000 (Fri, 24 Jul 2009)
Log Message:
-----------
Initial Import. Converter Graph plugin. For outputting a graph of all the converters in the tool. Code reviewed by Micah.
Added Paths:
-----------
trunk/core/org.cishell.algorithm.convertergraph/.classpath
trunk/core/org.cishell.algorithm.convertergraph/.project
trunk/core/org.cishell.algorithm.convertergraph/.settings/
trunk/core/org.cishell.algorithm.convertergraph/.settings/org.eclipse.pde.core.prefs
trunk/core/org.cishell.algorithm.convertergraph/META-INF/
trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/component.xml
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/l10n/
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/l10n/bundle_en.properties
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/metatype/
trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/metatype/METADATA.XML
trunk/core/org.cishell.algorithm.convertergraph/build/
trunk/core/org.cishell.algorithm.convertergraph/build.properties
trunk/core/org.cishell.algorithm.convertergraph/src/
trunk/core/org.cishell.algorithm.convertergraph/src/org/
trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/
trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/
trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/
trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithm.java
trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithmFactory.java
trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java
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
Added: trunk/core/org.cishell.algorithm.convertergraph/.classpath
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/.classpath (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/.classpath 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="build"/>
+</classpath>
Added: trunk/core/org.cishell.algorithm.convertergraph/.project
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/.project (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/.project 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.cishell.algorithm.convertergraph</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/core/org.cishell.algorithm.convertergraph/.settings/org.eclipse.pde.core.prefs
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/.settings/org.eclipse.pde.core.prefs (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/.settings/org.eclipse.pde.core.prefs 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,4 @@
+#Thu Nov 30 13:33:03 EST 2006
+eclipse.preferences.version=1
+pluginProject.equinox=false
+pluginProject.extensions=false
Added: trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/META-INF/MANIFEST.MF 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Converter Graph
+Bundle-SymbolicName: org.cishell.algorithm.convertergraph
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Bundle-Localization: plugin
+Import-Package: edu.iu.nwb.converter.nwb.common,
+ edu.iu.nwb.util.nwbfile,
+ org.cishell.framework,
+ org.cishell.framework.algorithm,
+ org.cishell.framework.data,
+ org.cishell.reference.service.metatype,
+ org.osgi.framework;version="1.3.0",
+ org.osgi.service.component;version="1.0.0",
+ org.osgi.service.log;version="1.3.0",
+ org.osgi.service.metatype,
+ org.osgi.service.prefs;version="1.1.0"
+X-AutoStart: true
+Service-Component: OSGI-INF/component.xml
Added: trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/algorithm.properties 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,12 @@
+menu_path=File/additions
+label=Converter Graph
+description=Provides graph of all the converters in the tool.
+in_data=null
+out_data=file:text/nwb
+service.pid=org.cishell.algorithm.convertergraph.ConverterGraphAlgorithm
+remoteable=true
+written_in=Java
+author=Chintan Tank
+implementers=Chintan Tank
+integrators=Chintan Tank
+documentation_url=https://nwb.slis.indiana.edu/community/?n=File.ConverterGraph
\ No newline at end of file
Added: trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/component.xml
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/component.xml (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/component.xml 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component name="org.cishell.algorithm.convertergraph.ConverterGraphAlgorithm.component" immediate="false">
+ <implementation class="org.cishell.algorithm.convertergraph.ConverterGraphAlgorithmFactory"/>
+ <properties entry="OSGI-INF/algorithm.properties"/>
+ <reference name="LOG" interface="org.osgi.service.log.LogService"/>
+ <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/>
+
+ <service>
+ <provide interface=
+ "org.cishell.framework.algorithm.AlgorithmFactory"/>
+ </service>
+</component>
\ No newline at end of file
Added: trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/l10n/bundle_en.properties
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/l10n/bundle_en.properties (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/l10n/bundle_en.properties 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,7 @@
+#Localization variables for OSGI-INF/metatatype/METADATA.XML
+#
+#Samples:
+#input=Input
+#desc=Enter an integer (that will be converted to a string)
+#name=Input->String
+#name_desc=Converts inputted integer to string
Added: trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/metatype/METADATA.XML
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/metatype/METADATA.XML (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/OSGI-INF/metatype/METADATA.XML 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0">
+ <OCD name="Converter Graph" id="org.cishell.algorithm.convertergraph.ConverterGraphAlgorithm.OCD"
+ description="Provides Graph of all the converters in the tool.">
+ </OCD>
+ <Designate pid="org.cishell.algorithm.convertergraph.ConverterGraphAlgorithm">
+ <Object ocdref="org.cishell.algorithm.convertergraph.ConverterGraphAlgorithm.OCD" />
+ </Designate>
+</metatype:MetaData>
Added: trunk/core/org.cishell.algorithm.convertergraph/build.properties
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/build.properties (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/build.properties 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = build/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/
Added: 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 (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithm.java 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,214 @@
+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;
+import org.cishell.framework.algorithm.AlgorithmExecutionException;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.BasicData;
+import org.cishell.framework.data.Data;
+import org.cishell.framework.data.DataProperty;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+/**
+ * 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
+ * MIME/TYPE are weighted depending upon how many times they participate in a converter
+ * relationship.
+ *
+ * @author Chintan Tank
+ */
+
+public class ConverterGraphAlgorithm implements Algorithm{
+
+ private static final int NODE_STRENGTH_INDEX = 1;
+ private static final int NODEID_INDEX = 0;
+ private static final int CONVERTER_SERVICE_PID_INDEX = 3;
+ private static final int CONVERTER_NAME_INDEX = 2;
+ private static final int EDGE_TARGETID_INDEX = 1;
+ private static final int EDGE_SOURCEID_INDEX = 0;
+
+ private LogService logger;
+ private BundleContext bundleContext;
+
+ private int nodeCount, edgeCount;
+
+ /**
+ * Construct with the appropriate parameters
+ * @param ciShellContext
+ * @param bundleContext
+ * @throws AlgorithmExecutionException
+ */
+ public ConverterGraphAlgorithm(Data[] data, Dictionary parameters,
+ CIShellContext ciShellContext, BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ this.logger = (LogService) ciShellContext.getService(LogService.class.getName());
+ }
+
+ 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"));
+
+ } 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(); ) {
+
+ 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);
+ }});
+ }
+ }
+
+ /**
+ * @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
+ */
+ private ServiceReference[] getAllConverters() {
+ try {
+ ServiceReference[] allConverters =
+ bundleContext.getAllServiceReferences(
+ AlgorithmFactory.class.getName(),
+ "(&(type=converter))");
+
+ if (allConverters == null) {
+ /*
+ * better to return a list of length zero than null
+ * */
+
+ allConverters = new ServiceReference[]{};
+ }
+
+ return allConverters;
+
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return new ServiceReference[]{};
+ }
+ }
+
+ /**
+ * Prepares output metadata to be displayed to the user.
+ * @param outNWBData
+ */
+ private Data[] prepareOutputMetadata(Data outNWBData) {
+ outNWBData.getMetadata().put(DataProperty.LABEL, "Converter Graph having "
+ + nodeCount + " nodes & " + edgeCount + " edges.");
+ outNWBData.getMetadata().put(DataProperty.TYPE, DataProperty.NETWORK_TYPE);
+ return new Data[]{outNWBData};
+ }
+}
Added: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithmFactory.java
===================================================================
--- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithmFactory.java (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphAlgorithmFactory.java 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,28 @@
+package org.cishell.algorithm.convertergraph;
+
+import java.util.Dictionary;
+
+import org.cishell.framework.CIShellContext;
+import org.cishell.framework.algorithm.Algorithm;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.data.Data;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @author cdtank
+ *
+ */
+
+public class ConverterGraphAlgorithmFactory implements AlgorithmFactory{
+
+ private BundleContext bundleContext;
+
+ protected void activate(ComponentContext ctxt) {
+ bundleContext = ctxt.getBundleContext();
+ }
+
+ public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) {
+ return new ConverterGraphAlgorithm(data, parameters, context, bundleContext);
+ }
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,176 @@
+/**
+ *
+ */
+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 org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+import edu.iu.nwb.util.nwbfile.NWBFileProperty;
+
+/**
+ * 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,
+ * id*int, label*string, strength*int
+ * 3. Create Edge Schema to be used when constructing the NWB file. In this case
+ * it will be,
+ * 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.
+ * (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.
+ * 6. For collecting information about Edges do,
+ * (a). Get the respective source & target node ids from the recently updates
+ * respective 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.
+ *
+ * @author cdtank
+ *
+ */
+public class ConverterGraphComputation {
+
+ private LogService logger;
+ private ServiceReference[] allConverterServices;
+
+ public Map nodes = new HashMap();
+ public LinkedHashMap nodeSchema = new LinkedHashMap();
+
+ public List edges = new ArrayList();
+ public LinkedHashMap edgeSchema = new LinkedHashMap();
+
+ private int nodeCount;
+
+ public ConverterGraphComputation(ServiceReference[] allConverterServices,
+ LogService logger) {
+
+ this.nodeCount = 0;
+ this.logger = logger;
+ this.allConverterServices = allConverterServices;
+
+ /*
+ * 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.
+ * */
+ private void processServiceReferences() {
+
+ for(int converterCount = 0; converterCount < allConverterServices.length; converterCount++) {
+
+ int sourceNodeID, targetNodeID;
+
+ ServiceReference currentConverterServiceReference = allConverterServices[converterCount];
+
+ String sourceNodeKey = (String)currentConverterServiceReference.getProperty("in_data");
+ String targetNodeKey = (String)currentConverterServiceReference.getProperty("out_data");
+
+ if(nodes.containsKey(sourceNodeKey)) {
+ sourceNodeID = updateNode(sourceNodeKey);
+ }
+ else {
+ sourceNodeID = createNode(sourceNodeKey);
+ }
+
+ if(nodes.containsKey(targetNodeKey)) {
+ targetNodeID = updateNode(targetNodeKey);
+ }
+ else {
+ targetNodeID = createNode(targetNodeKey);
+ }
+
+ createEdge(sourceNodeID, targetNodeID, currentConverterServiceReference);
+ }
+ }
+
+ private int updateNode(String currentNodeKey) {
+ int sourceNodeID;
+ Node sourceNodeValue = (Node) nodes.get(currentNodeKey);
+ sourceNodeID = sourceNodeValue.id;
+ sourceNodeValue.strength += 1;
+ return sourceNodeID;
+ }
+
+ private int createNode(String nodeKey) {
+ nodeCount++;
+ Node nodeValue = new Node();
+ nodeValue.id = nodeCount;
+ nodeValue.strength = 1;
+
+ nodes.put(nodeKey, nodeValue);
+ return nodeCount;
+ }
+
+ /**
+ * Create an edge based on source id, target id & other information.
+ * @param sourceNodeID
+ * @param targetNodeID
+ * @param currentConverterServiceReference
+ */
+ private void createEdge(int sourceNodeID, int targetNodeID,
+ ServiceReference currentConverterServiceReference) {
+ String serviceCompletePID = (String)currentConverterServiceReference.getProperty("service.pid");
+
+ /*
+ * Converter name is placed in the last block of service.pid. This is used
+ * to extract it.
+ * */
+ int startIndexForConverterName = serviceCompletePID.lastIndexOf(".") + 1;
+ String serviceShortPID = serviceCompletePID.substring(startIndexForConverterName);
+
+ /*
+ * Build the actual edge tuple.
+ * */
+ Edge edge = new Edge();
+ edge.source = sourceNodeID;
+ edge.target = targetNodeID;
+ edge.serviceShortPID = serviceShortPID;
+ edge.serviceCompletePID = serviceCompletePID;
+
+ edges.add(edge);
+ }
+
+}
Added: 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 (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphOutputGenerator.java 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,62 @@
+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;
+ }
+}
Added: 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 (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Edge.java 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,8 @@
+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
Added: 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 (rev 0)
+++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/Node.java 2009-07-24 18:09:35 UTC (rev 900)
@@ -0,0 +1,13 @@
+/**
+ *
+ */
+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.
|