Just made some time today to work on your project again. I think it's near completion, I'm just having trouble on one final detail.
Right now, it takes source.txt and creates two text files: nodes.txt and edges.txt. The only feature I wanted to code in (but could't figure out) was to take those two files and automatically put them together inside the graph:{} syntax as file graph.txt. As it is now, this is something you'd have to do manually (but should not be difficult).
Here's an example from your submission in the post above:
nodes.txt
node: {title: "dylan.cross"}
edges.txt
edge: {source: "dylan.cross" target: "gerbeenie"}
edge: {source: "dylan.cross" target: "laura-boland"}
edge: {source: "dylan.cross" target: "willconlon"}
edge: {source: "dylan.cross" target: "davkavo2"}
edge: {source: "dylan.cross" target: "sadge1"}
edge: {source: "dylan.cross" target: "greaneyc"}
edge: {source: "dylan.cross" target: "mr-sassy-pants"}
edge: {source: "dylan.cross" target: "eannaoshea"}
edge: {source: "dylan.cross" target: "micstallion"}
edge: {source: "dylan.cross" target: "niamhie21"}
I think that the comments in the code be fairly clear on each individual piece, but here's a note on the usage.
At the top of main, you'll see the line: const string breaktxt = "bebo";. This is the text that indicates a page break (can be easily substituted to anything else you find that's better), and usually would create a new node. The instance it would not is in the case of a new node being identical to the last, in which case the program simply continues making edges.
Give it a try on the data you have now, and let me know how it works. If you have a specific problem, it might be helpful to have a larger example of what you'd be sending the program.
So, without further ado, here's the source:
Source
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string getname( string& line );
//©noth(a)nk.you, 2006
int main()
{
const string breaktxt = "bebo";
const int timer = clock();
ifstream source( "source.txt", ios::in ); //source file
ofstream nodes( "nodes.txt", ios::out ), //node temp. file
edges( "edges.txt", ios::out ); //edge temp. file
if( !source || !nodes || !edges ) //checks existance
{
cerr << "File wasn't opened\n";
exit(1);
}
cout << "Processing..." << endl;
string line, username, nodename; //temporary variables
bool findnode = 1;
while( !source.eof() ) //stops at end of file
{
getline( source, line ); //gets a line at a time
username = getname( line ); //parses it
if ( username.empty() )
continue;
if ( line.find(breaktxt) != string::npos )
findnode = 1;
if ( findnode ) //write node to file
{
if ( nodename == username ) //no node for same user
continue;
nodename = username;
nodes << "node: {title: \"" << nodename << "\"}\n";
findnode = 0;
}
else //write edge to file
edges << "edge: {source: \"" << nodename << "\" target: \""
<< username << "\"}\n";
}
const int nodel = nodes.tellp(), edgel = edges.tellp();
//wrap up the files
source.close(), nodes.close(), edges.close();
cout << "Done!\nIt took " << (clock() - timer)/1000. << "s" << endl;
system("PAUSE");
}
string getname( string& line ) //parses a line passed
{
string temp = ""; //will be the output
int i = 0; //counter
bool writeflag = 0; //controls stop and start write
while( i < line.length() )
{
if ( writeflag ) //if we should be writing
{
temp += line[i]; //append each character
if ( line[++i] == 62 ) //if the character is a '>'
return temp; //stop writing
}
else if( line[i++] == 60 ) //if the character is a '<'
writeflag = true; //start writing
}
return temp;
}
Cheers!