Search in sources :

Example 6 with ColumnDraft

use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.

the class ImportContainerImpl method addEdgeColumn.

@Override
public ColumnDraft addEdgeColumn(String key, Class typeClass, boolean dynamic) {
    key = key.toLowerCase().trim();
    ColumnDraft column = edgeColumns.get(key);
    typeClass = AttributeUtils.getStandardizedType(typeClass);
    if (column == null) {
        int index = edgeColumns.size();
        column = new ColumnDraftImpl(key, index, dynamic, typeClass);
        edgeColumns.put(key, column);
        if (dynamic) {
            report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.AddDynamicEdgeColumn", key, typeClass.getSimpleName()));
        } else {
            report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.AddEdgeColumn", key, typeClass.getSimpleName()));
        }
    } else if (!column.getTypeClass().equals(typeClass)) {
        report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Column_Type_Mismatch", key, column.getTypeClass()), Level.SEVERE));
    }
    return column;
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue)

Example 7 with ColumnDraft

use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.

the class ImportContainerImpl method addNodeColumn.

@Override
public ColumnDraft addNodeColumn(String key, Class typeClass, boolean dynamic) {
    key = key.toLowerCase().trim();
    ColumnDraft column = nodeColumns.get(key);
    typeClass = AttributeUtils.getStandardizedType(typeClass);
    if (column == null) {
        int index = nodeColumns.size();
        column = new ColumnDraftImpl(key, index, dynamic, typeClass);
        nodeColumns.put(key, column);
        if (dynamic) {
            report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.AddDynamicNodeColumn", key, typeClass.getSimpleName()));
        } else {
            report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.AddNodeColumn", key, typeClass.getSimpleName()));
        }
    } else if (!column.getTypeClass().equals(typeClass)) {
        report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Column_Type_Mismatch", key, column.getTypeClass()), Level.SEVERE));
    }
    return column;
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue)

Example 8 with ColumnDraft

use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.

the class ImporterEdgeList method getEdges.

private void getEdges(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.getEdgeQuery());
    } catch (SQLException ex) {
        report.logIssue(new Issue("Failed to execute Edge query", Issue.Level.SEVERE, ex));
        return;
    }
    findEdgeAttributesColumns(rs);
    ResultSetMetaData metaData = rs.getMetaData();
    int columnsCount = metaData.getColumnCount();
    int idColumn = edgeColumns.findIdIndex(metaData, properties);
    while (rs.next()) {
        EdgeDraft edge = edgeColumns.getEdgeDraft(factory, rs, idColumn);
        for (int i = 0; i < columnsCount; i++) {
            String columnName = metaData.getColumnLabel(i + 1);
            EdgeProperties p = properties.getEdgeProperty(columnName);
            if (p != null) {
                injectEdgeProperty(p, rs, i + 1, edge);
            } else {
                // Inject edge attributes
                ColumnDraft col = container.getEdgeColumn(columnName);
                injectElementAttribute(rs, i + 1, col, edge);
            }
        }
        injectTimeIntervalProperty(edge);
        container.addEdge(edge);
    }
    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) ResultSetMetaData(java.sql.ResultSetMetaData) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) ResultSet(java.sql.ResultSet) EdgeProperties(org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)

Example 9 with ColumnDraft

use of org.gephi.io.importer.api.ColumnDraft in project gephi by gephi.

the class DynamicGraph method generate.

@Override
public void generate(ContainerLoader container) {
    Random random = new Random();
    double start = 2000.0;
    double end = 2015.0;
    double tick = 1.0;
    ColumnDraft col = container.addNodeColumn("score", Integer.class, true);
    container.setTimeRepresentation(TimeRepresentation.TIMESTAMP);
    NodeDraft[] nodeArray = new NodeDraft[numberOfNodes];
    for (int i = 0; i < numberOfNodes; i++) {
        NodeDraft nodeDraft = container.factory().newNodeDraft("n" + i);
        container.addNode(nodeDraft);
        Random r = new Random();
        for (double t = start; t < end; t += tick) {
            if (r.nextBoolean()) {
                nodeDraft.addTimestamp(t);
                nodeDraft.setValue(col.getId(), r.nextInt(5), t);
            }
        }
        nodeArray[i] = nodeDraft;
    }
    if (wiringProbability > 0) {
        for (int i = 0; i < numberOfNodes - 1; i++) {
            NodeDraft node1 = nodeArray[i];
            for (int j = i + 1; j < numberOfNodes; j++) {
                NodeDraft node2 = nodeArray[j];
                if (random.nextDouble() < wiringProbability) {
                    EdgeDraft edgeDraft = container.factory().newEdgeDraft();
                    edgeDraft.setSource(node1);
                    edgeDraft.setTarget(node2);
                    Random r = new Random();
                    // DynamicFloat dynamicWeight = new DynamicFloat(new Interval<Float>(2010, 2012, false, true, new Float(r.nextInt(3) + 1)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2012, 2014, false, true, new Float(r.nextInt(3) + 2)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2014, 2016, false, true, new Float(r.nextInt(3) + 3)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2016, 2018, false, true, new Float(r.nextInt(3) + 4)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2018, 2020, false, true, new Float(r.nextInt(3) + 5)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2020, 2022, false, true, new Float(r.nextInt(3) + 6)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2022, 2024, false, true, new Float(r.nextInt(3) + 7)));
                    // dynamicWeight = new DynamicFloat(dynamicWeight, new Interval<Float>(2024, 2026, false, false, new Float(r.nextInt(3) + 8)));
                    // edgeDraft.addAttributeValue(weightCol, dynamicWeight);
                    container.addEdge(edgeDraft);
                }
            }
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Random(java.util.Random) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 10 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) {
    ColumnDraft column = getColumn(key);
    if (column.isDynamic()) {
        if (container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
            if (container.getInterval() != null) {
                parseAndSetValue(key, value, container.getInterval().getLow(), container.getInterval().getHigh());
                return;
            }
        } else {
            if (container.getTimestamp() != null) {
                parseAndSetValue(key, value, container.getTimestamp());
                return;
            }
        }
    }
    Class typeClass = column.getResolvedTypeClass(container);
    Object val = AttributeUtils.parse(value, typeClass);
    setValue(key, val);
}
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