Search in sources :

Example 1 with NodeDraft

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

the class ImporterPajek method readArcsOrEdges.

private String readArcsOrEdges(String curLine, BufferedReader br) throws Exception {
    String nextLine = curLine;
    boolean reading_arcs = false;
    boolean reading_edges = false;
    if (nextLine.toLowerCase().startsWith("*arcs")) {
        reading_arcs = true;
    } else if (nextLine.toLowerCase().startsWith("*edges")) {
        reading_edges = true;
    }
    if (!(reading_arcs || reading_edges)) {
        return nextLine;
    }
    boolean is_list = false;
    if (nextLine.toLowerCase().endsWith("list")) {
        is_list = true;
    }
    while (br.ready()) {
        if (cancel) {
            return nextLine;
        }
        nextLine = br.readLine();
        if (nextLine == null || nextLine.startsWith("*")) {
            break;
        }
        if (nextLine.equals("")) {
            // skip blank lines
            report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat2", lineReader.getLineNumber()), Issue.Level.WARNING));
            continue;
        }
        StringTokenizer st = new StringTokenizer(nextLine.trim());
        int vid1 = Integer.parseInt(st.nextToken()) - 1;
        NodeDraft nodeFrom = verticesArray[vid1];
        if (// one source, multiple destinations
        is_list) {
            do {
                int vid2 = Integer.parseInt(st.nextToken()) - 1;
                NodeDraft nodeTo = verticesArray[vid2];
                EdgeDraft edge = container.factory().newEdgeDraft();
                edge.setSource(nodeFrom);
                edge.setTarget(nodeTo);
                container.addEdge(edge);
            } while (st.hasMoreTokens());
        } else // one source, one destination, at most one weight
        {
            int vid2 = Integer.parseInt(st.nextToken()) - 1;
            NodeDraft nodeTo = verticesArray[vid2];
            EdgeDraft edge = container.factory().newEdgeDraft();
            edge.setSource(nodeFrom);
            edge.setTarget(nodeTo);
            // get the edge weight if we care
            if (st.hasMoreTokens()) {
                double edgeWeight = 1.0;
                try {
                    edgeWeight = new Double(st.nextToken());
                } catch (Exception e) {
                    report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat7", lineReader.getLineNumber()), Issue.Level.WARNING));
                }
                edge.setWeight(edgeWeight);
            }
            container.addEdge(edge);
        }
    }
    return nextLine;
}
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 2 with NodeDraft

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

the class ImporterDL method readLabels.

private void readLabels(String labels) {
    StringTokenizer labelkonizer = new StringTokenizer(labels, ",");
    // check that there are the right number of labels
    if (labelkonizer.countTokens() != numNodes) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_labelscount", labelkonizer.countTokens(), numNodes), Issue.Level.SEVERE));
    }
    int nodeCount = 0;
    while (labelkonizer.hasMoreTokens()) {
        String label = labelkonizer.nextToken();
        nodeCount++;
        NodeDraft nodeDraft = container.factory().newNodeDraft("" + nodeCount);
        nodeDraft.setLabel(label);
        container.addNode(nodeDraft);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Issue(org.gephi.io.importer.api.Issue) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 3 with NodeDraft

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

the class ImporterDOT method stmt.

protected void stmt(StreamTokenizer streamTokenizer) throws Exception {
    if (streamTokenizer.sval == null || streamTokenizer.sval.equalsIgnoreCase("graph") || streamTokenizer.sval.equalsIgnoreCase("node") || streamTokenizer.sval.equalsIgnoreCase("edge")) {
    } else {
        String nodeId = nodeID(streamTokenizer);
        streamTokenizer.nextToken();
        if (streamTokenizer.ttype == '-') {
            NodeDraft nodeDraft = getOrCreateNode(nodeId);
            edgeStructure(streamTokenizer, nodeDraft);
        } else if (streamTokenizer.ttype == '[') {
            NodeDraft nodeDraft = getOrCreateNode(nodeId);
            nodeAttributes(streamTokenizer, nodeDraft);
        } else {
            getOrCreateNode(nodeId);
            streamTokenizer.pushBack();
        }
    }
}
Also used : NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 4 with NodeDraft

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

the class ImporterCSV method addNode.

private void addNode(String id, String label) {
    NodeDraft node;
    if (!container.nodeExists(id)) {
        node = container.factory().newNodeDraft(id);
        node.setLabel(label);
        container.addNode(node);
    }
}
Also used : NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 5 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft 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)

Aggregations

NodeDraft (org.gephi.io.importer.api.NodeDraft)36 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)17 Issue (org.gephi.io.importer.api.Issue)15 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 Map (java.util.Map)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