Entity/TagRepository.php
changeset 58 87bf6ec8af90
parent 42 0e57c730bb18
child 59 ea562f37d7a5
equal deleted inserted replaced
57:186c4121c7b3 58:87bf6ec8af90
    56         // We get the wikipedia references for the tag_label
    56         // We get the wikipedia references for the tag_label
    57         // We get or create the tag object
    57         // We get or create the tag object
    58         $tags = $this->findBy(array('normalizedLabel' => $tag_label_normalized));
    58         $tags = $this->findBy(array('normalizedLabel' => $tag_label_normalized));
    59         $tag = null;
    59         $tag = null;
    60         foreach ($tags as $t) {
    60         foreach ($tags as $t) {
    61             if($tag==null || $t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
    61             if($tag==null
       
    62             || $tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['unsemantized']
       
    63             || ($tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['null_result'] && $t->getUrlStatus() !== Tag::$TAG_URL_STATUS_DICT['unsemantized'])) {
    62                 $tag = $t;
    64                 $tag = $t;
    63                 if($t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
    65                 if($tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['unsemantized'] && $tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
    64                     break;
    66                     break;
    65                 }
    67                 }
    66             }
    68             }
    67         }
    69         }
    68         $wp_request_done = false;
    70         $wp_request_done = false;
    73             $tag->setNormalizedLabel($tag_label_normalized);
    75             $tag->setNormalizedLabel($tag_label_normalized);
    74             $created = true;
    76             $created = true;
    75         }
    77         }
    76         else {
    78         else {
    77             $created = false;
    79             $created = false;
    78             $match_exists = false;
       
    79             // Even if a tag with the normalised label exists, IF this tag is not wikipedia semantised,
       
    80             // we search if a wikipedia semantised version exists in the base
       
    81             foreach ($tags as $t) {
       
    82                 if($t->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['match']) {
       
    83                     $tag = $t;
       
    84                     $match_exists = true;
       
    85                     break;
       
    86                 }
       
    87             }
       
    88             if($match_exists==false) {
       
    89                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
       
    90                 $status = $wp_response['status'];
       
    91                 if($status==Tag::$TAG_URL_STATUS_DICT['match']) {
       
    92                     $tag = new Tag();
       
    93                     $tag->setLabel($tag_label_normalized);
       
    94                     $tag->setOriginalLabel($tag_label);
       
    95                     $tag->setNormalizedLabel($tag_label_normalized);
       
    96                     $created = true;
       
    97                     $wp_request_done = true;
       
    98                 }
       
    99             }
       
   100         }
    80         }
   101     
    81     
   102         // We request Wikipedia if the tag is created
    82         // We request Wikipedia if the tag is created or if this is a null result
   103         if($created==true) {
    83         if($created==true || $tag->getUrlStatus()===Tag::$TAG_URL_STATUS_DICT['null_result']) {
   104             
    84             
   105             if($wp_request_done==false) {
    85             if($wp_request_done==false) {
   106                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
    86                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
   107             }
    87             }
   108             
    88