I'm currently using Gephi source code for a school project. I have a database conform to the Edge List format where nodes NODE(ID,LABEL,TYPE) are different kinds of entities. Each node type has a table associated with it (eg USER(ID,AGE,...), CONTENT(ID,DIMENSION,...)) where I store attributes.
Is there a way to import these attributes in Gephi. I tried to add attributes to nodes after the graph has been created using this code
Code: Select all
stmt = connection.createStatement();
rs = stmt.executeQuery(attributeQuery);
ResultSetMetaData rsMetaData = (ResultSetMetaData) rs.getMetaData();
AttributeColumn attrcolumn;
int numberOfColumns = rsMetaData.getColumnCount();
ArrayList<String> attributesIDs = new ArrayList<String>();
for (int i = 1; i <= numberOfColumns; i++) {
String attributeID = rsMetaData.getColumnName(i);
int attributeType = rsMetaData.getColumnType(i);
attrcolumn = model.getNodeTable().getColumn(attributeID);
if (attrcolumn == null){
//Add column
attrcolumn = model.getNodeTable().addColumn(attributeID, AttributeType.STRING);
}
attributesIDs.add(attributeID);
}
//OverWrite values to nodes
while (rs.next()) {
Node n = graphModel.getGraph().getNode(rs.getString("ID"));
for(int j=1; j<attributesIDs.size(); j++){
if (!attributesIDs.get(j).equalsIgnoreCase("ID"))
n.getNodeData().getAttributes().setValue(
model.getNodeTable().getColumn(
attributesIDs.get(j)).getIndex(), rs.getInt(j+1));
}