use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class ImporterEdgeList method getNodes.
private void getNodes(Connection connection) throws SQLException {
// Factory
ElementDraft.Factory factory = container.factory();
// Properties
PropertiesAssociations properties = database.getPropertiesAssociations();
Statement s = connection.createStatement();
ResultSet rs = null;
try {
rs = s.executeQuery(database.getNodeQuery());
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to execute Node query", Issue.Level.SEVERE, ex));
return;
}
findNodeAttributesColumns(rs);
ResultSetMetaData metaData = rs.getMetaData();
int columnsCount = metaData.getColumnCount();
int idColumn = nodeColumns.findIdIndex(metaData, properties);
while (rs.next()) {
final NodeDraft node = nodeColumns.getNodeDraft(factory, rs, idColumn);
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
NodeProperties p = properties.getNodeProperty(columnName);
if (p != null) {
injectNodeProperty(p, rs, i + 1, node);
} else {
// Inject node attributes
ColumnDraft col = container.getNodeColumn(columnName);
injectElementAttribute(rs, i + 1, col, node);
}
}
injectTimeIntervalProperty(node);
container.addNode(node);
}
rs.close();
s.close();
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class AbstractProcessor method flushEdgeWeight.
protected void flushEdgeWeight(ContainerUnloader container, EdgeDraft edgeDraft, Edge edge, boolean newEdge) {
Column weightColumn = graphModel.getEdgeTable().getColumn("weight");
ColumnDraft weightColumnDraft = container.getEdgeColumn("weight");
boolean weightColumnDraftIsDynamic = weightColumnDraft != null && weightColumnDraft.isDynamic();
if (weightColumn.isDynamic() != weightColumnDraftIsDynamic) {
Class weightColumnDraftTypeClass = weightColumnDraft != null ? weightColumnDraft.getResolvedTypeClass(container) : Double.class;
if (!columnsTypeMismatchAlreadyWarned.contains(weightColumn)) {
columnsTypeMismatchAlreadyWarned.add(weightColumn);
String error = NbBundle.getMessage(AbstractProcessor.class, "AbstractProcessor.error.columnTypeMismatch", weightColumn.getId(), weightColumn.getTypeClass().getSimpleName(), weightColumnDraftTypeClass.getSimpleName());
report.logIssue(new Issue(error, Issue.Level.SEVERE));
}
return;
}
if (weightColumn.isDynamic()) {
Object val = edgeDraft.getValue("weight");
if (val != null && val instanceof TimeMap) {
TimeMap valMap = (TimeMap) val;
if (Number.class.isAssignableFrom(valMap.getTypeClass())) {
final TimeMap newMap;
if (val instanceof IntervalMap) {
newMap = new IntervalDoubleMap();
} else {
newMap = new TimestampDoubleMap();
}
TimeMap existingMap = (TimeMap) edge.getAttribute("weight");
if (existingMap != null) {
Object[] keys2 = existingMap.toKeysArray();
Object[] vals2 = existingMap.toValuesArray();
for (int i = 0; i < keys2.length; i++) {
newMap.put(keys2[i], ((Number) vals2[i]).doubleValue());
}
}
Object[] keys1 = valMap.toKeysArray();
Object[] vals1 = valMap.toValuesArray();
for (int i = 0; i < keys1.length; i++) {
try {
newMap.put(keys1[i], ((Number) vals1[i]).doubleValue());
} catch (IllegalArgumentException e) {
// Overlapping intervals, ignore
}
}
edge.setAttribute("weight", newMap);
}
}
} else if (!newEdge) {
if (edgeDraft.getTimeSet() != null || edgeDraft.getValue("timeset") != null || edge.getAttribute("timeset") != null) {
// Don't merge double (non dynamic) weights when the edges have dynamic time intervals/timestamps, they are the same edge in different periods of time
return;
}
// Merge the existing edge and the draft edge weights:
double result = edge.getWeight();
edgeCountForAverage.addTo(edge, 1);
int edgeCount = edgeCountForAverage.getInt(edge);
switch(containers[0].getEdgesMergeStrategy()) {
case AVG:
result = (edge.getWeight() * edgeCount + edgeDraft.getWeight()) / (edgeCount + 1);
break;
case MAX:
result = Math.max(edgeDraft.getWeight(), edge.getWeight());
break;
case MIN:
result = Math.min(edgeDraft.getWeight(), edge.getWeight());
break;
case SUM:
result = edgeDraft.getWeight() + edge.getWeight();
break;
case FIRST:
result = edge.getWeight();
break;
case LAST:
result = edgeDraft.getWeight();
break;
default:
break;
}
edge.setWeight(result);
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class DefaultProcessor method processConfiguration.
protected void processConfiguration(ContainerUnloader container, Workspace workspace) {
// Configuration
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
Configuration configuration = new Configuration();
configuration.setTimeRepresentation(container.getTimeRepresentation());
if (container.getEdgeTypeLabelClass() != null) {
configuration.setEdgeLabelType(container.getEdgeTypeLabelClass());
}
configuration.setNodeIdType(container.getElementIdType().getTypeClass());
configuration.setEdgeIdType(container.getElementIdType().getTypeClass());
ColumnDraft weightColumn = container.getEdgeColumn("weight");
if (weightColumn != null && weightColumn.isDynamic()) {
if (container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
configuration.setEdgeWeightType(IntervalDoubleMap.class);
} else {
configuration.setEdgeWeightType(TimestampDoubleMap.class);
}
}
GraphConfigurationWrapper originalConfig = new GraphConfigurationWrapper(graphController.getGraphModel(workspace).getConfiguration());
if (container.getEdgeCount() == 0) {
// Make weight types match:
if (!originalConfig.edgeWeightType.equals(configuration.getEdgeWeightType())) {
configuration.setEdgeWeightType(originalConfig.edgeWeightType);
}
}
GraphConfigurationWrapper newConfig = new GraphConfigurationWrapper(configuration);
if (!originalConfig.equals(newConfig)) {
try {
graphController.getGraphModel(workspace).setConfiguration(configuration);
} catch (Exception e) {
String message = NbBundle.getMessage(DefaultProcessor.class, "DefaultProcessor.error.configurationChangeForbidden", new GraphConfigurationWrapper(graphController.getGraphModel(workspace).getConfiguration()).toString(), new GraphConfigurationWrapper(configuration).toString());
report.logIssue(new Issue(message, Issue.Level.SEVERE));
}
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class ElementDraftImpl method setValue.
@Override
public void setValue(String key, Object value) {
if (value == null) {
throw new NullPointerException("Value can't be null");
}
Class type = value.getClass();
if (AttributeUtils.isDynamicType(type) && !TimeSet.class.isAssignableFrom(type)) {
type = AttributeUtils.getStaticType(type);
}
ColumnDraft column = getColumn(key, type);
try {
setAttributeValue(column, value);
} catch (Exception ex) {
String message = NbBundle.getMessage(ElementDraftImpl.class, "ElementDraftException_SetValueError", value.toString(), id, ex.getMessage());
container.getReport().logIssue(new Issue(message, Issue.Level.SEVERE));
}
}
use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.
the class ElementDraftImpl method parseAndSetValue.
@Override
public void parseAndSetValue(String key, String value, double start, double end) {
ColumnDraft column = getColumn(key);
Object val = AttributeUtils.parse(value, column.getTypeClass());
setValue(key, val, start, end);
}
Aggregations