function getGEXFtimeseries($filename, $series) { include_once 'common/Gexf.class.php'; $gexf = new Gexf(); $gexf->setTitle("Co-word " . $filename); $gexf->setEdgeType(GEXF_EDGE_UNDIRECTED); $gexf->setMode(GEXF_MODE_DYNAMIC); $gexf->setTimeFormat(GEXF_TIMEFORMAT_DATE); $gexf->setCreator("tools.digitalmethods.net"); foreach ($series as $time => $cw) { $w = $cw->getWords(); $cw = $cw->getCowords(); foreach ($cw as $word => $cowords) { foreach ($cowords as $coword => $coword_frequency) { $node1 = new GexfNode($word); if (isset($w[$word])) { $node1->addNodeAttribute("word_frequency", $w[$word], $type = "int"); } $gexf->addNode($node1); //if ($documentsPerWords[$word] > $threshold) // $node1->setNodeColor(0, 255, 0, 0.75); $gexf->nodeObjects[$node1->id]->addNodeSpell($time, $time); $node2 = new GexfNode($coword); if (isset($w[$coword])) { $node2->addNodeAttribute("word_frequency", $w[$word], $type = "int"); } $gexf->addNode($node2); //if ($documentsPerWords[$coword] > $threshold) // $node2->setNodeColor(0, 255, 0, 0.75); $gexf->nodeObjects[$node2->id]->addNodeSpell($time, $time); $edge_id = $gexf->addEdge($node1, $node2, $coword_frequency); $gexf->edgeObjects[$edge_id]->addEdgeSpell($time, $time); } } } $gexf->render(); file_put_contents($filename, $gexf->gexfFile); echo '<fieldset class="if_parameters">'; echo '<legend>Your co-hashtag time-series File</legend>'; echo '<p><a href="' . filename_to_url($filename) . '">' . $filename . '</a></p>'; echo '</fieldset>'; }
function getCowordsAsGexf($title = "") { include_once 'Gexf.class.php'; $gexf = new Gexf(); $gexf->setTitle("Co-word " . $title); $gexf->setEdgeType(GEXF_EDGE_UNDIRECTED); $gexf->setMode(GEXF_MODE_DYNAMIC); $gexf->setTimeFormat(GEXF_TIMEFORMAT_DATE); $gexf->setCreator("tools.digitalmethods.net"); foreach ($this->cowords as $word => $cowords) { if (empty($cowords)) { $node1 = new GexfNode($word); if (isset($this->words[$word])) { $node1->addNodeAttribute("word_frequency", $this->words[$word], $type = "int"); } $this->addNodeExtraNodeAttributes($node1, $word); $gexf->addNode($node1); } else { foreach ($cowords as $coword => $coword_frequency) { $node1 = new GexfNode($word); if (isset($this->words[$word])) { $node1->addNodeAttribute("word_frequency", $this->words[$word], $type = "int"); } $this->addNodeExtraNodeAttributes($node1, $word); $gexf->addNode($node1); $node2 = new GexfNode($coword); if (isset($this->words[$coword])) { $node2->addNodeAttribute("word_frequency", $this->words[$coword], $type = "int"); } $this->addNodeExtraNodeAttributes($node2, $coword); $gexf->addNode($node2); $edge_id = $gexf->addEdge($node1, $node2, $coword_frequency); } } } $gexf->render(); return $gexf->gexfFile; }
include "conf.php"; // prepare term $term = urlencode($term); $term = preg_replace("/[^a-zA-Z.]/", "", $term); $folder = getcwd() . "/json_" . $term; $list = scandir($folder); // shave off . and .. array_shift($list); array_shift($list); // initialize gexf object $gexf = new Gexf(); $gexf->setTitle("NY Times Categories"); $gexf->setEdgeType(GEXF_EDGE_UNDIRECTED); $gexf->setMode(GEXF_MODE_STATIC); $gexf->setTimeFormat(GEXF_TIMEFORMAT_DATE); $gexf->setCreator("polsys.net"); // iterate over all JSON files foreach ($list as $fn) { $json = file_get_contents($folder . "/" . $fn); $json = json_decode($json); // iterate over keyword matrix (half) for ($i = 0; $i < count($json->keywords); $i++) { $node1 = new GexfNode(strtolower($json->keywords[$i]->value)); $node1->addNodeAttribute("type", $json->keywords[$i]->name, $type = "string"); $gexf->addNode($node1); for ($j = $i; $j < count($json->keywords); $j++) { $node2 = new GexfNode(strtolower($json->keywords[$j]->value)); $node2->addNodeAttribute("type", $json->keywords[$j]->name, $type = "string"); $gexf->addNode($node2); if (strtolower($json->keywords[$i]->value) != strtolower($json->keywords[$j]->value)) { $gexf->addEdge($node1, $node2);
$sql .= sqlSubset($where); $sqlresults = mysql_unbuffered_query($sql); while ($res = mysql_fetch_assoc($sqlresults)) { $res['source'] = preg_replace("/<.+>/U", "", $res['source']); $res['source'] = preg_replace("/[ \\s\t]+/", " ", $res['source']); $res['source'] = trim($res['source']); if (!isset($sourcesHashtags[$res['source']][$res['hashtag']])) { $sourcesHashtags[$res['source']][$res['hashtag']] = 0; } $sourcesHashtags[$res['source']][$res['hashtag']]++; } mysql_free_result($sqlresults); $gexf = new Gexf(); $gexf->setTitle("source-hashtag " . $filename); $gexf->setEdgeType(GEXF_EDGE_UNDIRECTED); $gexf->setCreator("tools.digitalmethods.net"); foreach ($sourcesHashtags as $source => $hashtags) { foreach ($hashtags as $hashtag => $frequency) { $node1 = new GexfNode($source); $node1->addNodeAttribute("type", 'source', $type = "string"); $gexf->addNode($node1); $node2 = new GexfNode($hashtag); $node2->addNodeAttribute("type", 'hashtag', $type = "string"); $gexf->addNode($node2); $edge_id = $gexf->addEdge($node1, $node2, $frequency); } } $gexf->render(); file_put_contents($filename, $gexf->gexfFile); echo '<fieldset class="if_parameters">'; echo '<legend>Your network (GEXF) file</legend>';