Search in sources :

Example 21 with Element

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

the class AttributeColumnsControllerImpl method calculateColumnValuesFrequencies.

@Override
public Map<Object, Integer> calculateColumnValuesFrequencies(Table table, Column column) {
    Map<Object, Integer> valuesFrequencies = new HashMap<>();
    Object value;
    for (Element row : getTableAttributeRows(table)) {
        value = row.getAttribute(column);
        if (valuesFrequencies.containsKey(value)) {
            valuesFrequencies.put(value, valuesFrequencies.get(value) + 1);
        } else {
            valuesFrequencies.put(value, 1);
        }
    }
    return valuesFrequencies;
}
Also used : HashMap(java.util.HashMap) Element(org.gephi.graph.api.Element)

Example 22 with Element

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

the class AttributeColumnsControllerImpl method createBooleanMatchesColumn.

@Override
public Column createBooleanMatchesColumn(Table table, Column column, String newColumnTitle, Pattern pattern) {
    if (pattern != null) {
        Column newColumn = addAttributeColumn(table, newColumnTitle, Boolean.class);
        if (newColumn == null) {
            return null;
        }
        Matcher matcher;
        Object value;
        TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
        DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
        for (Element row : getTableAttributeRows(table)) {
            value = row.getAttribute(column);
            if (value != null) {
                matcher = pattern.matcher(AttributeUtils.print(value, timeFormat, timeZone));
            } else {
                matcher = pattern.matcher("");
            }
            row.setAttribute(newColumn, matcher.matches());
        }
        return newColumn;
    } else {
        return null;
    }
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Column(org.gephi.graph.api.Column) Matcher(java.util.regex.Matcher) Element(org.gephi.graph.api.Element) DateTimeZone(org.joda.time.DateTimeZone)

Example 23 with Element

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

the class AttributeColumnsControllerImpl method convertColumnToDynamic.

private Column convertColumnToDynamic(Table table, Column column, double low, double high, String newColumnTitle) {
    Class oldType = column.getTypeClass();
    TimeRepresentation timeRepresentation = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getConfiguration().getTimeRepresentation();
    Class<?> newType;
    if (timeRepresentation == TimeRepresentation.TIMESTAMP) {
        newType = AttributeUtils.getTimestampMapType(oldType);
    } else {
        newType = AttributeUtils.getIntervalMapType(oldType);
    }
    if (newColumnTitle != null) {
        if (newColumnTitle.equals(column.getTitle())) {
            throw new IllegalArgumentException("Column titles can't be equal");
        }
    }
    Element[] rows = getTableAttributeRows(table);
    Object[] oldValues = new Object[rows.length];
    for (int i = 0; i < rows.length; i++) {
        oldValues[i] = rows[i].getAttribute(column);
    }
    Column newColumn;
    if (newColumnTitle == null) {
        table.removeColumn(column);
        newColumn = table.addColumn(column.getTitle(), newType, column.getOrigin());
    } else {
        newColumn = table.addColumn(newColumnTitle, newType, column.getOrigin());
    }
    if (timeRepresentation == TimeRepresentation.TIMESTAMP) {
        for (int i = 0; i < rows.length; i++) {
            if (oldValues[i] != null) {
                rows[i].setAttribute(newColumn, oldValues[i], low);
            }
        }
    } else {
        Interval interval = new Interval(low, high);
        for (int i = 0; i < rows.length; i++) {
            if (oldValues[i] != null) {
                rows[i].setAttribute(newColumn, oldValues[i], interval);
            }
        }
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) TimeRepresentation(org.gephi.graph.api.TimeRepresentation) Element(org.gephi.graph.api.Element) GraphController(org.gephi.graph.api.GraphController) Interval(org.gephi.graph.api.Interval)

Example 24 with Element

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

the class AttributeColumnsControllerImpl method createFoundGroupsListColumn.

@Override
public Column createFoundGroupsListColumn(Table table, Column column, String newColumnTitle, Pattern pattern) {
    if (pattern != null) {
        Column newColumn = addAttributeColumn(table, newColumnTitle, String[].class);
        if (newColumn == null) {
            return null;
        }
        Matcher matcher;
        Object value;
        ArrayList<String> foundGroups = new ArrayList<>();
        TimeFormat timeFormat = table.getGraph().getModel().getTimeFormat();
        DateTimeZone timeZone = table.getGraph().getModel().getTimeZone();
        for (Element row : getTableAttributeRows(table)) {
            value = row.getAttribute(column);
            if (value != null) {
                matcher = pattern.matcher(AttributeUtils.print(value, timeFormat, timeZone));
            } else {
                matcher = pattern.matcher("");
            }
            while (matcher.find()) {
                foundGroups.add(matcher.group());
            }
            if (foundGroups.size() > 0) {
                row.setAttribute(newColumn, foundGroups.toArray(new String[0]));
                foundGroups.clear();
            } else {
                row.setAttribute(newColumn, null);
            }
        }
        return newColumn;
    } else {
        return null;
    }
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Column(org.gephi.graph.api.Column) Matcher(java.util.regex.Matcher) Element(org.gephi.graph.api.Element) ArrayList(java.util.ArrayList) DateTimeZone(org.joda.time.DateTimeZone)

Example 25 with Element

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

the class AttributeColumnsMergeStrategiesControllerImpl method maxValueNumbersMerge.

@Override
public Column maxValueNumbersMerge(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 max;
    for (Element row : ac.getTableAttributeRows(table)) {
        max = StatisticsUtils.maxValue(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, max);
    }
    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)

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