Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

linkgraph.cc

Go to the documentation of this file.
00001 /** @file linkgraph.cc */
00002 /* 
00003  * Copyright (C) 2002 Laird Breyer
00004  *  
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * 
00019  * Author:   Laird Breyer <laird@lbreyer.com>
00020  */
00021 
00022 #include "webnode.h"
00023 #include "linkgraph.h"
00024 #include <math.h>
00025 
00026 WebLinkGraph :: WebLinkGraph(): WebNodeList() {
00027   for(int k =0; k < TAG_NUMBER_OF_BITS; k++) {
00028     fromsetsize[k] = 0;
00029   }
00030 }
00031 
00032 /// Prints to a stream a textual description of the graph structure
00033 void WebLinkGraph :: PrintWebGraph(ostream& o) {
00034   o << "# node | date | num_dangling | num_fromlinks | num_tolinks | tolinks_list..." << endl;
00035   for(WebNodeList::iterator i = begin(); i != end(); i++ ) {
00036     o << (*i)->ID()
00037       << " " << (*i)->Date()
00038       << " " << (int)(*i)->NumberOfDanglingToLinks()
00039       << " " << (*i)->NumberOfValidFromLinks()
00040       << " " << (*i)->NumberOfValidToLinks();
00041     int n = (*i)->NumberOfValidToLinks();
00042     for(int k = 0; k < n; k++) {
00043       o << " " << (*i)->ValidToLink(k)->ID();
00044     }
00045     for(int k = 0; k < (*i)->NumberOfLeafLinks(); k++) {
00046       o << " " << (*i)->ValidLeafLink(k)->ID();
00047     }
00048     o << endl;
00049   }
00050 }
00051 
00052 /// Clears all tagged WebNode objects
00053 void WebLinkGraph :: ClearTags() {
00054   for(WebNodeList::iterator i = begin(); i != end(); i++) {
00055     (*i)->ClearTag();
00056   }
00057 }
00058 
00059 /// Builds FromSets for a given set of tagged WebNode objects.
00060 /// Note parameter k is currently not used.
00061 void WebLinkGraph :: BuildFromSets(int k) {
00062   // k not actually used
00063   assert( k <= TAG_NUMBER_OF_BITS );
00064   assert( k >= 0 );
00065   for(int t = 0; t < (TAG_NUMBER_OF_BITS - 1); t++) {
00066     cerr << "info: tagging fromset # " << (t+1) << endl;
00067     for(WebNodeList::iterator i = begin(); i != end(); i++) {
00068       assert(*i);
00069       WebNodePtr w = (*i);
00070       assert(w);
00071       if( w->Tagged(t) ) {
00072         for(int j = 0; j < w->NumberOfValidFromLinks(); j++) {
00073           WebNodePtr v = w->ValidFromLink(j);
00074           assert(v);
00075           // assert(v != w); NOT true, since redirects can introduce autolinks
00076           v->SetTag(t+1);
00077           assert( v->Tagged(t+1) );
00078         }
00079       }
00080     }
00081   }
00082 }
00083 
00084 /// Calculates the size of each FromSet.
00085 /// This calculation is saved in the array fromsetsize[]
00086 void WebLinkGraph :: MeasureFromSets() {
00087   // clear counts
00088   for(int j = 0; j < TAG_NUMBER_OF_BITS; j++) {
00089     fromsetsize[j] = 0;
00090   }
00091   // iterate through the graph
00092   for(WebNodeList::iterator i = begin(); i != end(); i++) {
00093     assert(*i);
00094     for(int j = 0; j < TAG_NUMBER_OF_BITS; j++) {
00095       if( (*i)->Tagged(j) ) {
00096         fromsetsize[j]++;
00097       }
00098     }
00099   }
00100 }
00101 
00102 /// Lists the fromsetsize[] values to a stream.
00103 void WebLinkGraph :: StatisticsFromSets(ostream& o) {
00104   o << "\nNumber of tagged webnodes:  " << fromsetsize[0] << endl;
00105   if( fromsetsize[0] ) {
00106     for(int i = 1; i < TAG_NUMBER_OF_BITS; i++) {
00107       o << "Number of webnodes at distance " << i << " from tagged set:  " << fromsetsize[i] << endl;
00108     }
00109   }
00110 }

Generated on Wed May 29 11:37:14 2002 for MarkovPR by doxygen1.2.15