use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterPajek method readArcsOrEdges.
private String readArcsOrEdges(String curLine, BufferedReader br) throws Exception {
String nextLine = curLine;
boolean reading_arcs = false;
boolean reading_edges = false;
if (nextLine.toLowerCase().startsWith("*arcs")) {
reading_arcs = true;
} else if (nextLine.toLowerCase().startsWith("*edges")) {
reading_edges = true;
}
if (!(reading_arcs || reading_edges)) {
return nextLine;
}
boolean is_list = false;
if (nextLine.toLowerCase().endsWith("list")) {
is_list = true;
}
while (br.ready()) {
if (cancel) {
return nextLine;
}
nextLine = br.readLine();
if (nextLine == null || nextLine.startsWith("*")) {
break;
}
if (nextLine.equals("")) {
// skip blank lines
report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat2", lineReader.getLineNumber()), Issue.Level.WARNING));
continue;
}
StringTokenizer st = new StringTokenizer(nextLine.trim());
int vid1 = Integer.parseInt(st.nextToken()) - 1;
NodeDraft nodeFrom = verticesArray[vid1];
if (// one source, multiple destinations
is_list) {
do {
int vid2 = Integer.parseInt(st.nextToken()) - 1;
NodeDraft nodeTo = verticesArray[vid2];
EdgeDraft edge = container.factory().newEdgeDraft();
edge.setSource(nodeFrom);
edge.setTarget(nodeTo);
container.addEdge(edge);
} while (st.hasMoreTokens());
} else // one source, one destination, at most one weight
{
int vid2 = Integer.parseInt(st.nextToken()) - 1;
NodeDraft nodeTo = verticesArray[vid2];
EdgeDraft edge = container.factory().newEdgeDraft();
edge.setSource(nodeFrom);
edge.setTarget(nodeTo);
// get the edge weight if we care
if (st.hasMoreTokens()) {
double edgeWeight = 1.0;
try {
edgeWeight = new Double(st.nextToken());
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat7", lineReader.getLineNumber()), Issue.Level.WARNING));
}
edge.setWeight(edgeWeight);
}
container.addEdge(edge);
}
}
return nextLine;
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterDL method readLabels.
private void readLabels(String labels) {
StringTokenizer labelkonizer = new StringTokenizer(labels, ",");
// check that there are the right number of labels
if (labelkonizer.countTokens() != numNodes) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_labelscount", labelkonizer.countTokens(), numNodes), Issue.Level.SEVERE));
}
int nodeCount = 0;
while (labelkonizer.hasMoreTokens()) {
String label = labelkonizer.nextToken();
nodeCount++;
NodeDraft nodeDraft = container.factory().newNodeDraft("" + nodeCount);
nodeDraft.setLabel(label);
container.addNode(nodeDraft);
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterDOT method stmt.
protected void stmt(StreamTokenizer streamTokenizer) throws Exception {
if (streamTokenizer.sval == null || streamTokenizer.sval.equalsIgnoreCase("graph") || streamTokenizer.sval.equalsIgnoreCase("node") || streamTokenizer.sval.equalsIgnoreCase("edge")) {
} else {
String nodeId = nodeID(streamTokenizer);
streamTokenizer.nextToken();
if (streamTokenizer.ttype == '-') {
NodeDraft nodeDraft = getOrCreateNode(nodeId);
edgeStructure(streamTokenizer, nodeDraft);
} else if (streamTokenizer.ttype == '[') {
NodeDraft nodeDraft = getOrCreateNode(nodeId);
nodeAttributes(streamTokenizer, nodeDraft);
} else {
getOrCreateNode(nodeId);
streamTokenizer.pushBack();
}
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterCSV method addNode.
private void addNode(String id, String label) {
NodeDraft node;
if (!container.nodeExists(id)) {
node = container.factory().newNodeDraft(id);
node.setLabel(label);
container.addNode(node);
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterCSV method addEdge.
private void addEdge(String source, String target, float weight) {
NodeDraft sourceNode;
if (!container.nodeExists(source)) {
sourceNode = container.factory().newNodeDraft(source);
container.addNode(sourceNode);
} else {
sourceNode = container.getNode(source);
}
NodeDraft targetNode;
if (!container.nodeExists(target)) {
targetNode = container.factory().newNodeDraft(target);
container.addNode(targetNode);
} else {
targetNode = container.getNode(target);
}
EdgeDraft edge = container.factory().newEdgeDraft();
edge.setSource(sourceNode);
edge.setTarget(targetNode);
edge.setWeight(weight);
container.addEdge(edge);
}
Aggregations