Search in sources :

Example 16 with EdgeDraft

use of org.gephi.io.importer.api.EdgeDraft in project gephi by gephi.

the class ImporterTGF method addEdge.

private void addEdge(String source, String target, String label) {
    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);
    }
    if (!container.edgeExists(sourceNode.getId(), targetNode.getId())) {
        EdgeDraft edge = container.factory().newEdgeDraft();
        edge.setSource(sourceNode);
        edge.setTarget(targetNode);
        edge.setLabel(label);
        container.addEdge(edge);
    }
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 17 with EdgeDraft

use of org.gephi.io.importer.api.EdgeDraft in project gephi by gephi.

the class ImporterTLP method parseEdge.

private void parseEdge(String[] tokens, int cptLine) {
    if (tokens.length != 4) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerTPL_error_dataformat1", cptLine), Issue.Level.WARNING));
    }
    String id = tokens[1];
    EdgeDraft edge = container.factory().newEdgeDraft(id);
    NodeDraft source = container.getNode(tokens[2]);
    NodeDraft target = container.getNode(tokens[3]);
    edge.setSource(source);
    edge.setTarget(target);
    container.addEdge(edge);
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Issue(org.gephi.io.importer.api.Issue) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 18 with EdgeDraft

use of org.gephi.io.importer.api.EdgeDraft in project gephi by gephi.

the class ImporterVNA method addEdge.

private void addEdge(String[] edgeData) {
    NodeDraft sourceNode;
    if (!container.nodeExists(edgeData[0])) {
        sourceNode = container.factory().newNodeDraft(edgeData[0]);
        container.addNode(sourceNode);
    } else {
        sourceNode = container.getNode(edgeData[0]);
    }
    NodeDraft targetNode;
    if (!container.nodeExists(edgeData[1])) {
        targetNode = container.factory().newNodeDraft(edgeData[1]);
        container.addNode(targetNode);
    } else {
        targetNode = container.getNode(edgeData[1]);
    }
    EdgeDraft edge = container.factory().newEdgeDraft();
    edge.setSource(sourceNode);
    edge.setTarget(targetNode);
    int i = 0;
    try {
        for (i = 2; i < edgeData.length; i++) {
            switch(tieAttributes[i]) {
                case EDGE_STRENGTH:
                    float weight = Float.parseFloat(edgeData[i]);
                    if (edgeWidthFunction != null) {
                        weight = edgeWidthFunction.computeTransformation(weight);
                    }
                    edge.setWeight(weight);
                    break;
                case OTHER:
                    edge.parseAndSetValue(tieDataColumns[i].getId(), edgeData[i]);
                    break;
            }
        }
    } catch (NumberFormatException e) {
        report.logIssue(new Issue("Error parsing numerical value at '" + edgeData[i] + "'.", Issue.Level.WARNING));
    }
    container.addEdge(edge);
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Issue(org.gephi.io.importer.api.Issue) 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