Example #1
0
<?php

include "config.inc.php";
include "common.php";
/**
 * @author   Christian Becker
 */
$fhandle = fopen("photoCollections.nt", "w");
$conn = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, true);
mysql_select_db(MYSQL_DB, $conn);
mysql_query("SET NAMES utf8", $conn);
$res = mysql_query("select page_title from page where (page_namespace = 0) and page_is_redirect = 0", $conn);
$ctr = 0;
while ($row = mysql_fetch_assoc($res)) {
    /* Output as N-Triples */
    if ($resource = wikipediaEncode($row['page_title'])) {
        fwrite($fhandle, "<" . DBPEDIA_URI_ROOT . $resource . "> ");
        fwrite($fhandle, "<http://dbpedia.org/property/hasPhotoCollection> ");
        fwrite($fhandle, "<" . FLICKRWRAPPR_PHOTOS_DOC_URI_ROOT . $resource . "> .\n");
    }
    if (++$ctr % 1000 == 0) {
        echo $ctr . "\n";
    }
}
fclose($fhandle);
Example #2
0
function geoLookup($lat, $long, $radius, &$resultsLabel)
{
    global $FLICKRSERVICE;
    $resURI = DBPEDIA_URI_ROOT . wikipediaEncode($_REQUEST['item']);
    $locationURI = FLICKRWRAPPR_LOCATION_URI_ROOT . $_REQUEST['lat'] . '/' . $_REQUEST['long'] . '/' . $_REQUEST['radius'];
    $dataURI = FLICKRWRAPPR_LOCATION_DATA_URI_ROOT . $_REQUEST['lat'] . '/' . $_REQUEST['long'] . '/' . $_REQUEST['radius'];
    /* Initialize result model */
    $resultModel = new MemModel();
    $resultModel->addNamespace('foaf', 'http://xmlns.com/foaf/0.1/');
    $resultModel->addNamespace('dcterms', 'http://purl.org/dc/terms/');
    $resultModel->addNamespace('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
    //$resultModel->addNamespace('geonames', 'http://www.geonames.org/ontology#');
    $resultModel->addNamespace('geo', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
    $resultModel->addNamespace('georss', 'http://www.georss.org/georss/');
    /* Perform flickr search */
    $flickrPhotos = $FLICKRSERVICE->getFlickrPhotos('', $lat, $long, $radius / 1000);
    /* Process found photos */
    foreach ($flickrPhotos as $flickrPhoto) {
        /* Provide the picture itself (small version) */
        $resultModel->add(new Statement(new Resource($locationURI), new Resource("http://xmlns.com/foaf/0.1/depiction"), new Resource($flickrPhoto['imgsmall'])));
        /* Provide its page on flickr */
        $resultModel->add(new Statement(new Resource($flickrPhoto['imgsmall']), new Resource("http://xmlns.com/foaf/0.1/page"), new Resource($flickrPhoto['flickrpage'])));
    }
    if ($resultModel->size() > 0) {
        /* Add metadata for location */
        $resultModel->add(new Statement(new Resource($locationURI), new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new Resource("http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing")));
        $latLiteral = new Literal($lat);
        $latLiteral->setDatatype("http://www.w3.org/2001/XMLSchema#float");
        $resultModel->add(new Statement(new Resource($locationURI), new Resource("http://www.w3.org/2003/01/geo/wgs84_pos#lat"), $latLiteral));
        $longLiteral = new Literal($long);
        $longLiteral->setDatatype("http://www.w3.org/2001/XMLSchema#float");
        $resultModel->add(new Statement(new Resource($locationURI), new Resource("http://www.w3.org/2003/01/geo/wgs84_pos#long"), $longLiteral));
        $radiusLiteral = new Literal($radius);
        $radiusLiteral->setDatatype("http://www.w3.org/2001/XMLSchema#double");
        $resultModel->add(new Statement(new Resource($locationURI), new Resource("http://www.georss.org/georss/radius"), $radiusLiteral));
        /* Add metadata for document */
        $resultModel->add(new Statement(new Resource($dataURI), new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), new Resource("http://xmlns.com/foaf/0.1/Document")));
        $resultsLabel = "Photos taken within {$radius} meters of geographic location lat={$lat} long={$long}";
        $resultModel->add(new Statement(new Resource($dataURI), new Resource("http://www.w3.org/2000/01/rdf-schema#label"), new Literal($resultsLabel, "en")));
        $resultModel->add(new Statement(new Resource($dataURI), new Resource("http://xmlns.com/foaf/0.1/primaryTopic"), new Resource($locationURI)));
        $resultModel->add(new Statement(new Resource($dataURI), new Resource("http://purl.org/dc/terms/license"), new Resource(FLICKR_TOS_URL)));
        $resultModel->add(new Statement(new Resource($dataURI), new Resource("http://xmlns.com/foaf/0.1/maker"), new Resource(FLICKRWRAPPR_HOMEPAGE)));
        $resultModel->add(new Statement(new Resource(FLICKRWRAPPR_HOMEPAGE), new Resource("http://www.w3.org/2000/01/rdf-schema#label"), new Literal("flickr(tm) wrappr", "en")));
    }
    return $resultModel;
}