Search in sources :

Example 11 with NodeDraft

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);
    }
}
Also used : NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 12 with NodeDraft

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]);
    }
}
Also used : NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 13 with NodeDraft

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();
}
Also used : ContainerUnloader(org.gephi.io.importer.api.ContainerUnloader) Random(java.util.Random) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 14 with NodeDraft

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;
    }
}
Also used : NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 15 with NodeDraft

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);
                }
            }
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Random(java.util.Random) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Aggregations

NodeDraft (org.gephi.io.importer.api.NodeDraft)31 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)15 Issue (org.gephi.io.importer.api.Issue)14 IOException (java.io.IOException)5 StringTokenizer (java.util.StringTokenizer)5 Random (java.util.Random)4 SQLException (java.sql.SQLException)2 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)2 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Edge (org.gephi.graph.api.Edge)1 Graph (org.gephi.graph.api.Graph)1 GraphController (org.gephi.graph.api.GraphController)1 GraphFactory (org.gephi.graph.api.GraphFactory)1 Node (org.gephi.graph.api.Node)1 ContainerUnloader (org.gephi.io.importer.api.ContainerUnloader)1 ElementDraft (org.gephi.io.importer.api.ElementDraft)1