equal
deleted
inserted
replaced
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 try { |
|
90 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
|
91 } |
|
92 catch (\Exception $e){ |
|
93 throw new \Exception($e->getMessage()); |
|
94 } |
|
95 $status = $wp_response['status']; |
|
96 if($status==Tag::$TAG_URL_STATUS_DICT['match']) { |
|
97 $tag = new Tag(); |
|
98 $tag->setLabel($tag_label_normalized); |
|
99 $tag->setOriginalLabel($tag_label); |
|
100 $tag->setNormalizedLabel($tag_label_normalized); |
|
101 $created = true; |
|
102 $wp_request_done = true; |
|
103 } |
|
104 } |
|
105 } |
80 } |
106 |
81 |
107 // We request Wikipedia if the tag is created |
82 // We request Wikipedia if the tag is created or if this is a null result |
108 if($created==true) { |
83 if($created==true || $tag->getUrlStatus()===Tag::$TAG_URL_STATUS_DICT['null_result']) { |
109 |
84 |
110 if($wp_request_done==false) { |
85 if($wp_request_done==false) { |
111 try { |
86 try { |
112 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
87 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
113 } |
88 } |
140 } |
115 } |
141 |
116 |
142 return array($tag, $wikipedia_revision_id, $created);//, $wpReponse); |
117 return array($tag, $wikipedia_revision_id, $created);//, $wpReponse); |
143 } |
118 } |
144 |
119 |
145 |
|
146 } |
120 } |