use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterTLP method parseNodes.
private void parseNodes(String[] tokens) {
for (int i = 1; i < tokens.length; i++) {
String id = tokens[i];
NodeDraft node = container.factory().newNodeDraft(id);
container.addNode(node);
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterVNA method addNode.
private void addNode(String[] nodeData) {
NodeDraft node;
String id = nodeData[0];
if (!container.nodeExists(id)) {
node = container.factory().newNodeDraft(id);
container.addNode(node);
} else {
node = container.getNode(id);
}
for (int i = 1; i < nodeDataColumns.length; i++) {
node.parseAndSetValue(nodeDataColumns[i].getId(), nodeData[i]);
}
}
use of org.gephi.io.importer.api.NodeDraft in project gephi-plugins-bootcamp by gephi.
the class InitalPositionProcessor method process.
@Override
public void process() {
if (containers.length > 1) {
throw new RuntimeException("This processor can only handle single containers");
}
ContainerUnloader container = containers[0];
long hash = 0;
//Calculate the hash of the current graph
for (NodeDraft nodeDraft : container.getNodes()) {
String id = nodeDraft.getId();
hash += id.hashCode();
}
//Create a random with this seed
Random random = new Random(hash);
for (NodeDraft nodeDraft : container.getNodes()) {
nodeDraft.setX((float) ((0.01 + random.nextDouble()) * 1000) - 500);
nodeDraft.setY((float) ((0.01 + random.nextDouble()) * 1000) - 500);
}
//Call default processor
super.process();
}
use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.
the class ImporterEdgeList method injectEdgeProperty.
private void injectEdgeProperty(EdgeProperties p, ResultSet rs, int column, EdgeDraft edgeDraft) throws SQLException {
switch(p) {
case LABEL:
String label = rs.getString(column);
if (label != null) {
edgeDraft.setLabel(label);
}
break;
case SOURCE:
String source = rs.getString(column);
if (source != null && !source.isEmpty()) {
NodeDraft sourceNode = container.getNode(source);
edgeDraft.setSource(sourceNode);
}
break;
case TARGET:
String target = rs.getString(column);
if (target != null && !target.isEmpty()) {
NodeDraft targetNode = container.getNode(target);
edgeDraft.setTarget(targetNode);
}
break;
case WEIGHT:
float weight = rs.getFloat(column);
if (weight != 0) {
edgeDraft.setWeight(weight);
}
break;
case COLOR:
String color = rs.getString(column);
if (color != null) {
String[] rgb = color.split(",");
if (rgb.length == 3) {
edgeDraft.setColor(rgb[0], rgb[1], rgb[2]);
} else {
edgeDraft.setColor(color);
}
}
break;
case START:
container.setTimeFormat(getTimeFormat(rs, column));
String start = getDateData(rs, column);
if (start != null) {
timeIntervalStart = start;
}
break;
case START_OPEN:
container.setTimeFormat(getTimeFormat(rs, column));
String startOpen = rs.getString(column);
if (startOpen != null) {
timeIntervalStart = startOpen;
}
break;
case END:
container.setTimeFormat(getTimeFormat(rs, column));
String end = rs.getString(column);
if (end != null) {
timeIntervalEnd = end;
}
break;
case END_OPEN:
container.setTimeFormat(getTimeFormat(rs, column));
String endOpen = rs.getString(column);
if (endOpen != null) {
timeIntervalEnd = endOpen;
}
break;
}
}
use of org.gephi.io.importer.api.NodeDraft 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);
}
}
}
}
}
Aggregations