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;
}
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;
}
}
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;
}
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;
}
}
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;
}
Aggregations