Search in sources :

Example 6 with EdgeDraft

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

Example 7 with EdgeDraft

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

Example 8 with 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++;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Issue(org.gephi.io.importer.api.Issue) NodeDraft(org.gephi.io.importer.api.NodeDraft) IOException(java.io.IOException)

Example 9 with EdgeDraft

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);
                }
            }
        }
    }
}
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)

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

Aggregations

EdgeDraft (org.gephi.io.importer.api.EdgeDraft)18 NodeDraft (org.gephi.io.importer.api.NodeDraft)15 Issue (org.gephi.io.importer.api.Issue)9 IOException (java.io.IOException)3 Random (java.util.Random)3 StringTokenizer (java.util.StringTokenizer)3 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)3 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)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 TimeMap (org.gephi.graph.api.types.TimeMap)1 ElementDraft (org.gephi.io.importer.api.ElementDraft)1