コード例 #1
0
ファイル: move2s3db.php プロジェクト: helenadeus/s3db.map
function findUpdates1($fileOld, $fileNew)
{
    ###
    #parse the local doc
    $rdfmodel = rdf2php($fileOld);
    ###
    ##find every doc and put it in an array with data
    $sparql = 'SELECT ?file ?date ?path WHERE {?file <http://purl.org/dc/elements/1.1/date> ?date . 
	?file <http://s3db.org/scripts> ?path .}';
    $subset = $rdfmodel->sparqlQuery($sparql);
    $files = pushURI($subset, '?path', 'label');
    $dates = pushURI($subset, '?date', 'label');
    $local = array_combine($files, $dates);
    ###
    ##find all the remote docs
    $rssUrl = $fileNew;
    #$rssUrl= 'extras/updates.rdf'; =>testnig it with the same file to make sure the questions are returning valid responses
    $newRSS = @fopen($rssUrl, 'r');
    $remote = @stream_get_contents($newRSS);
    $remotemodel = rdf2php($rssUrl);
    $subset = $remotemodel->sparqlQuery($sparql);
    $files = pushURI($subset, '?path', 'label');
    $dates = pushURI($subset, '?date', 'label');
    $remote = array_combine($files, $dates);
    #echo '<pre>';print_r($remote);exit;
    #echo '<pre>';print_r(array_filter($local));
    ###
    #ask questions
    #question 1: nr remote > nr local?
    if (count(array_filter($remote)) > count(array_filter($local))) {
        #then list all missing
        $missing = array_diff_key($remote, $local);
    }
    #question 2: of the existing local files, is there any that is more ancient that the corresponding remote?
    foreach ($local as $filepath => $date) {
        if (strtotime($remote[$filepath]) > strtotime($local[$filepath])) {
            $missing[$filepath] = $remote[$filepath];
        }
    }
    return $missing;
}
コード例 #2
0
ファイル: sparql_read.php プロジェクト: helenadeus/s3db.map
function buildAndExecuteQ($b)
{
    extract($b);
    $q = array();
    $ans = array();
    $queryModel = $model;
    foreach ($from as $e) {
        $tri_s3ql = $s3ql;
        $tri_s3ql['select'] = '*';
        $tri_s3ql['from'] = switchFromCore($e);
        if (!is_array($where[$e]) || empty($where[$e])) {
            if ($tri_s3ql['url']) {
                $tri_s3ql['format'] = 'rdf';
                $query = S3QLQuery($tri_s3ql);
                $rQ[] = $query;
            } else {
                $start = strtotime('His');
                $lQ[] = $tri_s3ql;
            }
        } else {
            for ($i = 0; $i < count($where[$e]); $i++) {
                $tmp = $where[$e][$i];
                $ind = $i;
                if ($tmp) {
                    $tri_s3ql['where'] = $tmp;
                }
                #again... efficiency
                if ($tri_s3ql['url']) {
                    $tri_s3ql['format'] = 'rdf';
                    $query = S3QLQuery($tri_s3ql);
                    $rQ[] = $query;
                } else {
                    $start = strtotime('His');
                    $lQ[] = $tri_s3ql;
                }
            }
        }
    }
    if (is_array($lQ)) {
        foreach ($lQ as $localQuery) {
            $answer = localQ($tri_s3ql);
            if (!empty($answer)) {
                $rdfanswer = rdf2php($answer);
                #Line up the answer with the model
                $queryModel->addModel($rdfanswer);
            }
        }
    }
    if (is_array($rQ)) {
        foreach ($rQ as $remoteQuery) {
            $answer = remoteQ($q);
            if (!empty($answer)) {
                $rdfanswer = rdf2php($answer);
                #Line up the answer with the model
                $queryModel->addModel($rdfanswer);
            }
        }
    }
    return $queryModel;
    #$t is the array with the vars that were discovered in this triple
}
コード例 #3
0
ファイル: sparql2s3db.php プロジェクト: helenadeus/s3db.map
//	   ?R rdf:type s3db:s3dbRule .
//	   ?R rdfs:label ?Rlabel .
//	   ?R rdf:subject :C186 .}
//
//";
$sparql = $in['sparql'] == '' ? $mysparql : urldecode($in['sparql']);
##Interpret the query
$parsed = s3db_parse($sparql);
exit;
$out = $in['format'] == '' ? 'HTML' : strtoupper($in['format']);
##serialize the data so that is does not take very long to re-load it
$filename = md5($rdf);
$file_place = $GLOBALS['uploads'] . '/';
if (!is_file($file_place . $filename)) {
    #read the data into a model
    $model = rdf2php($rdf);
    if ($model == '') {
        echo "dataset could not be parsed";
    } else {
        $s_model = serialize($model);
        file_put_contents($file_place . $filename, $s_model);
    }
} else {
    $model = file_get_contents($file_place . $filename);
    $model = unserialize($model);
}
#echo '<pre>';print_r($model);
if (!$in['no_color']) {
    echo '
<html>
<head>