GraphsPathFilter.init();
String path = Settings.GRAPHS_PATH + "PADA/";
String nodesFile = "people-w-attributes.csv";
String co_occurenceFile = "co-occurences-filter-ts2.csv";
DNVGraph graph = new DNVGraph();
File file = new File( path, nodesFile );
FileReader fr = new FileReader( file );
CSVReader csv = new CSVReader( fr );
String[] line;
DNVNode node;
while( (line=csv.readNext()) != null )
{
if( !line[0].equals( "" ) )
{
node = (DNVNode)graph.getNodeByBbId( line[0] );
if( node == null )
{
// if( line[3].trim().equals( "1" ) )
// {
node = new DNVNode( graph );
node.setBbId( line[0] );
node.setProperty( "numDocuments", line[1] );
node.setProperty( "numFamilyRelations", line[2] );
node.setProperty( "hasFamilyRelation", line[3] );
if( line[3].trim().equals( "1" ) )
{
node.setProperty( "Contents", "hasFamilyRelation" );
}
node.setPosition( (float)Math.random(), (float)Math.random() );
node.setLabel( line[4] );
graph.addNode( 0, node );
// }
}
else
{
System.out.println( "Multiple occurances of same node: " + line[0] );
}
}
}
csv.close();
fr.close();
System.out.println( "Added " + graph.getGraphSize( 0 ) + " nodes to the graph." );
file = new File( path, co_occurenceFile );
fr = new FileReader( file );
csv = new CSVReader( fr );
DNVNode node1;
DNVNode node2;
DNVEdge edge;
long time;
while( (line=csv.readNext()) != null )
{
if( !line[0].equals( "" ) )
{
node1 = (DNVNode)graph.getNodeByBbId( line[0] );
node2 = (DNVNode)graph.getNodeByBbId( line[1] );
if( !node1.getNeighborMap().containsKey( node2.getId() ) )
{
edge = new DNVEdge( node1, node2, graph );
edge.setBbId( node1.getBbId() + "->" + node2.getBbId() );
time = convertTimeStampToLong( line[3] );
if( time != -1 )
{
edge.setProperty( "time", "" + time );
}
graph.addEntity( 0, edge );
}
}
}
GraphFunctions.removeIsolatedNodes( graph, 0 );
List<DNVNode> nodes = graph.getNodes( 0 );
for( DNVNode tempNode : nodes )
{
List<DNVEdge> edges = new ArrayList<DNVEdge>( tempNode.getFromEdges() );
edges.addAll( tempNode.getToEdges() );
SortByFloatProperty sbfp = new SortByFloatProperty( "time", true );
Collections.sort( edges, sbfp );
tempNode.setProperty( "maxTime", edges.get( 0 ).getProperty( "time" ) );
tempNode.setProperty( "minTime", edges.get( edges.size()-1 ).getProperty( "time" ) );
}
SortByFloatProperty sbfp = new SortByFloatProperty( "numDocuments", true );
Collections.sort( nodes, sbfp );
node = nodes.get( 0 );
int maxNumDocuments = Integer.parseInt( node.getProperty( "numDocuments" ) );
System.out.println( "Max number of docs " + maxNumDocuments );
for( DNVNode tempNode : nodes )
{
Vector3D color = new Vector3D( LIGHT_GREEN );
if( tempNode.hasProperty( "numDocuments" ) )
{
Vector3D difference = new Vector3D( LIGHT_RED );
difference.subtract( color );
difference.dotProduct( (float)(Integer.parseInt( tempNode.getProperty( "numDocuments" ) ) )/(float)maxNumDocuments );
color.add( difference );
color.setX( (float)Math.max( 0, color.getX() ) );
color.setY( (float)Math.max( 0, color.getY() ) );
color.setZ( (float)Math.max( 0, color.getZ() ) );
color.setX( (float)Math.min( 1, color.getX() ) );
color.setY( (float)Math.min( 1, color.getY() ) );
color.setZ( (float)Math.min( 1, color.getZ() ) );
}
tempNode.setColor( color );
}
new FruchtermanReingold().runLayout( 100, 100, graph, 0.01f, 0, false, false );
System.out.println( "Graph has " + graph.getGraphSize( 0 ) + " nodes and " + graph.getEdgeMap( 0 ).size() + " edges." );
graph.writeGraph( Settings.GRAPHS_PATH + "PADA/" + nodesFile + ".dnv" );
}