Пример #1
0
$delim = "\t";
//csv file delimiter
$lang = "en";
//language to render
$taxonomyFile = "../../factual_taxonomy.json";
//filename and path
$outPutFile = "/tmp/factual_taxonomy.csv";
//output file
//Should not need to edit anything below this line
$taxonomy = json_decode(file_get_contents($taxonomyFile), true);
$iteration = array();
//get information for each node
foreach ($taxonomy as $nodeID => $node) {
    $iteration[$nodeID]['label'] = $taxonomy[$nodeID]['labels'][$lang];
    $iteration[$nodeID]['parents'] = $taxonomy[$nodeID]['parents'];
    $iteration[$nodeID]['ancestors'] = getAncestors($nodeID);
    $iteration[$nodeID]['breadcrumb'] = getBreadCrumb($nodeID);
}
//order by node ID
ksort($iteration);
//render to file
$fp = fopen($outPutFile, 'a');
foreach ($iteration as $nodeID => $node) {
    $line = $nodeID . $delim . $node['label'] . $delim . $node['parents'][0] . $delim . json_encode($node['breadcrumb']) . "\n";
    fwrite($fp, $line);
}
fclose($fp);
//get ancestors
function getAncestors($nodeID)
{
    global $globalParents;
Пример #2
0
function getAncestors(&$base, &$ancestors, $rootId = 0, $withOwn = 0)
{
    global $connectionLink;
    static $deep = 0;
    if ($deep == 0) {
        $ancestors = array();
    }
    if (!isset($base->up)) {
        handleError("up not set in getAncestors!");
    }
    $deep++;
    if ($deep > 10) {
        //too deep, may be error in structure!!!
        Roll::setInfoText("deep_struct");
        $deep--;
        return deep_struct;
    }
    if ($withOwn != 0) {
        $ancestors[] = $base;
    }
    if ($base->up == 0 || $base->up == $rootId) {
        $deep--;
        return ok;
    }
    $className = $base->get_class();
    $a = new $className();
    $a->id = $base->up;
    $ret = $a->load();
    if ($ret == not_found_in_db) {
        //up not found, we are on the top
        $deep--;
        Roll::setInfoText("no_father");
        return no_father;
    }
    if ($ret != ok) {
        $deep--;
        return $ret;
    }
    $ancestors[] = $a;
    if ($a->up == 0 || $a->id == $rootId) {
        $deep--;
        return ok;
    }
    $ret = getAncestors($a, $ancestors, $rootId);
    $deep--;
    return $ret;
}