use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterVNA method addEdge.
private void addEdge(String[] edgeData) {
NodeDraft sourceNode;
if (!container.nodeExists(edgeData[0])) {
sourceNode = container.factory().newNodeDraft(edgeData[0]);
container.addNode(sourceNode);
} else {
sourceNode = container.getNode(edgeData[0]);
}
NodeDraft targetNode;
if (!container.nodeExists(edgeData[1])) {
targetNode = container.factory().newNodeDraft(edgeData[1]);
container.addNode(targetNode);
} else {
targetNode = container.getNode(edgeData[1]);
}
EdgeDraft edge = container.factory().newEdgeDraft();
edge.setSource(sourceNode);
edge.setTarget(targetNode);
int i = 0;
try {
for (i = 2; i < edgeData.length; i++) {
switch(tieAttributes[i]) {
case EDGE_STRENGTH:
float weight = Float.parseFloat(edgeData[i]);
if (edgeWidthFunction != null) {
weight = edgeWidthFunction.computeTransformation(weight);
}
edge.setWeight(weight);
break;
case OTHER:
edge.parseAndSetValue(tieDataColumns[i].getId(), edgeData[i]);
break;
}
}
} catch (NumberFormatException e) {
report.logIssue(new Issue("Error parsing numerical value at '" + edgeData[i] + "'.", Issue.Level.WARNING));
}
container.addEdge(edge);
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterVNA method addNodeProperties.
private void addNodeProperties(String[] nodeProperties) {
NodeDraft node;
String id = nodeProperties[0];
if (!container.nodeExists(id)) {
node = container.factory().newNodeDraft(id);
container.addNode(node);
} else {
node = container.getNode(id);
}
int i = 0;
try {
for (i = 1; i < nodeProperties.length; i++) {
switch(nodeDataAttributes[i]) {
case NODE_X:
node.setX(Float.parseFloat(nodeProperties[i]));
break;
case NODE_Y:
node.setY(Float.parseFloat(nodeProperties[i]));
break;
case NODE_COLOR:
node.setColor(nodeProperties[i]);
break;
case NODE_SIZE:
node.setSize(Float.parseFloat(nodeProperties[i]));
break;
case NODE_SHORT_LABEL:
node.setLabel(nodeProperties[i]);
break;
}
}
} catch (NumberFormatException e) {
report.logIssue(new Issue("Error parsing numerical value at '" + nodeProperties[i] + "'.", Issue.Level.WARNING));
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterEdgeList method getNodes.
private void getNodes(Connection connection) throws SQLException {
//Factory
ElementDraft.Factory factory = container.factory();
//Properties
PropertiesAssociations properties = database.getPropertiesAssociations();
Statement s = connection.createStatement();
ResultSet rs = null;
try {
rs = s.executeQuery(database.getNodeQuery());
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to execute Node query", Issue.Level.SEVERE, ex));
return;
}
findNodeAttributesColumns(rs);
ResultSetMetaData metaData = rs.getMetaData();
int columnsCount = metaData.getColumnCount();
while (rs.next()) {
String id = null;
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
NodeProperties p = properties.getNodeProperty(columnName);
if (p != null && p.equals(NodeProperties.ID)) {
String ide = rs.getString(i + 1);
if (ide != null) {
id = ide;
}
}
}
NodeDraft node;
if (id != null) {
node = factory.newNodeDraft(id);
} else {
node = factory.newNodeDraft();
}
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
NodeProperties p = properties.getNodeProperty(columnName);
if (p != null) {
injectNodeProperty(p, rs, i + 1, node);
} else {
//Inject node attributes
ColumnDraft col = container.getNodeColumn(columnName);
injectElementAttribute(rs, i + 1, col, node);
}
}
injectTimeIntervalProperty(node);
container.addNode(node);
}
rs.close();
s.close();
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterEdgeList method injectElementAttribute.
private void injectElementAttribute(ResultSet rs, int columnIndex, ColumnDraft column, ElementDraft draft) {
String elementName;
if (draft instanceof NodeDraft) {
elementName = "node";
} else {
elementName = "edge";
}
Class typeClass = column.getTypeClass();
if (typeClass.equals(Boolean.class)) {
try {
boolean val = rs.getBoolean(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a BOOLEAN value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else if (typeClass.equals(Double.class)) {
try {
double val = rs.getDouble(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a DOUBLE value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else if (typeClass.equals(Float.class)) {
try {
float val = rs.getFloat(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a FLOAT value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else if (typeClass.equals(Integer.class)) {
try {
int val = rs.getInt(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a INT value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else if (typeClass.equals(Long.class)) {
try {
long val = rs.getLong(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a LONG value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else if (typeClass.equals(Short.class)) {
try {
short val = rs.getShort(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a SHORT value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else if (typeClass.equals(Byte.class)) {
try {
byte val = rs.getByte(columnIndex);
draft.setValue(column.getId(), val);
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a BYTE value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
} else {
try {
String val = rs.getString(columnIndex);
if (val != null) {
draft.setValue(column.getId(), val);
} else {
report.logIssue(new Issue("Failed to get a STRING value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.WARNING));
}
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to get a STRING value for " + elementName + " attribute '" + column.getId() + "'", Issue.Level.SEVERE, ex));
}
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterPajek method readVertex.
private void readVertex(String curLine, int num_vertices) throws Exception {
String[] parts = null;
// index of first coordinate in parts; -1 indicates no coordinates found
int firstParts = -1;
String index;
String label = null;
// if there are quote marks on this line, split on them; label is surrounded by them
if (curLine.indexOf('"') != -1) {
String[] initial_split = curLine.trim().split("\"");
// if there are any quote marks, there should be exactly 2
if (initial_split.length < 1 || initial_split.length > 3) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat3", lineReader.getLineNumber()), Issue.Level.SEVERE));
}
index = initial_split[0].trim();
if (initial_split.length > 1) {
label = initial_split[1].trim();
}
if (initial_split.length == 3) {
parts = initial_split[2].trim().split("\\s+", -1);
}
firstParts = 0;
} else // no quote marks, but are there coordinates?
{
parts = curLine.trim().split("\\s+", -1);
index = parts[0];
switch(parts.length) {
case // just the ID; nothing to do, continue
1:
break;
case // just the ID and a label
2:
label = parts[1];
break;
case // ID, no label, coordinates
3:
firstParts = 1;
break;
case // ID, label, (x,y) coordinates
4:
firstParts = 2;
break;
}
}
// go from 1-based to 0-based index
int v_id = Integer.parseInt(index) - 1;
if (v_id >= num_vertices || v_id < 0) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat4", v_id, num_vertices), Issue.Level.SEVERE));
}
NodeDraft node = verticesArray[v_id];
// only attach the label if there's one to attach
if (label != null && label.length() > 0) {
node.setLabel(label);
}
// parse the rest of the line
if (firstParts != -1 && parts != null && parts.length >= firstParts + 2) {
int i = firstParts;
//Coordinates
if (i < parts.length - 1) {
try {
float x = Float.parseFloat(parts[i]);
float y = Float.parseFloat(parts[i + 1]);
node.setX(x);
node.setY(y);
i++;
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat5", lineReader.getLineNumber()), Issue.Level.WARNING));
}
}
//Size
if (i < parts.length - 1) {
try {
float size = Float.parseFloat(parts[i]);
node.setSize(size);
i++;
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat6", lineReader.getLineNumber()), Issue.Level.WARNING));
}
}
// parse colors
for (; i < parts.length - 1; i++) {
// node's internal color
if ("ic".equals(parts[i])) {
// remove spaces from color's name so we can look it up
String colorName = parts[i + 1].replaceAll(" ", "");
node.setColor(colorName);
break;
}
}
}
}
Aggregations