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;
}
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;
}
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();
}
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);
}
}
}
}
}
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);
}
Aggregations