Package org.gephi.data.attributes.api

Examples of org.gephi.data.attributes.api.AttributeColumn


        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel previewModel = previewController.getModel(graph.getGraphModel().getWorkspace());
       
        //Get the sort column from the properties, if any
        PreviewProperties previewProperties = previewModel.getProperties();
        final AttributeColumn sortColumn = previewProperties.getValue(SORT_COLUMN);
       
        //Get the standard node items from the node builder
        Item[] nodeItems = super.getItems(graph, attributeModel);
        if (sortColumn != null) {
            //Sort by column
            Arrays.sort(nodeItems, new Comparator<Item>() {

                @Override
                public int compare(Item o1, Item o2) {
                    Node n1 = (Node) o1.getSource();
                    Node n2 = (Node) o2.getSource();
                    Number s1 = (Number) n1.getAttributes().getValue(sortColumn.getIndex());
                    Number s2 = (Number) n2.getAttributes().getValue(sortColumn.getIndex());
                    double size1 = s1 == null ? Double.NEGATIVE_INFINITY : s1.doubleValue();
                    double size2 = s2 == null ? Double.NEGATIVE_INFINITY : s2.doubleValue();
                    return size1 > size2 ? 1 : size1 < size2 ? -1 : 0;
                }
            });
View Full Code Here


    }

    public void execute(Graph graph, AttributeModel attributeModel) {
        //Look if the result column already exist and create it if needed
        AttributeTable nodeTable = attributeModel.getNodeTable();
        AttributeColumn col = nodeTable.getColumn(AVG_EUCLIDEAN_DISTANCE);
        if (col == null) {
            col = nodeTable.addColumn(AVG_EUCLIDEAN_DISTANCE, "Average Euclidean Distance", AttributeType.DOUBLE, AttributeOrigin.COMPUTED, 0.0);
        }

        //Lock to graph. This is important to have consistent results if another
        //process is currently modifying it.
        graph.readLock();

        //Iterate on all nodes
        Node[] nodes = graph.getNodes().toArray();
        for (Node n : nodes) {
            double avg = 0;
            int count = 0;
            if (useOnlyConnections) {
                //Calculate distance with neighbors
                for (Node m : graph.getNeighbors(n)) {
                    double xDist = n.getNodeData().x() - m.getNodeData().x();
                    double yDist = n.getNodeData().y() - m.getNodeData().y();
                    double dist = Math.sqrt(xDist * xDist + yDist * yDist);
                    avg = (dist + avg) / ++count;
                }
            } else {
                //Calculate distance with all other nodes
                for (Node m : nodes) {
                    if (n != m) {
                        double xDist = n.getNodeData().x() - m.getNodeData().x();
                        double yDist = n.getNodeData().y() - m.getNodeData().y();
                        double dist = Math.sqrt(xDist * xDist + yDist * yDist);
                        avg = (dist + avg) / ++count;
                    }
                }
            }
            //Store the average in the node attribute
            n.getAttributes().setValue(col.getIndex(), avg);
        }

        graph.readUnlock();
    }
View Full Code Here

                values[i] = dynamicType.parse(String.format("[%s,%s,%s]", start, end, rows[i].getValue(column.getIndex()).toString()));
            } catch (Exception e) {
            }
        }

        AttributeColumn dynamicColumn = table.replaceColumn(column, column.getId(), column.getTitle(), dynamicType, column.getOrigin(), null);

        for (int i = 0; i < values.length; i++) {
            rows[i].setValue(dynamicColumn.getIndex(), values[i]);
        }
    }
