Search in sources :

Example 11 with Issue

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

the class ImporterGDF method importData.

private void importData(LineNumberReader reader) throws Exception {
    //Progress
    Progress.start(progressTicket);
    //Verify a node line exists and puts nodes and edges lines in arrays
    walkFile(reader);
    //Progress
    Progress.switchToDeterminate(progressTicket, nodeLines.size() + edgeLines.size());
    //Magix regex
    Pattern pattern = Pattern.compile("(?<=(?:,|^)\")(.*?)(?=(?<=(?:[^\\\\]))\",|\"$)|(?<=(?:,|^)')(.*?)(?=(?<=(?:[^\\\\]))',|'$)|(?<=(?:,|^))(?=[^'\"])(.*?)(?=(?:,|$))|(?<=,)($)");
    //Nodes
    for (String nodeLine : nodeLines) {
        if (cancel) {
            return;
        }
        //Create Node
        NodeDraft node = null;
        Matcher m = pattern.matcher(nodeLine);
        int count = 0;
        String id = "";
        while (m.find()) {
            int start = m.start();
            int end = m.end();
            if (start != end) {
                String data = nodeLine.substring(start, end);
                data = data.trim();
                if (!data.isEmpty() && !data.toLowerCase().equals("null")) {
                    if (count == 0) {
                        //Id
                        id = data;
                        if (node == null) {
                            node = container.factory().newNodeDraft(id);
                        }
                    } else if (count - 1 < nodeColumns.length) {
                        if (nodeColumns[count - 1] != null) {
                            setNodeData(node, nodeColumns[count - 1], data);
                        }
                    } else {
                        report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat7", id), Issue.Level.SEVERE));
                    }
                }
            }
            count++;
        }
        container.addNode(node);
        //Progress
        Progress.progress(progressTicket);
    }
    //Edges
    for (String edgeLine : edgeLines) {
        if (cancel) {
            return;
        }
        //Create Edge
        EdgeDraft edge = container.factory().newEdgeDraft();
        //Default to undirected unless stated
        edge.setDirection(EdgeDirection.UNDIRECTED);
        Matcher m = pattern.matcher(edgeLine);
        int count = 0;
        String id = "";
        while (m.find()) {
            int start = m.start();
            int end = m.end();
            if (start != end) {
                String data = edgeLine.substring(start, end);
                data = data.trim();
                if (!data.isEmpty() && !data.toLowerCase().equals("null")) {
                    if (count == 0) {
                        NodeDraft nodeSource = container.getNode(data);
                        edge.setSource(nodeSource);
                        id = data;
                    } else if (count == 1) {
                        NodeDraft nodeTarget = container.getNode(data);
                        edge.setTarget(nodeTarget);
                        id += "," + data;
                    } else if (count - 2 < edgeColumns.length) {
                        if (edgeColumns[count - 2] != null) {
                            setEdgeData(edge, edgeColumns[count - 2], data);
                        }
                    } else {
                        report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat7", id), Issue.Level.SEVERE));
                    }
                }
            }
            count++;
        }
        container.addEdge(edge);
        //Progress
        Progress.progress(progressTicket);
    }
}
Also used : Pattern(java.util.regex.Pattern) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Issue(org.gephi.io.importer.api.Issue) Matcher(java.util.regex.Matcher) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 12 with Issue

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

the class ImporterEdgeList method getEdges.

