From: <jen...@us...> - 2008-10-27 09:36:28
|
Revision: 1441 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1441&view=rev Author: jenslehmann Date: 2008-10-27 09:32:07 +0000 (Mon, 27 Oct 2008) Log Message: ----------- continued city template Modified Paths: -------------- trunk/src/dbpedia-navigator/Settings.php.dist trunk/src/dbpedia-navigator/templates/AbstractTemplate.php trunk/src/dbpedia-navigator/templates/CityTemplate.php Added Paths: ----------- trunk/src/dbpedia-navigator/templates/PlaceTemplate.php trunk/src/dbpedia-navigator/templates/PopulatedPlaceTemplate.php Modified: trunk/src/dbpedia-navigator/Settings.php.dist =================================================================== --- trunk/src/dbpedia-navigator/Settings.php.dist 2008-10-27 09:28:53 UTC (rev 1440) +++ trunk/src/dbpedia-navigator/Settings.php.dist 2008-10-27 09:32:07 UTC (rev 1441) @@ -40,6 +40,8 @@ public $endpoint="DBPEDIA"; //public $endpoint="LOCALDBPEDIA"; + public $dbpediaPropertyPrefix = 'http://dbpedia.org/ontology/'; + public $dbpediaClassPrefix = 'http://dbpedia.org/ontology/'; // in mikrosekunden public $sparqlttl=60000000; Modified: trunk/src/dbpedia-navigator/templates/AbstractTemplate.php =================================================================== --- trunk/src/dbpedia-navigator/templates/AbstractTemplate.php 2008-10-27 09:28:53 UTC (rev 1440) +++ trunk/src/dbpedia-navigator/templates/AbstractTemplate.php 2008-10-27 09:32:07 UTC (rev 1441) @@ -32,6 +32,31 @@ abstract function printTemplate($triples); + // utility method, which checks whether the given DBpedia ontology properties exists in the triples + // is they exist, the method returns true and false otherwise; + // TODO: use $dbpediaOntologyPrefix in $settings (how do we access those settings in all scripts?) + function areDBpediaPropertiesSet($triples, $properties) { + foreach($properties as $property) { + if(!isset($triples['http://dbpedia.org/ontology/'.$property])) { + return false; + } + } + return true; + } + + // gets the value of the property + function getPropValue($triples, $property) { + return $triples['http://dbpedia.org/ontology/'.$property]; + } + + // gets the value of the property and removes it from the triple array + // (this means you cannot access this information anymore afterwards) + function extractPropValue($triples, $property) { + $value = $triples['http://dbpedia.org/ontology/'.$property]; + unset($triples['http://dbpedia.org/ontology/'.$property]); + return $value; + } + } ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/templates/CityTemplate.php =================================================================== --- trunk/src/dbpedia-navigator/templates/CityTemplate.php 2008-10-27 09:28:53 UTC (rev 1440) +++ trunk/src/dbpedia-navigator/templates/CityTemplate.php 2008-10-27 09:32:07 UTC (rev 1441) @@ -24,15 +24,15 @@ * * @author Jens Lehmann */ -class CityTemplate { +class CityTemplate extends PopulatedPlaceTemplate { function getTemplate($triples) { $content = ""; + $content .= '<table>'; + $content .= '<tr><td colspan="2">City Information</td></tr>'; + $content .= '<tr><td>total population</td><td>' + getPopulationString($triples) + '</td></tr>'; + $content .= '</table>'; - $latitude = $triples['http://dbpedia.org/ontology/latitutedegrees'] + "° " - + $triples['http://dbpedia.org/ontology/latitudeminutes'] + "′" - + $triples['http://dbpedia.org/ontology/latitudeseconds'] + "″N"; - // .. continue ... return $content; Added: trunk/src/dbpedia-navigator/templates/PlaceTemplate.php =================================================================== --- trunk/src/dbpedia-navigator/templates/PlaceTemplate.php (rev 0) +++ trunk/src/dbpedia-navigator/templates/PlaceTemplate.php 2008-10-27 09:32:07 UTC (rev 1441) @@ -0,0 +1,59 @@ +<?php +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Abstract template class. Templates are used for displaying information + * about a particular entity in a user friendly way. + * + * You can also use this class for convenience functions accessible by + * all concrete templates. + * + * @author Jens Lehmann + */ +abstract class PlaceTemplate extends AbstractTemplate { + + // returns a latitude string of the form 49°1′0″N or "unknown" + public getLatitudeString($triples) { + if(!areDBpediaPropertiesSet(array('latitudedegrees','latitudeminutes','latitudeseconds'))) { + return "unknown"; + } + + $latitude = $triples['http://dbpedia.org/ontology/latitutedegrees'] + "° " + + $triples['http://dbpedia.org/ontology/latitudeminutes'] + "′" + + $triples['http://dbpedia.org/ontology/latitudeseconds'] + "″N"; + return $latitude; + } + + // returns a latitude string of the form 49°1′0″E or "unknown" + public getLongitudeString($triples) { + if(!areDBpediaPropertiesSet(array('longitudedegrees','longitudeminutes','longitudeseconds'))) { + return "unknown"; + } + + $longitude = $triples['http://dbpedia.org/ontology/longitutedegrees'] + "° " + + $triples['http://dbpedia.org/ontology/longitudeminutes'] + "′" + + $triples['http://dbpedia.org/ontology/longitudeseconds'] + "″N"; + return $longitude; + } + +} + +?> \ No newline at end of file Added: trunk/src/dbpedia-navigator/templates/PopulatedPlaceTemplate.php =================================================================== --- trunk/src/dbpedia-navigator/templates/PopulatedPlaceTemplate.php (rev 0) +++ trunk/src/dbpedia-navigator/templates/PopulatedPlaceTemplate.php 2008-10-27 09:32:07 UTC (rev 1441) @@ -0,0 +1,36 @@ +<?php +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Template for all populated places. + */ +abstract class PopulatedPlaceTemplate extends PlaceTemplate { + + // return a nicely formatted string for the population of the place + public getPopulationString() { + $number = number_format(extractPropValue('populationTotal')); + $asOf = extractPropValue('populationAsOf'); + + return $number + ' (as of ' + $asOf + ')'; + } + +} +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |