Utils/WikiTagUtils.php
changeset 32 38dcd2db04e4
parent 22 99c15cfe420b
child 42 0e57c730bb18
equal deleted inserted replaced
31:b910b4f7485f 32:38dcd2db04e4
    36                 if($t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']){
    36                 if($t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']){
    37                     break;
    37                     break;
    38                 }
    38                 }
    39             }
    39             }
    40         }
    40         }
       
    41         $wp_request_done = false;
    41         if($tag==null){
    42         if($tag==null){
    42             $tag = new Tag();
    43             $tag = new Tag();
    43             $tag->setLabel($tag_label_normalized);
    44             $tag->setLabel($tag_label_normalized);
    44             $tag->setOriginalLabel($tag_label);
    45             $tag->setOriginalLabel($tag_label);
    45             $tag->setNormalizedLabel($tag_label_normalized);
    46             $tag->setNormalizedLabel($tag_label_normalized);
    46             $created = true;
    47             $created = true;
    47         }
    48         }
    48         else{
    49         else{
    49             $created = false;
    50             $created = false;
       
    51             $match_exists = false;
       
    52             // Even if a tag with the normalised label exists, IF this tag is not wikipedia semantised,
       
    53             // we search if a wikipedia semantised version exists in the base
       
    54             foreach ($tags as $t){
       
    55                 if($t->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['match']){
       
    56                     $tag = $t;
       
    57                     $match_exists = true;
       
    58                     break;
       
    59                 }
       
    60             }
       
    61             if($match_exists==false){
       
    62                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
       
    63                 $status = $wp_response['status'];
       
    64                 if($status==Tag::$TAG_URL_STATUS_DICT['match']){
       
    65                     $tag = new Tag();
       
    66                     $tag->setLabel($tag_label_normalized);
       
    67                     $tag->setOriginalLabel($tag_label);
       
    68                     $tag->setNormalizedLabel($tag_label_normalized);
       
    69                     $created = true;
       
    70                     $wp_request_done = true;
       
    71                 }
       
    72             }
    50         }
    73         }
    51         
    74         
    52         // We request Wikipedia if the tag is created
    75         // We request Wikipedia if the tag is created
    53         if($created==true){
    76         if($created==true){
    54             $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
    77             if($wp_request_done==false){
       
    78                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
       
    79             }
    55             $new_label = $wp_response['new_label'];
    80             $new_label = $wp_response['new_label'];
    56             $status = $wp_response['status'];
    81             $status = $wp_response['status'];
    57             $url = $wp_response['wikipedia_url'];
    82             $url = $wp_response['wikipedia_url'];
    58             $pageid = $wp_response['pageid'];
    83             $pageid = $wp_response['pageid'];
    59             $dbpedia_uri = $wp_response["dbpedia_uri"];
    84             $dbpedia_uri = $wp_response["dbpedia_uri"];
    81             $wikipedia_revision_id = $wp_response['revision_id'];
   106             $wikipedia_revision_id = $wp_response['revision_id'];
    82         }
   107         }
    83         else{
   108         else{
    84             $wikipedia_revision_id = null;
   109             $wikipedia_revision_id = null;
    85         }
   110         }
    86         //return "coucou4";
       
    87         
   111         
    88         return array($tag, $wikipedia_revision_id, $created);//, $wpReponse);
   112         return array($tag, $wikipedia_revision_id, $created);//, $wpReponse);
    89     }
   113     }
    90     
   114     
    91     /**
   115     /**