Search in sources :

Example 1 with Table

use of org.gephi.graph.api.Table in project gephi-plugins-bootcamp by gephi.

the class AverageEuclideanDistance method execute.

@Override
public void execute(GraphModel graphModel) {
    Graph graph = graphModel.getGraphVisible();
    //Look if the result column already exist and create it if needed
    Table nodeTable = graphModel.getNodeTable();
    Column col = nodeTable.getColumn(AVG_EUCLIDEAN_DISTANCE);
    if (col == null) {
        col = nodeTable.addColumn(AVG_EUCLIDEAN_DISTANCE, "Average Euclidean Distance", Double.class, Origin.DATA);
    }
    //Lock to graph. This is important to have consistent results if another
    //process is currently modifying it.
    graph.readLock();
    //Iterate on all nodes
    Node[] nodes = graph.getNodes().toArray();
    for (Node n : nodes) {
        double avg = 0;
        int count = 0;
        if (useOnlyConnections) {
            //Calculate distance with neighbors
            for (Node m : graph.getNeighbors(n)) {
                double xDist = n.x() - m.x();
                double yDist = n.y() - m.y();
                double dist = Math.sqrt(xDist * xDist + yDist * yDist);
                avg = (dist + avg) / ++count;
            }
        } else {
            //Calculate distance with all other nodes
            for (Node m : nodes) {
                if (n != m) {
                    double xDist = n.x() - m.x();
                    double yDist = n.y() - m.y();
                    double dist = Math.sqrt(xDist * xDist + yDist * yDist);
                    avg = (dist + avg) / ++count;
                }
            }
        }
        //Store the average in the node attribute
        n.setAttribute(col, avg);
    }
    graph.readUnlock();
}
Also used : Graph(org.gephi.graph.api.Graph) Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) Node(org.gephi.graph.api.Node)

Example 2 with Table

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

the class ClusteringCoefficient method execute.

public void execute(Graph graph) {
    isCanceled = false;
    HashMap<String, Double> resultValues = new HashMap<>();
    if (isDirected) {
        avgClusteringCoeff = bruteForce(graph);
    } else {
        initStartValues(graph);
        resultValues = computeTriangles(graph, network, triangles, nodeClustering, isDirected);
        totalTriangles = resultValues.get("triangles").intValue();
        avgClusteringCoeff = resultValues.get("clusteringCoefficient");
    }
    //Set results in columns
    Table nodeTable = graph.getModel().getNodeTable();
    Column clusteringCol = nodeTable.getColumn(CLUSTERING_COEFF);
    if (clusteringCol == null) {
        clusteringCol = nodeTable.addColumn(CLUSTERING_COEFF, "Clustering Coefficient", Double.class, new Double(0));
    }
    Column triCount = null;
    if (!isDirected) {
        triCount = nodeTable.getColumn("Triangles");
        if (triCount == null) {
            triCount = nodeTable.addColumn("Triangles", "Number of triangles", Integer.class, new Integer(0));
        }
    }
    for (int v = 0; v < N; v++) {
        if (network[v].length() > 1) {
            network[v].node.setAttribute(clusteringCol, nodeClustering[v]);
            if (!isDirected) {
                network[v].node.setAttribute(triCount, triangles[v]);
            }
        }
    }
}
Also used : Table(org.gephi.graph.api.Table) HashMap(java.util.HashMap) Column(org.gephi.graph.api.Column)

Example 3 with Table

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

the class AbstractProcessor method flushColumns.

protected void flushColumns(ContainerUnloader container) {
    TimeRepresentation timeRepresentation = container.getTimeRepresentation();
    Table nodeTable = graphModel.getNodeTable();
    for (ColumnDraft col : container.getNodeColumns()) {
        if (!nodeTable.hasColumn(col.getId())) {
            Class typeClass = col.getTypeClass();
            if (col.isDynamic()) {
                if (timeRepresentation.equals(TimeRepresentation.TIMESTAMP)) {
                    typeClass = AttributeUtils.getTimestampMapType(typeClass);
                } else {
                    typeClass = AttributeUtils.getIntervalMapType(typeClass);
                }
            }
            nodeTable.addColumn(col.getId(), col.getTitle(), typeClass, Origin.DATA, col.getDefaultValue(), !col.isDynamic());
        }
    }
    Table edgeTable = graphModel.getEdgeTable();
    for (ColumnDraft col : container.getEdgeColumns()) {
        if (!edgeTable.hasColumn(col.getId())) {
            Class typeClass = col.getTypeClass();
            if (col.isDynamic()) {
                if (timeRepresentation.equals(TimeRepresentation.TIMESTAMP)) {
                    typeClass = AttributeUtils.getTimestampMapType(typeClass);
                } else {
                    typeClass = AttributeUtils.getIntervalMapType(typeClass);
                }
            }
            edgeTable.addColumn(col.getId(), col.getTitle(), typeClass, Origin.DATA, col.getDefaultValue(), !col.isDynamic());
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Table(org.gephi.graph.api.Table) TimeRepresentation(org.gephi.graph.api.TimeRepresentation)

Example 4 with Table

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

the class Modularity method saveValues.

private void saveValues(int[] struct, Graph graph, CommunityStructure theStructure) {
    Table nodeTable = graph.getModel().getNodeTable();
    Column modCol = nodeTable.getColumn(MODULARITY_CLASS);
    if (modCol == null) {
        modCol = nodeTable.addColumn(MODULARITY_CLASS, "Modularity Class", Integer.class, 0);
    }
    for (Node n : graph.getNodes()) {
        int n_index = theStructure.map.get(n);
        n.setAttribute(modCol, struct[n_index]);
    }
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) Node(org.gephi.graph.api.Node)

Example 5 with Table

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

the class DynamicClusteringCoefficient method execute.

@Override
public void execute(GraphModel graphModel) {
    this.graphModel = graphModel;
    this.isDirected = graphModel.isDirected();
    this.averages = new HashMap<>();
    //Attributes cols
    if (!averageOnly) {
        TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
        Table nodeTable = graphModel.getNodeTable();
        dynamicCoefficientColumn = nodeTable.getColumn(DYNAMIC_CLUSTERING_COEFFICIENT);
        if (dynamicCoefficientColumn == null) {
            dynamicCoefficientColumn = nodeTable.addColumn(DYNAMIC_CLUSTERING_COEFFICIENT, NbBundle.getMessage(DynamicClusteringCoefficient.class, "DynamicClusteringCoefficient.nodecolumn.ClusteringCoefficient"), tr.equals(TimeRepresentation.INTERVAL) ? IntervalDoubleMap.class : TimestampDoubleMap.class, null);
        }
    }
}
Also used : Table(org.gephi.graph.api.Table) TimeRepresentation(org.gephi.graph.api.TimeRepresentation)

Aggregations

Table (org.gephi.graph.api.Table)28 Column (org.gephi.graph.api.Column)22 Node (org.gephi.graph.api.Node)10 GraphController (org.gephi.graph.api.GraphController)7 Edge (org.gephi.graph.api.Edge)5 GraphElementsController (org.gephi.datalab.api.GraphElementsController)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 EdgesDataTable (org.gephi.desktop.datalab.tables.EdgesDataTable)3 NodesDataTable (org.gephi.desktop.datalab.tables.NodesDataTable)3 TimeFormat (org.gephi.graph.api.TimeFormat)3 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)3 DateTimeZone (org.joda.time.DateTimeZone)3 CsvReader (com.csvreader.CsvReader)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 SearchResult (org.gephi.datalab.api.SearchReplaceController.SearchResult)2 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)2