use of org.gephi.io.importer.api.EdgeDraft 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);
}
use of org.gephi.io.importer.api.EdgeDraft in project gephi by gephi.
the class ImporterDL method readEdgelistRow.
private void readEdgelistRow(String row, int pointer, double startTime, double endTime) {
StringTokenizer rowkonizer = new StringTokenizer(row);
if (!rowkonizer.hasMoreTokens()) {
return;
}
// should have three entries, int from, int to, weight
String from = rowkonizer.nextToken();
if (!rowkonizer.hasMoreTokens()) {
return;
}
String to = rowkonizer.nextToken();
double weight = 1.0;
if (rowkonizer.hasMoreTokens()) {
String weightParse = rowkonizer.nextToken();
try {
weight = Double.parseDouble(weightParse);
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_edgeparseweight", weightParse, getLineNumber(pointer)), Issue.Level.WARNING));
}
}
NodeDraft sourceNode = container.getNode(from);
NodeDraft targetNode = container.getNode(to);
EdgeDraft edgeDraft = container.factory().newEdgeDraft();
edgeDraft.setSource(sourceNode);
edgeDraft.setTarget(targetNode);
edgeDraft.setWeight((float) weight);
container.addEdge(edgeDraft);
}
use of org.gephi.io.importer.api.EdgeDraft in project gephi by gephi.
the class ImporterDL method readMatrixRow.
private void readMatrixRow(String line, int pointer, int row, int startTime, int endTime) {
StringTokenizer rowkonizer = new StringTokenizer(line, " ");
int from = row + 1;
int to = 1;
double weight = 0;
while (rowkonizer.hasMoreTokens()) {
String toParse = (String) rowkonizer.nextToken();
if (to > numNodes) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_matrixentriescount", row, startTime, getLineNumber(pointer)), Issue.Level.SEVERE));
}
try {
weight = Double.parseDouble(toParse);
} catch (Exception e) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_weightparseerror", toParse, startTime, getLineNumber(pointer)), Issue.Level.SEVERE));
}
if (weight != 0) {
NodeDraft sourceNode = container.getNode("" + from);
NodeDraft targetNode = container.getNode("" + to);
EdgeDraft edgeDraft = container.factory().newEdgeDraft();
edgeDraft.setSource(sourceNode);
edgeDraft.setTarget(targetNode);
edgeDraft.setWeight((float) weight);
container.addEdge(edgeDraft);
}
to++;
}
}
use of org.gephi.io.importer.api.EdgeDraft in project gephi by gephi.
the class DynamicGraph method generate.
@Override
public void generate(ContainerLoader container) {
Random random = new Random();
double start = 2000.0;
double end = 2015.0;
double tick = 1.0;
ColumnDraft col = container.addNodeColumn("score", Integer.class, true);
container.setTimeRepresentation(TimeRepresentation.TIMESTAMP);
NodeDraft[] nodeArray = new NodeDraft[numberOfNodes];
for (int i = 0; i < numberOfNodes; i++) {
NodeDraft nodeDraft = container.factory().newNodeDraft("n" + i);
container.addNode(nodeDraft);
Random r = new Random();
for (double t = start; t < end; t += tick) {
if (r.nextBoolean()) {
nodeDraft.addTimestamp(t);
nodeDraft.setValue(col.getId(), r.nextInt(5), t);
}
}
nodeArray[i] = nodeDraft;
}
if (wiringProbability > 0) {
for (int i = 0; i < numberOfNodes - 1; i++) {
NodeDraft node1 = nodeArray[i];
for (int j = i + 1; j < numberOfNodes; j++) {
NodeDraft node2 = nodeArray[j];
if (random.nextDouble() < wiringProbability) {
EdgeDraft edgeDraft = container.factory().newEdgeDraft();
edgeDraft.setSource(node1);
edgeDraft.setTarget(node2);
Random r = new Random();
// DynamicFloat dynamicWeight = new DynamicFloat(new Interval<Float>(2010, 2012, false, true, new Float(r.nextInt(3) + 1)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2012, 2014, false, true, new Float(r.nextInt(3) + 2)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2014, 2016, false, true, new Float(r.nextInt(3) + 3)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2016, 2018, false, true, new Float(r.nextInt(3) + 4)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2018, 2020, false, true, new Float(r.nextInt(3) + 5)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2020, 2022, false, true, new Float(r.nextInt(3) + 6)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2022, 2024, false, true, new Float(r.nextInt(3) + 7)));
// dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2024, 2026, false, false, new Float(r.nextInt(3) + 8)));
// edgeDraft.addAttributeValue(weightCol, dynamicWeight);
container.addEdge(edgeDraft);
}
}
}
}
}
use of org.gephi.io.importer.api.EdgeDraft in project gephi-plugins-bootcamp by gephi.
the class SimpleGenerator method generate.
@Override
public void generate(ContainerLoader container) {
// create nodes
NodeDraft n1 = container.factory().newNodeDraft();
NodeDraft n2 = container.factory().newNodeDraft();
// set node labels
n1.setLabel("Hello");
n2.setLabel("World");
// create edge
EdgeDraft e = container.factory().newEdgeDraft();
e.setSource(n1);
e.setTarget(n2);
// fill in the graph
container.addNode(n1);
container.addNode(n2);
container.addEdge(e);
}
Aggregations