--- a/Command/QueryWikipediaCommand.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Command/QueryWikipediaCommand.php Thu Dec 08 23:48:55 2011 +0100
@@ -41,8 +41,9 @@
$this
->setName('wikitag:query-wikipedia')
->setDescription('Query wikipedia for tags.')
- ->addOption("force","f",InputOption::VALUE_NONE, "Force remove tags")
- ->addOption("all","a",InputOption::VALUE_NONE, "all")
+ ->addOption("force","f",InputOption::VALUE_NONE, "Force processing tags, will ask no confirmation")
+ ->addOption("all","a",InputOption::VALUE_NONE, "Search all tags")
+ ->addOption("null","n",InputOption::VALUE_NONE, "Treat only non processed tags")
->addOption("redirection",null,InputOption::VALUE_NONE, "Treat redirections")
->addOption("random","r",InputOption::VALUE_NONE, "randomize query on tags")
->addOption("site","S",InputOption::VALUE_OPTIONAL, "the url for the wikipedia site", "http://fr.wikipedia.org/w/api.php")
@@ -60,6 +61,7 @@
$site = $input->getOption('site');
$limit = intval($input->getOption('limit'));
$start = intval($input->getOption('start'));
+ $null = $input->getOption('null');
$doctrine = $this->getContainer()->get('doctrine');
$qb = $doctrine->getEntityManager()->createQueryBuilder();
@@ -72,8 +74,11 @@
if($redirection) {
$qb->where($qb->expr()->andx($qb->expr()->eq("t.urlStatus",Tag::$TAG_URL_STATUS_DICT['redirection']), $qb->expr()->isNull("t.alternativeLabel")));
}
+ elseif($null) {
+ $qb->where($qb->expr()->isNull("t.urlStatus"));
+ }
else {
- $qb->where($qb->expr()->isNull("t.urlStatus"));
+ $qb->where($qb->expr()->orx($qb->expr()->isNull("t.urlStatus"), $qb->expr()->eq("t.urlStatus", Tag::$TAG_URL_STATUS_DICT['null_result'])));
}
}
--- a/Controller/WikiTagController.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Controller/WikiTagController.php Thu Dec 08 23:48:55 2011 +0100
@@ -312,17 +312,21 @@
$id_doc = $this->getRequest()->request->get('wikitag_document_id');
$id_tag = $this->getRequest()->request->get('tag_id');
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
- //return new Response(var_dump(array($tag)));
- // We search if the unsemantized version of the tag already exist.
- $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result']));
+
$em = $this->getDoctrine()->getEntityManager();
- $un_tag_created = FALSE;
+ $query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.label = :label AND (t.urlStatus = :status_null OR t.urlStatus = :status_unsemantized)");
+ $query->setParameters(array("label"=>$tag->getLabel(),"status_null"=>Tag::$TAG_URL_STATUS_DICT['null_result'],"status_unsemantized"=>Tag::$TAG_URL_STATUS_DICT['unsemantized']));
+ $un_tag = null;
+ $un_tags = $query->getResult();
+ if(count($un_tags)>0) {
+ $un_tag = $un_tags[0];
+ }
+ $un_tag_created = false;
if(!$un_tag){
// Create another tag almost identical, without the W info
$un_tag = new Tag();
$un_tag->setLabel($tag->getLabel());
$un_tag->setOriginalLabel($tag->getOriginalLabel());
- $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']);
$un_tag->setWikipediaUrl(null);
$un_tag->setWikipediaPageId(null);
$un_tag->setAlternativeWikipediaUrl(null);
@@ -332,9 +336,18 @@
$un_tag->setCategory($tag->getCategory());
$un_tag->setAlias($tag->getAlias());
$un_tag->setPopularity($tag->getPopularity());
- $em->persist($un_tag);
+ $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
$un_tag_created = true;
+ $em->persist($un_tag);
}
+ elseif($un_tag->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['null_result'])
+ {
+ $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
+ $un_tag_created = true;
+ $em->persist($un_tag);
+ }
+
+
if($id_doc && $id_doc!=""){
// We associate the unsemantized tag to the DocumentTag and save datas
@@ -345,7 +358,7 @@
}
else{
// Here we are in the context of tag list.
- if($un_tag_created==TRUE){
+ if($un_tag_created==true){
$em->flush();
$num_page = $this->getRequest()->request->get('num_page');
$nb_by_page = $this->getRequest()->request->get('nb_by_page');
@@ -533,7 +546,8 @@
$searched = $this->getRequest()->request->get('searched');
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
}
-
+
+
/**
*
* Resemantize the tag with its original label. Kind of undo if we changed the tag's label.
--- a/Entity/TagRepository.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Entity/TagRepository.php Thu Dec 08 23:48:55 2011 +0100
@@ -58,9 +58,11 @@
$tags = $this->findBy(array('normalizedLabel' => $tag_label_normalized));
$tag = null;
foreach ($tags as $t) {
- if($tag==null || $t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
+ if($tag==null
+ || $tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['unsemantized']
+ || ($tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['null_result'] && $t->getUrlStatus() !== Tag::$TAG_URL_STATUS_DICT['unsemantized'])) {
$tag = $t;
- if($t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
+ if($tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['unsemantized'] && $tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
break;
}
}
@@ -75,32 +77,10 @@
}
else {
$created = false;
- $match_exists = false;
- // Even if a tag with the normalised label exists, IF this tag is not wikipedia semantised,
- // we search if a wikipedia semantised version exists in the base
- foreach ($tags as $t) {
- if($t->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['match']) {
- $tag = $t;
- $match_exists = true;
- break;
- }
- }
- if($match_exists==false) {
- $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
- $status = $wp_response['status'];
- if($status==Tag::$TAG_URL_STATUS_DICT['match']) {
- $tag = new Tag();
- $tag->setLabel($tag_label_normalized);
- $tag->setOriginalLabel($tag_label);
- $tag->setNormalizedLabel($tag_label_normalized);
- $created = true;
- $wp_request_done = true;
- }
- }
}
- // We request Wikipedia if the tag is created
- if($created==true) {
+ // We request Wikipedia if the tag is created or if this is a null result
+ if($created==true || $tag->getUrlStatus()===Tag::$TAG_URL_STATUS_DICT['null_result']) {
if($wp_request_done==false) {
$wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
--- a/Model/Document.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Model/Document.php Thu Dec 08 23:48:55 2011 +0100
@@ -74,7 +74,7 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.BaseDocumentInterface::setExternalId()
*/
function setExternalId($externalId)
@@ -83,7 +83,7 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getExternalId()
*/
function getExternalId()
@@ -92,7 +92,7 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getTags()
*/
function getTags()
@@ -101,18 +101,18 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::setTagsStr()
*/
function setTagsStr($tagsStr)
{
$this->tagsStr = $tagsStr;
}
-
- /**
- * TODO: (non-PHPdoc)
- * @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getTagsStr()
- */
+
+ /**
+ * (non-PHPdoc)
+ * @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getTagsStr()
+ */
function getTagsStr()
{
return $this->tagsStr;
--- a/Model/Tag.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Model/Tag.php Thu Dec 08 23:48:55 2011 +0100
@@ -15,7 +15,7 @@
abstract class Tag implements TagInterface {
- public static $TAG_URL_STATUS_DICT = array('null_result'=>0,'redirection'=>1,'homonyme'=>2,'match'=>3);
+ public static $TAG_URL_STATUS_DICT = array('null_result'=>0,'redirection'=>1,'homonyme'=>2,'match'=>3, 'unsemantized'=>4);
/**
* @var integer $id
@@ -317,6 +317,10 @@
*/
public function getUrlStatusText()
{
+ if(is_null($this->getUrlStatus()))
+ {
+ return null;
+ }
switch ($this->getUrlStatus()) {
case 0:
return "null_result";
@@ -326,6 +330,10 @@
return "homonyme";
case 3:
return "match";
+ case 4:
+ return "unsemantized";
+ default:
+ return "";
}
}
--- a/Resources/views/WikiTag/TagListTable.html.twig Tue Dec 06 14:53:12 2011 +0100
+++ b/Resources/views/WikiTag/TagListTable.html.twig Thu Dec 08 23:48:55 2011 +0100
@@ -24,10 +24,10 @@
{% endif %}
</th>
<th>original_label</th>
- <th class="text_centered">Lien W</th>
- <th class="text_centered">Lien D</th>
+ <th class="wikitag_text_centered">Lien W</th>
+ <th class="wikitag_text_centered">Lien D</th>
<th>Catégorie</th>
- <th class="large_25 text_centered">Supprimer<br/>le lien W</th>
+ <th class="wikitag_large_25 wikitag_text_centered">Supprimer le lien W</th>
<th>Alias</th>
<th>
{% if sort != "nba" and sort != "nbd" %}
@@ -94,7 +94,13 @@
{% endif %}
</td>
<td class="wikitag_category" id="{{tag.id}}">{% if tag.category %}{{ tag.category.label }}{% endif %}</td>
- <td class="wikitag_text_centered"><img src="{{ asset('bundles/wikitag/images/red_cross.png') }}" class="wikitag_remove_wp_link" id="{{tag.id}}" alt="{{tag.label}}" /></td>
+ <td class="wikitag_text_centered">
+ {% if tag.urlstatus and tag.urlstatus != 4 %}
+ <img src="{{ asset('bundles/wikitag/images/red_cross.png') }}" class="wikitag_remove_wp_link" id="{{tag.id}}" alt="{{tag.label}}" />
+ {% else %}
+
+ {% endif %}
+ </td>
<td class="wikitag_alias" id="{{tag.id}}" >{% if tag.alias %}{{tag.alias}}{% endif %}</td>
<td class="wikitag_text_centered">
{% if nb_docs > 0 %}
--- a/Utils/SchemaUtils.php Tue Dec 06 14:53:12 2011 +0100
+++ b/Utils/SchemaUtils.php Thu Dec 08 23:48:55 2011 +0100
@@ -90,7 +90,6 @@
public function filter_foreign_key(array $sqls)
{
$res_sqls = array();
- //TODO : take the column and table names from the schema
foreach ($sqls as $sql) {
if(!preg_match("/ADD CONSTRAINT .+ FOREIGN KEY \(.*\) REFERENCES wikitag_document\(id\)/i", $sql))
{