private void getEdges(Connection connection) throws SQLException {
    //Factory
    ElementDraft.Factory factory = container.factory();
    //Properties
    PropertiesAssociations properties = database.getPropertiesAssociations();
    Statement s = connection.createStatement();
    ResultSet rs = null;
    try {
        rs = s.executeQuery(database.getEdgeQuery());
    } catch (SQLException ex) {
        report.logIssue(new Issue("Failed to execute Edge query", Issue.Level.SEVERE, ex));
        return;
    }
    findEdgeAttributesColumns(rs);
    ResultSetMetaData metaData = rs.getMetaData();
    int columnsCount = metaData.getColumnCount();
    while (rs.next()) {
        String id = null;
        for (int i = 0; i < columnsCount; i++) {
            String columnName = metaData.getColumnLabel(i + 1);
            EdgeProperties p = properties.getEdgeProperty(columnName);
            if (p != null && p.equals(EdgeProperties.ID)) {
                String ide = rs.getString(i + 1);
                if (ide != null) {
                    id = ide;
                }
            }
        }
        EdgeDraft edge;
        if (id != null) {
            edge = factory.newEdgeDraft(id);
        } else {
            edge = factory.newEdgeDraft();
        }
        for (int i = 0; i < columnsCount; i++) {
            String columnName = metaData.getColumnLabel(i + 1);
            EdgeProperties p = properties.getEdgeProperty(columnName);
            if (p != null) {
                injectEdgeProperty(p, rs, i + 1, edge);
            } else {
                //Inject edge attributes
                ColumnDraft col = container.getEdgeColumn(columnName);
                injectElementAttribute(rs, i + 1, col, edge);
            }
        }
        injectTimeIntervalProperty(edge);
        container.addEdge(edge);
    }
    rs.close();
    s.close();
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) SQLException(java.sql.SQLException) ElementDraft(org.gephi.io.importer.api.ElementDraft) PropertiesAssociations(org.gephi.io.importer.api.PropertiesAssociations) Statement(java.sql.Statement) ResultSetMetaData(java.sql.ResultSetMetaData) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) ResultSet(java.sql.ResultSet) EdgeProperties(org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)

Example 13 with Issue

use of org.gephi.io.importer.api.Issue 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 14 with Issue

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

the class ImporterDL method importData.

private void importData(LineNumberReader reader) throws Exception {
    //Progress
    Progress.start(progressTicket);
    List<String> lines = new ArrayList<>();
    for (; reader.ready(); ) {
        String line = reader.readLine();
        if (line != null && !line.isEmpty()) {
            lines.add(line);
        }
    }
    if (lines.isEmpty() || (!lines.get(0).startsWith("DL") && !lines.get(0).startsWith("dl"))) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_firstline"), Issue.Level.CRITICAL));
    }
    headerMap = new HashMap<>();
    readHeaderLine(lines.get(0).substring(2));
    int i = 1;
    for (; i < lines.size(); i++) {
        String line = lines.get(i).toLowerCase();
        if (line.trim().endsWith("data:") || line.trim().endsWith("labels:")) {
            break;
        } else {
            readHeaderLine(line);
        }
    }
    computeHeaders();
    if (lines.get(i).toLowerCase().trim().endsWith("labels:") && lines.size() > i + 1) {
        readLabels(lines.get(++i));
    }
    int dataLineStart = -1;
    for (; i < lines.size(); i++) {
        String line = lines.get(i).toLowerCase();
        if (line.trim().endsWith("data:")) {
            dataLineStart = i + 1;
            break;
        }
    }
    if (dataLineStart == -1) {
        report.logIssue(new Issue(NbBundle.getMessage(ImporterDL.class, "importerDL_error_nodata"), Issue.Level.SEVERE));
    } else if (lines.size() > dataLineStart) {
        dataLineStartDelta = dataLineStart + 1;
        lines = lines.subList(dataLineStart, lines.size());
        if (format.equals(Format.FULLMATRIX)) {
            readeMatrixBlock(lines);
        } else if (format.equals(Format.EDGELIST1)) {
            readEdgelistBlock(lines);
        }
    }
}
Also used : Issue(org.gephi.io.importer.api.Issue) ArrayList(java.util.ArrayList)

Example 15 with Issue

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

Aggregations

Issue (org.gephi.io.importer.api.Issue)52 NodeDraft (org.gephi.io.importer.api.NodeDraft)14 IOException (java.io.IOException)11 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)10 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)9 StringTokenizer (java.util.StringTokenizer)5 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 Interval (org.gephi.graph.api.Interval)3 EdgeProperties (org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)3 NodeProperties (org.gephi.io.importer.api.PropertiesAssociations.NodeProperties)3 Color (java.awt.Color)2 ResultSet (java.sql.ResultSet)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 Statement (java.sql.Statement)2 Pattern (java.util.regex.Pattern)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 TimestampSet (org.gephi.graph.api.types.TimestampSet)2 ElementDraft (org.gephi.io.importer.api.ElementDraft)2