View Full Code Here

        Object[] oldValues = new Object[rows.length];
        for (int i = 0; i < rows.length; i++) {
            oldValues[i] = rows[i].getValue(oldColumnIndex);
        }

        AttributeColumn newColumn;
        if (newColumnTitle == null) {
            newColumn = table.replaceColumn(column, column.getId(), column.getTitle(), newType, column.getOrigin(), null);
        } else {
            newColumn = table.addColumn(newColumnTitle, newColumnTitle, newType, column.getOrigin(), null);
        }
        int newColumnIndex = newColumn.getIndex();
       
        Object value;
        for (int i = 0; i < rows.length; i++) {
            if (oldValues[i] != null) {
                Interval interval = new Interval(low, high, lopen, ropen, oldValues[i]);
View Full Code Here

        return newColumn;
    }

    public AttributeColumn duplicateColumn(AttributeTable table, AttributeColumn column, String title, AttributeType type) {
        AttributeColumn newColumn = addAttributeColumn(table, title, type);
        if (newColumn == null) {
            return null;
        }
        copyColumnDataToOtherColumn(table, column, newColumn);
        return newColumn;
View Full Code Here

        return valuesFrequencies;
    }

    public AttributeColumn createBooleanMatchesColumn(AttributeTable table, AttributeColumn column, String newColumnTitle, Pattern pattern) {
        if (pattern != null) {
            AttributeColumn newColumn = addAttributeColumn(table, newColumnTitle, AttributeType.BOOLEAN);
            if (newColumn == null) {
                return null;
            }
            Matcher matcher;
            Object value;
            for (Attributes row : getTableAttributeRows(table)) {
                value = row.getValue(column.getIndex());
                if (value != null) {
                    matcher = pattern.matcher(value.toString());
                } else {
                    matcher = pattern.matcher("");
                }
                row.setValue(newColumn.getIndex(), matcher.matches());
            }
            return newColumn;
        } else {
            return null;
        }
View Full Code Here

        }
    }

    public AttributeColumn createFoundGroupsListColumn(AttributeTable table, AttributeColumn column, String newColumnTitle, Pattern pattern) {
        if (pattern != null) {
            AttributeColumn newColumn = addAttributeColumn(table, newColumnTitle, AttributeType.LIST_STRING);
            if (newColumn == null) {
                return null;
            }
            Matcher matcher;
            Object value;
            ArrayList<String> foundGroups = new ArrayList<String>();
            for (Attributes attributes : getTableAttributeRows(table)) {
                value = attributes.getValue(column.getIndex());
                if (value != null) {
                    matcher = pattern.matcher(value.toString());
                } else {
                    matcher = pattern.matcher("");
                }
                while (matcher.find()) {
                    foundGroups.add(matcher.group());
                }
                if (foundGroups.size() > 0) {
                    attributes.setValue(newColumn.getIndex(), new StringList(foundGroups.toArray(new String[0])));
                    foundGroups.clear();
                } else {
                    attributes.setValue(newColumn.getIndex(), null);
                }
            }
            return newColumn;
        } else {
            return null;
View Full Code Here

                        otherRow.setValue(column.getIndex(), row.getValue(column.getIndex()));
                    }
                }
            }
        } else {
            AttributeColumn column;
            AttributeValue[] values = attributeRow.getValues();
            for (int i = 0; i < values.length; i++) {
                column = values[i].getColumn();
                //Copy all except id and computed attributes:
                if (canChangeColumnData(column)) {
                    for (Attributes otherRow : otherRows) {
                        otherRow.setValue(column.getIndex(), row.getValue(column.getIndex()));
                    }
                }
            }
        }
    }
View Full Code Here

                if (columnNames[i].equalsIgnoreCase("id")) {
                    if (idColumn == null) {
                        idColumn = columnNames[i];
                    }
                } else if (nodesTable.hasColumn(columnNames[i])) {
                    AttributeColumn column = nodesTable.getColumn(columnNames[i]);
                    columnsList.add(column);
                    columnHeaders.put(column, columnNames[i]);
                } else {
                    AttributeColumn column = addAttributeColumn(nodesTable, columnNames[i], columnTypes[i]);
                    if (column != null) {
                        columnsList.add(column);
                        columnHeaders.put(column, columnNames[i]);
                    }
                }
View Full Code Here

                } else if (columnNames[i].equalsIgnoreCase("target") && targetColumn == null) {//Separate first target column found from the list to use as target node id
                    targetColumn = columnNames[i];
                } else if (columnNames[i].equalsIgnoreCase("type") && typeColumn == null) {//Separate first type column found from the list to use as edge type (directed/undirected)
                    typeColumn = columnNames[i];
                } else if (edgesTable.hasColumn(columnNames[i])) {
                    AttributeColumn column = edgesTable.getColumn(columnNames[i]);
                    columnsList.add(column);
                    columnHeaders.put(column, columnNames[i]);
                } else {
                    AttributeColumn column = addAttributeColumn(edgesTable, columnNames[i], columnTypes[i]);
                    if (column != null) {
                        columnsList.add(column);
                        columnHeaders.put(column, columnNames[i]);
                    }
                }
View Full Code Here

TOP

Related Classes of org.gephi.data.attributes.api.AttributeColumn

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.