Search in sources :

Example 16 with ColumnDraft

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();
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) SQLException(java.sql.SQLException) ElementDraft(org.gephi.io.importer.api.ElementDraft) PropertiesAssociations(org.gephi.io.importer.api.PropertiesAssociations) Statement(java.sql.Statement) NodeDraft(org.gephi.io.importer.api.NodeDraft) ResultSetMetaData(java.sql.ResultSetMetaData) NodeProperties(org.gephi.io.importer.api.PropertiesAssociations.NodeProperties) ResultSet(java.sql.ResultSet)

Example 17 with ColumnDraft

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);
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) TimeMap(org.gephi.graph.api.types.TimeMap) IntervalDoubleMap(org.gephi.graph.api.types.IntervalDoubleMap) Column(org.gephi.graph.api.Column) TimestampDoubleMap(org.gephi.graph.api.types.TimestampDoubleMap) IntervalMap(org.gephi.graph.api.types.IntervalMap)

Example 18 with ColumnDraft

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));
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) Configuration(org.gephi.graph.api.Configuration) GraphController(org.gephi.graph.api.GraphController)

Example 19 with ColumnDraft

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));
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue)

Example 20 with ColumnDraft

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);
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft)

Aggregations

ColumnDraft (org.gephi.io.importer.api.ColumnDraft)20 Issue (org.gephi.io.importer.api.Issue)14 TimeMap (org.gephi.graph.api.types.TimeMap)4 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 EdgeProperties (org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)3 NodeProperties (org.gephi.io.importer.api.PropertiesAssociations.NodeProperties)3 ResultSet (java.sql.ResultSet)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 Column (org.gephi.graph.api.Column)2 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)2 TimeSet (org.gephi.graph.api.types.TimeSet)2 ElementDraft (org.gephi.io.importer.api.ElementDraft)2 NodeDraft (org.gephi.io.importer.api.NodeDraft)2 PropertiesAssociations (org.gephi.io.importer.api.PropertiesAssociations)2 BigInteger (java.math.BigInteger)1 Random (java.util.Random)1 Configuration (org.gephi.graph.api.Configuration)1