Search in sources :

Example 11 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsControllerImpl method negateColumnListBooleanType.

/**
     * Used to negate all values of a list of boolean values column.
     */
private void negateColumnListBooleanType(Table table, Column column) {
    Object value;
    Boolean[] newValues;
    for (Element row : getTableAttributeRows(table)) {
        value = row.getAttribute(column);
        if (value != null) {
            Boolean[] list = (Boolean[]) value;
            newValues = new Boolean[list.length];
            for (int i = 0; i < list.length; i++) {
                newValues[i] = !list[i];
            }
            row.setAttribute(column, newValues);
        }
    }
}
Also used : Element(org.gephi.graph.api.Element)

Example 12 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method joinWithSeparatorMerge.

@Override
public Column joinWithSeparatorMerge(Table table, Column[] columnsToMerge, Class newColumnType, String newColumnTitle, String separator) {
    if (table == null || columnsToMerge == null) {
        throw new IllegalArgumentException("Table or columns can't be null");
    }
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    //Create as STRING column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, newColumnType != null ? newColumnType : String.class);
    if (newColumn == null) {
        return null;
    }
    if (separator == null) {
        separator = "";
    }
    Object value;
    StringBuilder sb;
    final int columnsCount = columnsToMerge.length;
    GraphModel graphModel = table.getGraph().getModel();
    TimeFormat timeFormat = graphModel.getTimeFormat();
    DateTimeZone timeZone = graphModel.getTimeZone();
    for (Element row : ac.getTableAttributeRows(table)) {
        sb = new StringBuilder();
        for (int i = 0; i < columnsCount; i++) {
            value = row.getAttribute(columnsToMerge[i]);
            if (value != null) {
                sb.append(AttributeUtils.print(value, timeFormat, timeZone));
                if (i < columnsCount - 1) {
                    sb.append(separator);
                }
            }
        }
        ac.setAttributeValue(sb.toString(), row, newColumn);
    }
    return newColumn;
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) GraphModel(org.gephi.graph.api.GraphModel) Element(org.gephi.graph.api.Element) DateTimeZone(org.joda.time.DateTimeZone)

Example 13 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method minValueNumbersMerge.

@Override
public Column minValueNumbersMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    //Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal min;
    for (Element row : ac.getTableAttributeRows(table)) {
        min = StatisticsUtils.minValue(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, min);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 14 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method mergeNumericColumnsToTimeInterval.

@Override
public Column mergeNumericColumnsToTimeInterval(Table table, Column startColumn, Column endColumn, double defaultStart, double defaultEnd) {
    checkTableAndOneColumn(table, startColumn, endColumn);
    Column timeIntervalColumn = getTimeIntervalColumn(table);
    final int startColumnIndex = startColumn != null ? startColumn.getIndex() : -1;
    final int endColumnIndex = endColumn != null ? endColumn.getIndex() : -1;
    final boolean isStartColumnNumeric = startColumn != null ? (!AttributeUtils.isDynamicType(startColumn.getTypeClass()) && AttributeUtils.isNumberType(startColumn.getTypeClass())) : false;
    final boolean isEndColumnNumeric = endColumn != null ? (!AttributeUtils.isDynamicType(endColumn.getTypeClass()) && AttributeUtils.isNumberType(endColumn.getTypeClass())) : false;
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Object value;
    double start, end;
    for (Element row : ac.getTableAttributeRows(table)) {
        if (startColumnIndex != -1) {
            value = row.getAttribute(startColumn);
            if (value != null) {
                if (isStartColumnNumeric) {
                    start = ((Number) value).doubleValue();
                } else {
                    start = parseDouble(value.toString(), defaultStart);
                }
            } else {
                start = defaultStart;
            }
        } else {
            start = defaultStart;
        }
        if (endColumnIndex != -1) {
            value = row.getAttribute(endColumn);
            if (value != null) {
                if (isEndColumnNumeric) {
                    end = ((Number) value).doubleValue();
                } else {
                    end = parseDouble(value.toString(), defaultEnd);
                }
            } else {
                end = defaultEnd;
            }
        } else {
            end = defaultEnd;
        }
        if (!Double.isInfinite(start) && !Double.isInfinite(end) && start > end) {
            //When start>end, check what column was provided and keep its value. If both columns were provided, set an infinite interval:
            if (startColumnIndex == -1) {
                start = Double.NEGATIVE_INFINITY;
            } else if (endColumnIndex == -1) {
                end = Double.POSITIVE_INFINITY;
            } else {
                start = Double.NEGATIVE_INFINITY;
                end = Double.POSITIVE_INFINITY;
            }
        }
        IntervalSet timeInterval = new IntervalSet(new double[] { start, end });
        row.setAttribute(timeIntervalColumn, timeInterval);
    }
    return timeIntervalColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) IntervalSet(org.gephi.graph.api.types.IntervalSet)

Example 15 with Element

use of org.gephi.graph.api.Element in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method booleanLogicOperationsMerge.

@Override
public Column booleanLogicOperationsMerge(Table table, Column[] columnsToMerge, BooleanOperations[] booleanOperations, String newColumnTitle) {
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    if (table == null || columnsToMerge == null || booleanOperations == null || booleanOperations.length != columnsToMerge.length - 1) {
        throw new IllegalArgumentException("table, columns or operations can't be null and operations length must be columns length -1");
    }
    for (Column column : columnsToMerge) {
        if (!column.getTypeClass().equals(Boolean.class)) {
            throw new IllegalArgumentException("All columns have to be boolean columns");
        }
    }
    Column newColumn;
    newColumn = ac.addAttributeColumn(table, newColumnTitle, Boolean.class);
    if (newColumn == null) {
        return null;
    }
    Boolean value;
    Boolean secondValue;
    for (Element row : ac.getTableAttributeRows(table)) {
        value = (Boolean) row.getAttribute(columnsToMerge[0]);
        //Use false if null
        value = value != null ? value : false;
        for (int i = 0; i < booleanOperations.length; i++) {
            secondValue = (Boolean) row.getAttribute(columnsToMerge[i + 1]);
            //Use false if null
            secondValue = secondValue != null ? secondValue : false;
            switch(booleanOperations[i]) {
                case AND:
                    value = value && secondValue;
                    break;
                case OR:
                    value = value || secondValue;
                    break;
                case XOR:
                    value = value ^ secondValue;
                    break;
                case NAND:
                    value = !(value && secondValue);
                    break;
                case NOR:
                    value = !(value || secondValue);
                    break;
            }
        }
        row.setAttribute(newColumn, value);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element)

Aggregations

Element (org.gephi.graph.api.Element)30 Column (org.gephi.graph.api.Column)19 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)15 BigDecimal (java.math.BigDecimal)8 GraphController (org.gephi.graph.api.GraphController)4 TimeFormat (org.gephi.graph.api.TimeFormat)4 DateTimeZone (org.joda.time.DateTimeZone)4 Matcher (java.util.regex.Matcher)3 GraphModel (org.gephi.graph.api.GraphModel)3 TimeMap (org.gephi.graph.api.types.TimeMap)3 ArrayList (java.util.ArrayList)2 Graph (org.gephi.graph.api.Graph)2 Interval (org.gephi.graph.api.Interval)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JFileChooser (javax.swing.JFileChooser)1 Index (org.gephi.graph.api.Index)1 Node (org.gephi.graph.api.Node)1