Esempio n. 1
0
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);
            }
        }
    }
}
$gexf->render();
file_put_contents(getcwd() . "/data_" . $term . ".gexf", $gexf->gexfFile);
echo "done";
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>';
}
Esempio 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;
 }
Esempio n. 4
0
    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>';
echo '<p><a href="' . filename_to_url($filename) . '">' . $filename . '</a></p>';
echo '</fieldset>';
?>

    </body>
</html>
Esempio n. 5
0
$gexf->setTitle("Hashtag - user " . $filename);
$gexf->setEdgeType(GEXF_EDGE_UNDIRECTED);
$gexf->setCreator("tools.digitalmethods.net");
foreach ($userHashtags as $user => $hashtags) {
    foreach ($hashtags as $hashtag => $frequency) {
        $node1 = new GexfNode($user);
        $node1->id = md5('n-user_' . $user);
        $node1->addNodeAttribute("type", 'user', $type = "string");
        $node1->addNodeAttribute("userFrequency", $userCount[$user], $type = "int");
        $node1->addNodeAttribute("hashtagFrequency", 0, $type = "int");
        $node1->addNodeAttribute("language", $languages[$user], $type = "string");
        $node1->addNodeAttribute("location", $locations[$user], $type = "string");
        $node1->addNodeAttribute("from_user_utcoffset", $from_user_utcoffset[$user], $type = "string");
        $node1->addNodeAttribute("from_user_timezone", $from_user_timezone[$user], $type = "string");
        $gexf->addNode($node1);
        $node2 = new GexfNode($hashtag);
        $node2->id = md5('n-hashtag_' . $hashtag);
        $node2->addNodeAttribute("type", 'hashtag', $type = "string");
        $node2->addNodeAttribute("userFrequency", 0, $type = "int");
        $node2->addNodeAttribute("hashtagFrequency", $hashtagCount[$hashtag], $type = "int");
        $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 GEXF File</legend>';
echo '<p><a href="' . filename_to_url($filename) . '">' . $filename . '</a></p>';
echo '</fieldset>';
?>
Esempio n. 6
0
}
$gexf = new Gexf();
$gexf->setTitle("URL-user " . $filename);
$gexf->setEdgeType(GEXF_EDGE_UNDIRECTED);
$gexf->setCreator("tools.digitalmethods.net");
foreach ($urlUsernames as $url => $usernames) {
    foreach ($usernames as $username => $frequency) {
        $node1 = new GexfNode($url);
        $node1->addNodeAttribute("type", 'url', $type = "string");
        $node1->addNodeAttribute('shortlabel', $urlDomain[$url], $type = "string");
        $node1->addNodeAttribute('longlabel', $url, $type = "string");
        $node1->addNodeAttribute('status_code', $urlStatusCode[$url], $type = "string");
        $node1->addNodeAttribute('unique_users', $urlUniqueUsers[$url], $type = "integer");
        $node1->addNodeAttribute('total_users', $urlTotalUsers[$url], $type = "integer");
        $gexf->addNode($node1);
        $node2 = new GexfNode($username);
        $node2->addNodeAttribute("type", 'user', $type = "string");
        $node2->addNodeAttribute('shortlabel', $username, $type = "string");
        $node2->addNodeAttribute('longlabel', $username, $type = "string");
        $node2->addNodeAttribute('unique_urls', $userUniqueUrls[$username], $type = "integer");
        $node2->addNodeAttribute('total_urls', $userTotalUrls[$username], $type = "integer");
        $gexf->addNode($node2);
        $edge_id = $gexf->addEdge($node1, $node2, $frequency);
    }
}
$gexf->render();
$filename = get_filename_for_export("urlUser", '', 'gexf');
file_put_contents($filename, $gexf->gexfFile);
echo '<fieldset class="if_parameters">';
echo '<legend>Your network (GEXF) file</legend>';
echo '<p><a href="' . filename_to_url($filename) . '">' . $filename . '</a></p>';
Esempio n. 7
0
echo '<fieldset class="if_parameters">';
echo '<legend>Your spreadsheet (CSV) file</legend>';
echo '<p><a href="' . str_replace("#", urlencode("#"), str_replace("\"", "%22", $filename)) . '">' . $filename . '</a></p>';
echo '</fieldset>';
$gexf = new Gexf();
$gexf->setTitle("URL-hashtag " . $filename);
$gexf->setEdgeType(GEXF_EDGE_UNDIRECTED);
$gexf->setCreator("tools.digitalmethods.net");
foreach ($urlHashtags as $url => $hashtags) {
    foreach ($hashtags as $hashtag => $frequency) {
        $node1 = new GexfNode($url);
        $node1->addNodeAttribute("type", 'url', $type = "string");
        $node1->addNodeAttribute('shortlabel', $urlDomain[$url], $type = "string");
        $node1->addNodeAttribute('status_code', $urlStatusCode[$url], $type = "string");
        $gexf->addNode($node1);
        $node2 = new GexfNode($hashtag);
        $node2->addNodeAttribute("type", 'hashtag', $type = "string");
        $node2->addNodeAttribute('shortlabel', $hashtag, $type = "string");
        $gexf->addNode($node2);
        $edge_id = $gexf->addEdge($node1, $node2, $frequency);
    }
}
$gexf->render();
$filename = get_filename_for_export("urlHashtag", '', 'gexf');
file_put_contents($filename, $gexf->gexfFile);
echo '<fieldset class="if_parameters">';
echo '<legend>Your network (GEXF) file</legend>';
echo '<p><a href="' . filename_to_url($filename) . '">' . $filename . '</a></p>';
echo '</fieldset>';
?>