Ejemplo n.º 1
0
// using Erik Borra's very useful Gexf class
require_once "Gexf.class.php";
// search query and api key are in:
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");
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>';
}
Ejemplo n.º 3
0
 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;
 }