예제 #1
0
function rdfRead($F)
{
    extract($F);
    $fileclean = $file . '_clean';
    #Remove the files
    #$root = ($_REQUEST['root']!='')?$_REQUEST['root']:$argv[4];
    $root = $inputs['root'];
    $inData = $inputs;
    #Before parsing the RDF, remove the files from the document
    #$data = removeFiles($file); ##COMPLETED IN A SEPARATE SCRIPT (momentarily because of segmantation fault)
    $data = fread(fopen($fileclean, 'r+'), filesize($fileclean));
    define("RDFAPI_INCLUDE_DIR", S3DB_SERVER_ROOT . "/pearlib/rdfapi-php/api/");
    include RDFAPI_INCLUDE_DIR . "RdfAPI.php";
    include RDFAPI_INCLUDE_DIR . "syntax/SyntaxN3.php";
    include RDFAPI_INCLUDE_DIR . "syntax/SyntaxRDF.php";
    include S3DB_SERVER_ROOT . '/s3dbcore/rdf.resources.inc.php';
    include S3DB_SERVER_ROOT . '/rdfheader.inc.php';
    extract($resources);
    #Create an RDF model from the raw data
    #echo "Parsing the RDF data".chr(10);
    if (!is_file($file . '_model') || $inputs['clean'] == 1) {
        #$model = ntriples2php($data); ##=> Crashing when the model is too big :-( :-(
        if (filesize($fileclean) < 20000) {
            $model = ntriples2php($data);
        } else {
            #For big files, use the big file library ( which actually is smaller..)
            $model = arc_ntriples2php($fileclean);
            $m = ModelFactory::getDefaultModel();
            if (empty($model)) {
                echo "Your file could not be parsed.";
                exit;
            }
            foreach ($model as $triple) {
                $mS = new Resource($triple['s']);
                $mP = new Resource($triple['p']);
                $mO = $triple['o_type'] == 'literal' ? new Literal($triple['o']) : new Resource($triple['o']);
                $s = new Statement($mS, $mP, $mO);
                $m->add($s);
            }
            $model = $m;
        }
        if (!empty($model)) {
            unlink($fileclean);
        } else {
            echo "Your file seems to be empty.";
            exit;
        }
        $tmp = serialize($model);
        file_put_contents($file . '_model', $tmp);
    } else {
        $model = unserialize(file_get_contents($file . '_model'));
    }
    #Create an S3DB model from the RDF model
    #echo "Building and S3DB structure from the RDF data".chr(10).chr(13);
    if (!is_file($file . '_s3db') || $inputs['clean'] == 1) {
        $s3db = model2deploy($model, $resources, $root, $inData);
        #$s3db = arc_model2deploy($model, $resources, $root, $inData);
        $tmp = serialize($s3db);
        file_put_contents($file . '_s3db', $tmp);
    } else {
        $s3db = unserialize(file_get_contents($file . '_s3db'));
    }
    #include('rdfWrite.php');
    return $s3db;
}
예제 #2
0
파일: rdf.php 프로젝트: helenadeus/s3db.map
 $simileLink = 'http://simile.mit.edu/babel/translator?reader=n3&writer=rdf-xml&mimetype=text%2Fplain&url=' . $filelink;
 $simile = @fopen($simileLink, 'r');
 if (!$simile) {
     echo "Could not connect to the rdf conversion service (http://simile.mit.edu/babel), please make sure you are connected to the internet.";
     exit;
 }
 $translation = stream_get_contents($simile);
 if (ereg('<html>', $translation)) {
     echo "Simile could not convert the file. Please copy the triples on this <a href='" . $filelink . "'>direct link</a> and submit it to <a href='http://simile.mit.edu/babel'>simile</a> for a conversion in your format of choice.";
     exit;
 }
 switch ($inputs['output']) {
     case 'rdf-xml':
         ##Convert the n3 to a model; convert that model into rdf
         include_once S3DB_SERVER_ROOT . '/rdfheader.inc.php';
         $model = ntriples2php($n3);
         $model->saveAs(S3DB_SERVER_ROOT . '/tmp/' . str_replace('.n3', '.rdf', $linkname), 'RDF');
         $filelink = str_replace('.n3', '.rdf', $filelink);
         $simileLink = 'http://simile.mit.edu/babel/translator?reader=n3&writer=rdf-xml&mimetype=text%2Fplain&url=' . $filelink;
         break;
     case 'json':
         $filelink = str_replace('.n3', '.json', $filelink);
         $simileLink = 'http://simile.mit.edu/babel/translator?reader=n3&writer=exhibit-json&mimetype=text%2Fplain&url=' . $filelink;
         break;
     default:
         $filelink = str_replace('.n3', '.rdf', $filelink);
         $simileLink = 'http://simile.mit.edu/babel/translator?reader=n3&writer=rdf-xml&mimetype=text%2Fplain&url=' . $filelink;
         break;
 }
 $simile = @fopen($simileLink, 'r');
 $translation = stream_get_contents($simile);