server/src/app/Services/GeonamesResolver.php
changeset 308 e032d686d88e
parent 304 20071981ba2a
child 550 fbd1bfc9f963
equal deleted inserted replaced
307:07b44a378ad8 308:e032d686d88e
    63         }
    63         }
    64 
    64 
    65         $label = isset($labels['fr']) ? $labels['fr'] : ( isset($labels[''])? $labels['']: null) ;
    65         $label = isset($labels['fr']) ? $labels['fr'] : ( isset($labels[''])? $labels['']: null) ;
    66 
    66 
    67         if(is_null($label)) {
    67         if(is_null($label)) {
    68             $labelLit = $graph->getLiteral("<$url>", "<http://www.geonames.org/ontology#name>");            
    68             $labelLit = $graph->getLiteral("<$url>", "<http://www.geonames.org/ontology#name>");
    69             $label = (!is_null($labelLit)) ? $labelLit->getValue() : null;
    69             $label = (!is_null($labelLit)) ? $labelLit->getValue() : null;
    70         }
    70         }
    71 
    71 
    72         return $label;
    72         return $label;
    73     }
    73     }
    84      * @param string $id The id to resolve. Can be an url starting with http://sws.geonames.org/
    84      * @param string $id The id to resolve. Can be an url starting with http://sws.geonames.org/
    85      * @return a string with the name
    85      * @return a string with the name
    86      */
    86      */
    87     public function getLabel($id) {
    87     public function getLabel($id) {
    88         $geonamesid = $id;
    88         $geonamesid = $id;
    89         if(strpos($id, config('corpusparole.geonames_base_url')) === 0) {
    89         $matches = [];
    90             $geonamesid = substr($id, strlen(config('corpusparole.geonames_base_url')));
    90         if( preg_match(config('corpusparole.geonames_url_regexp'), $id, $matches) === 1) {
       
    91             $geonamesid = $matches[1];
    91         }
    92         }
    92         $geonamesid = rtrim($geonamesid, '/');
    93         $geonamesid = rtrim($geonamesid, '/');
    93 
    94 
    94         if(!$this->checkGeonamesIdFormat($geonamesid)) {
    95         if(!$this->checkGeonamesIdFormat($geonamesid)) {
    95             throw new GeonamesResolverException("GeonamesId not in correct format", 400);
    96             throw new GeonamesResolverException("GeonamesId not in correct format", 400);