Skip to content

Commit

Permalink
bug fix suggested by WAH Spekkink
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Levallois committed Mar 11, 2014
1 parent c9bbe5c commit d13f541
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 63 deletions.
7 changes: 4 additions & 3 deletions ExcelCsvImporter/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Manifest-Version: 1.1.1
AutoUpdate-Show-In-Client: true
OpenIDE-Module: ExcelCsvImporter
OpenIDE-Module: ExcelCsvImporter/1
OpenIDE-Module-Implementation-Version: 1
OpenIDE-Module-Localizing-Bundle: ExcelCsvImporter/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0
OpenIDE-Module-Specification-Version: 1

Binary file modified ExcelCsvImporter/private/ExcelTest.xlsx
Binary file not shown.
5 changes: 4 additions & 1 deletion ExcelCsvImporter/src/ExcelCsvImporter/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ OpenIDE-Module-Long-Description=\
<h2>Convert Excel and csv files to networks</h2>\n\nThis plugin helps you import Excel files and csv files into Gephi, by transforming them into networks.\
<br>\nIt takes the rows of your file and let you define which relations should be found in it.\
<br>\n\nPlease post issues and ask for feature request on <a href="https://github.com/seinecle/My-Plugins-for-Gephi">Github</a>.\
<br>\n\nOr contact me (Clement Levallois) via Twitter @seinecle.
<br>\n\nOr contact me (Clement Levallois) via Twitter @seinecle.\n\n\n\
<b>Release History:</b>\n\nVersion 1.1.1 (March 2014)\n-> Bug fix (suggested by Wouters A.H. \
Spekkink)\nSame names in different columns of the Excel of csv files are now correctly analyzed.\n\n\
Version 1.0 (October 2014)\n-> Initial release.
OpenIDE-Module-Name=Convert Excel and csv files to networks
OpenIDE-Module-Short-Description=Converts Excel files and csv files into networks
Panel1.jButtonSelectFile.text=select file
Expand Down
75 changes: 44 additions & 31 deletions ExcelCsvImporter/src/Parsers/CsvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class CsvParser {
public CsvReader csvReader;
String textDelimiter;
String fieldDelimiter;
Multiset<String> nodes = HashMultiset.create();
Multiset<String> nodesFirst = HashMultiset.create();
Multiset<String> nodesSecond = HashMultiset.create();
Multiset<String> edges = HashMultiset.create();
Expand Down Expand Up @@ -117,9 +118,7 @@ public final void init() {

} catch (FileNotFoundException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}

public String[] getHeaders() throws IOException {
Expand Down Expand Up @@ -181,15 +180,16 @@ public void convertToNetwork() throws IOException {
String[] firstAgentSplit;
String[] secondAgentSplit;


if (firstDelimiter != null) {
firstAgentSplit = firstAgent.trim().split(firstDelimiter);
} else {
firstAgentSplit = new String[1];
firstAgentSplit[0] = firstAgent;
}
for (String node : firstAgentSplit) {
nodesFirst.add(node.trim());
node = node.trim();
nodesFirst.add(node);
nodes.add(node);
}

if (!oneTypeOfAgent) {
Expand All @@ -201,56 +201,69 @@ public void convertToNetwork() throws IOException {
secondAgentSplit[0] = secondAgent;
}
for (String node : secondAgentSplit) {
nodesSecond.add(node.trim());
node = node.trim();
nodesSecond.add(node);
nodes.add(node);
}
} else {
secondAgentSplit = null;
}

String[] both = ArrayUtils.addAll(firstAgentSplit, secondAgentSplit);
//let's find all connections between all the tags for this picture
//let's find all connections between all the agents in this row
Utils usefulTools = new Utils();
List<String> connections = usefulTools.getListOfLinks(both,MyFileImporter.removeSelfLoops);
edges.addAll(connections);
}

if (!MyFileImporter.innerLinksIncluded) {
for (String x : firstAgentSplit) {
for (String xx : secondAgentSplit) {
if (!(MyFileImporter.removeSelfLoops & x.equals(xx))) {
edges.add(x.trim() + "|" + xx.trim());
}
}
}
} else {
List<String> connections;
String[] both = ArrayUtils.addAll(firstAgentSplit, secondAgentSplit);
connections = usefulTools.getListOfLinks(both, MyFileImporter.removeSelfLoops);
edges.addAll(connections);
}

}

NodeDraft node;
AttributeTable atNodes = container.getAttributeModel().getNodeTable();
AttributeColumn acFrequency = atNodes.addColumn("frequency", AttributeType.INT);
AttributeColumn acType = atNodes.addColumn("type", AttributeType.STRING);

for (String n : nodesFirst.elementSet()) {
StringBuilder type;
boolean atLeastOneType = false;

for (String n : nodes.elementSet()) {
node = container.factory().newNodeDraft();
node.setId(n);
node.setLabel(n);
node.addAttributeValue(acFrequency, nodesFirst.count(n));
node.addAttributeValue(acType, MyFileImporter.getFirstConnectedAgent());
container.addNode(node);
}

for (String n : nodesSecond.elementSet()) {
node = container.factory().newNodeDraft();
node.setId(n);
node.setLabel(n);
node.addAttributeValue(acFrequency, nodesSecond.count(n));
node.addAttributeValue(acType, MyFileImporter.getSecondConnectedAgent());
type = new StringBuilder();
node.addAttributeValue(acFrequency, nodes.count(n));
if (nodesFirst.contains(n)) {
type.append(MyFileImporter.getFirstConnectedAgent());
atLeastOneType = true;
}
if (nodesSecond.contains(n)) {
if (atLeastOneType) {
type.append("; ");
}
type.append(MyFileImporter.getSecondConnectedAgent());
}
node.addAttributeValue(acType, type);
container.addNode(node);
}
}

//loop for edges
Integer idEdge = 0;
EdgeDraft edge;
for (String e : edges.elementSet()) {
System.out.println("edge: " + e);

String sourceNode = e.split("\\|")[0].trim();
String targetNode = e.split("\\|")[1].trim();
if (!MyFileImporter.innerLinksIncluded) {
if ((nodesFirst.contains(sourceNode) & nodesFirst.contains(targetNode)) || (nodesSecond.contains(sourceNode) & nodesSecond.contains(targetNode))) {
continue;
}
}

edge = container.factory().newEdgeDraft();
idEdge = idEdge + 1;
edge.setSource(container.getNode(sourceNode));
Expand Down
69 changes: 41 additions & 28 deletions ExcelCsvImporter/src/Parsers/ExcelParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class ExcelParser {
String sheetName;
boolean headersPresent;
Integer columnCount;
Multiset<String> nodes = HashMultiset.create();
Multiset<String> nodesFirst = HashMultiset.create();
Multiset<String> nodesSecond = HashMultiset.create();
Multiset<String> edges = HashMultiset.create();
Expand Down Expand Up @@ -205,22 +206,22 @@ public void convertToNetwork() throws IOException, InvalidFormatException {
}
}


}
lineCounter++;

String[] firstAgentSplit;
String[] secondAgentSplit;


if (firstDelimiter != null) {
firstAgentSplit = firstAgent.trim().split(firstDelimiter);
} else {
firstAgentSplit = new String[1];
firstAgentSplit[0] = firstAgent;
}
for (String node : firstAgentSplit) {
nodesFirst.add(node.trim());
node = node.trim();
nodesFirst.add(node);
nodes.add(node);
}

if (!oneTypeOfAgent) {
Expand All @@ -232,56 +233,68 @@ public void convertToNetwork() throws IOException, InvalidFormatException {
secondAgentSplit[0] = secondAgent;
}
for (String node : secondAgentSplit) {
nodesSecond.add(node.trim());
node = node.trim();
nodesSecond.add(node);
nodes.add(node);
}
} else {
secondAgentSplit = null;
}

String[] both = ArrayUtils.addAll(firstAgentSplit, secondAgentSplit);
//let's find all connections between all the tags for this picture
//let's find all connections between all the agents in this row
Utils usefulTools = new Utils();
List<String> connections = usefulTools.getListOfLinks(both,MyFileImporter.removeSelfLoops);
edges.addAll(connections);
}

if (!MyFileImporter.innerLinksIncluded) {
for (String x : firstAgentSplit) {
for (String xx : secondAgentSplit) {
if (!(MyFileImporter.removeSelfLoops & x.equals(xx))) {
edges.add(x.trim() + "|" + xx.trim());
}
}
}
} else {
List<String> connections;
String[] both = ArrayUtils.addAll(firstAgentSplit, secondAgentSplit);
connections = usefulTools.getListOfLinks(both, MyFileImporter.removeSelfLoops);
edges.addAll(connections);
}
}

NodeDraft node;
AttributeTable atNodes = container.getAttributeModel().getNodeTable();
AttributeColumn acFrequency = atNodes.addColumn("frequency", AttributeType.INT);
AttributeColumn acType = atNodes.addColumn("type", AttributeType.STRING);
StringBuilder type;
boolean atLeastOneType = false;

for (String n : nodesFirst.elementSet()) {
for (String n : nodes.elementSet()) {
type = new StringBuilder();
node = container.factory().newNodeDraft();
node.setId(n);
node.setLabel(n);
node.addAttributeValue(acFrequency, nodesFirst.count(n));
node.addAttributeValue(acType, MyFileImporter.getFirstConnectedAgent());
container.addNode(node);
}

for (String n : nodesSecond.elementSet()) {
node = container.factory().newNodeDraft();
node.setId(n);
node.setLabel(n);
node.addAttributeValue(acFrequency, nodesSecond.count(n));
node.addAttributeValue(acType, MyFileImporter.getSecondConnectedAgent());
node.addAttributeValue(acFrequency, nodes.count(n));
if (nodesFirst.contains(n)) {
type.append(MyFileImporter.getFirstConnectedAgent());
atLeastOneType = true;
}
if (nodesSecond.contains(n)) {
if (atLeastOneType) {
type.append("; ");
}
type.append(MyFileImporter.getSecondConnectedAgent());
}
node.addAttributeValue(acType, type);
container.addNode(node);
}
}

//loop for edges
Integer idEdge = 0;
EdgeDraft edge;
for (String e : edges.elementSet()) {
System.out.println("edge: " + e);
// System.out.println("edge: " + e);

String sourceNode = e.split("\\|")[0];
String targetNode = e.split("\\|")[1];
if (!MyFileImporter.innerLinksIncluded) {
if ((nodesFirst.contains(sourceNode) & nodesFirst.contains(targetNode)) || (nodesSecond.contains(sourceNode) & nodesSecond.contains(targetNode))) {
continue;
}
}
edge = container.factory().newEdgeDraft();
idEdge = idEdge + 1;
edge.setSource(container.getNode(sourceNode));
Expand Down
1 change: 1 addition & 0 deletions ExcelCsvImporter/src/Wizard/Panel5Wizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void removeChangeListener(ChangeListener cl) {
public void readSettings(WizardDescriptor data) {
((Panel5) getComponent()).jLabel3.setText(MyFileImporter.getFirstConnectedAgent());
((Panel5) getComponent()).jLabel5.setText(MyFileImporter.getSecondConnectedAgent());
MyFileImporter.innerLinksIncluded = Panel4.jCheckBoxInnerLinks.isSelected();

}

Expand Down

0 comments on commit d13f541

Please sign in to comment.