| 12 |
* Get sql access and important functions |
* Get sql access and important functions |
| 13 |
*/ |
*/ |
| 14 |
require_once './includes/bootstrap.inc'; |
require_once './includes/bootstrap.inc'; |
| 15 |
drupal_bootstrap(DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE); |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
| 16 |
require_once 'modules/sna/common.php'; |
require_once 'modules/sna/common.php'; |
| 17 |
|
|
| 18 |
/** |
/** |
| 19 |
* Create a graph from nodes-comments tables. |
* Create a graph from nodes-comments tables. |
| 20 |
* |
* |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
/** |
/** |
|
* When should we throw away edges |
|
|
* |
|
|
* @param integer $total Number of connections |
|
|
* @return integer The thresold for throwing away edges |
|
|
*/ |
|
|
function get_limit($total) { |
|
|
if ($total < 1000) { |
|
|
return FALSE; |
|
|
} |
|
|
else { |
|
|
return 3 * log($total - 999); // Ad-hoc computation based on some experiment |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
| 96 |
* Create a dot file from the graph to Graphviz |
* Create a dot file from the graph to Graphviz |
| 97 |
* Graphviz is a graph visualization tool |
* Graphviz is a graph visualization tool |
| 98 |
* |
* |
| 102 |
*/ |
*/ |
| 103 |
function generate_graphviz_input($edges, $num_interactions) { |
function generate_graphviz_input($edges, $num_interactions) { |
| 104 |
$dot_graph = "digraph G {\n"; |
$dot_graph = "digraph G {\n"; |
|
$limit = intval(get_limit($num_interactions)); |
|
| 105 |
foreach ($edges as $u1 => $sub_arr) { |
foreach ($edges as $u1 => $sub_arr) { |
| 106 |
if ($u1 === 0) { // Anonymous - don't count them! |
if ($u1 === 0) { // Anonymous - don't count them! |
| 107 |
break; |
break; |
| 110 |
if ($u2 === 0) { // Anonymous - don't count them! |
if ($u2 === 0) { // Anonymous - don't count them! |
| 111 |
break; |
break; |
| 112 |
} |
} |
| 113 |
if (($num > $limit) || ($limit === FALSE)) { |
$dot_graph .= "\t\"". get_real_name($u1). |
| 114 |
$dot_graph .= "\t\"". get_real_name($u1). |
"\" -> \"". get_real_name($u2) . |
| 115 |
"\" -> \"". get_real_name($u2) . |
"\" [label=". round($edges[$u1][$u2], 2) ."];\n"; |
|
"\" [label=". round($edges[$u1][$u2], 2) ."];\n"; |
|
|
} |
|
| 116 |
} |
} |
| 117 |
} |
} |
|
|
|
| 118 |
$dot_graph .= "}"; |
$dot_graph .= "}"; |
| 119 |
if (!$fp = fopen(DOT_PATH, "w")) { |
if (!$fp = fopen(DOT_PATH, "w")) { |
| 120 |
return FALSE; |
return FALSE; |
| 151 |
if ($vx_to === 0) { // Anonymous - don't count them! |
if ($vx_to === 0) { // Anonymous - don't count them! |
| 152 |
break; |
break; |
| 153 |
} |
} |
| 154 |
if ($edges[$vx_from][$vx_to] > 20) { |
$edg .= $real_id[$vx_from] ." ". $real_id[$vx_to] ." ". $edges[$vx_from][$vx_to] ."\n"; |
|
$edg .= $real_id[$vx_from] ." ". $real_id[$vx_to] ." ". $edges[$vx_from][$vx_to] ."\n"; |
|
|
} |
|
| 155 |
} |
} |
|
|
|
|
|
|
| 156 |
} |
} |
| 157 |
$net .= "*Vertices ". $num_vertex ."\n". $vert . $edg; |
$net .= "*Vertices ". $num_vertex ."\n". $vert . $edg; |
| 158 |
if (!$fp = fopen(NET_PATH, "w")) { |
if (!$fp = fopen(NET_PATH, "w")) { |
| 188 |
* @return array $edges The adjacentcy list of the graph |
* @return array $edges The adjacentcy list of the graph |
| 189 |
*/ |
*/ |
| 190 |
function transform_edges($edges) { |
function transform_edges($edges) { |
| 191 |
$min_max = get_min_and_max_degree($edges); |
$min_max = get_min_and_max_strength($edges); |
| 192 |
$transformed_graph = array(); |
$transformed_graph = array(); |
| 193 |
foreach (array_keys($edges) as $A) { |
foreach (array_keys($edges) as $A) { |
| 194 |
foreach (array_keys($edges[$A]) as $B) { |
foreach (array_keys($edges[$A]) as $B) { |
| 197 |
} |
} |
| 198 |
return $transformed_graph; |
return $transformed_graph; |
| 199 |
} |
} |
|
$at_start = res_start(); |
|
| 200 |
|
|
| 201 |
|
$at_start = res_start(); |
| 202 |
if (!function_exists('dba_open')) { |
if (!function_exists('dba_open')) { |
| 203 |
die('Dba support is not available.'); |
die('Dba support is not available.'); |
| 204 |
} |
} |
| 212 |
if (!put_graph($edges)) { |
if (!put_graph($edges)) { |
| 213 |
die('Cannot save the network into file'); |
die('Cannot save the network into file'); |
| 214 |
} |
} |
|
|
|
| 215 |
/* Cache the most popular vertex's minimal tree */ |
/* Cache the most popular vertex's minimal tree */ |
| 216 |
$most_popular = sort_by_popularity($edges); |
$most_popular = sort_by_popularity($edges); |
| 217 |
$most_popular_size = sizeof($most_popular); |
$most_popular_size = sizeof($most_popular); |
| 222 |
a_to_any($edges, $most_popular[$i][1], TRUE); |
a_to_any($edges, $most_popular[$i][1], TRUE); |
| 223 |
print $most_popular[$i][1] . " cached\n"; |
print $most_popular[$i][1] . " cached\n"; |
| 224 |
} |
} |
|
|
|
| 225 |
generate_graphviz_input($edges, $num_interactions); |
generate_graphviz_input($edges, $num_interactions); |
| 226 |
generate_pajek_input($edges); |
generate_pajek_input($edges); |
| 227 |
print_r(res_stop($at_start)); |
print_r(res_stop($at_start)); |