Package org.gephi.io.importer.api

Examples of org.gephi.io.importer.api.NodeDraft


        if (id.isEmpty()) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGraphML.class, "importerGraphML_error_nodeid"), Issue.Level.SEVERE));
            return;
        }

        NodeDraft node = null;
        if (container.nodeExists(id)) {
            node = container.getNode(id);
        } else {
            node = container.factory().newNodeDraft(id);
        }
View Full Code Here


            edge = container.factory().newEdgeDraft(id);
        } else {
            edge = container.factory().newEdgeDraft();
        }

        NodeDraft nodeSource = container.getNode(source);
        NodeDraft nodeTarget = container.getNode(target);
        edge.setSource(nodeSource);
        edge.setTarget(nodeTarget);

        //Type
        if (!directed.isEmpty()) {
View Full Code Here

        }
        Progress.progress(progressTicket);      //Progress
    }

    private void addNode(String id, String label) {
        NodeDraft node;
        if (!container.nodeExists(id)) {
            node = container.factory().newNodeDraft(id);
            node.setLabel(label);
            container.addNode(node);
        }
    }
View Full Code Here

            container.addNode(node);
        }
    }

    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);
View Full Code Here

        } 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();
            }
View Full Code Here

        }
    }

    protected NodeDraft getOrCreateNode(String id) {
        if (!container.nodeExists(id)) {
            NodeDraft nodeDraft = container.factory().newNodeDraft(id);
            container.addNode(nodeDraft);
            return nodeDraft;
        }
        return container.getNode(id);
    }
View Full Code Here

            Progress.switchToDeterminate(progressTicket, num_vertices);        //Progress

            verticesArray = new NodeDraft[num_vertices];
            for (int i = 0; i < num_vertices; i++) {
                String label = "" + (i + 1);
                NodeDraft node = container.factory().newNodeDraft(label);
                node.setLabel(label);
                verticesArray[i] = node;
            }

            curLine = null;
            while (reader.ready()) {
View Full Code Here

        int v_id = Integer.parseInt(index) - 1; // go from 1-based to 0-based index
        if (v_id >= num_vertices || v_id < 0) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat4", v_id, num_vertices), Issue.Level.SEVERE));
        }

        NodeDraft node = verticesArray[v_id];

        // only attach the label if there's one to attach
        if (label != null && label.length() > 0) {
            node.setLabel(label);
        }

        // parse the rest of the line
        if (firstParts != -1 && parts != null && parts.length >= firstParts + 2) {
            int i = firstParts;
            //Coordinates
            if (i < parts.length - 1) {
                try {
                    float x = Float.parseFloat(parts[i]);
                    float y = Float.parseFloat(parts[i + 1]);

                    node.setX(x);
                    node.setY(y);

                    i++;
                } catch (Exception e) {
                    report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat5", lineReader.getLineNumber()), Issue.Level.WARNING));
                }
            }

            //Size
            if (i < parts.length - 1) {
                try {
                    float size = Float.parseFloat(parts[i]);

                    node.setSize(size);

                    i++;
                } catch (Exception e) {
                    report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat6", lineReader.getLineNumber()), Issue.Level.WARNING));
                }
            }

            // parse colors
            for (; i < parts.length - 1; i++) {
                // node's internal color
                if ("ic".equals(parts[i])) {
                    String colorName = parts[i + 1].replaceAll(" ", ""); // remove spaces from color's name so we can look it up
                    Color color = getPajekColorFromName(colorName);
                    node.setColor(color);
                    break;
                }
            }
        }
    }
View Full Code Here

            }

            StringTokenizer st = new StringTokenizer(nextLine.trim());

            int vid1 = Integer.parseInt(st.nextToken()) - 1;
            NodeDraft nodeFrom = verticesArray[vid1];

            if (is_list) // one source, multiple destinations
            {
                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
View Full Code Here

                final String message = NbBundle.getMessage(GraphDbImporter.class, "Issue_NoIdentifier");
                final Issue issue = new Issue(message, Issue.Level.WARNING);
                report.logIssue(issue);
                continue;
            }
            final NodeDraft gephiNode = container.factory().newNodeDraft();
            gephiNode.setId(vertexId.toString());           
            container.addNode(gephiNode);
            report.log(NbBundle.getMessage(GraphDbImporter.class, "Report_NodeAdded",
                    vertexId.toString()));           
            for (final String propertyKey : vertex.getPropertyKeys()) {
                final Object propertyValue = vertex.getProperty(propertyKey);
                AttributeColumn attributeColumn;
                if (attributeModel.getNodeTable().hasColumn(propertyKey)) {
                    attributeColumn = attributeModel.getNodeTable().getColumn(propertyKey);
                } else {
                    final AttributeType attributeType = AttributeTypeMapper.map(propertyValue);
                    attributeColumn = attributeModel.getNodeTable().addColumn(propertyKey, attributeType);
                }
                gephiNode.addAttributeValue(attributeColumn, propertyValue);
                report.log(NbBundle.getMessage(GraphDbImporter.class,
                        "Report_AttributeAdded", propertyKey, propertyValue));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.gephi.io.importer.api.NodeDraft

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.