10 namespace IRI\Bundle\WikiTagBundle\Command; |
10 namespace IRI\Bundle\WikiTagBundle\Command; |
11 |
11 |
12 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
12 use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
13 |
13 |
14 use Doctrine\ORM\QueryBuilder; |
14 use Doctrine\ORM\QueryBuilder; |
15 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
16 use Symfony\Component\Console\Input\InputArgument; |
15 use Symfony\Component\Console\Input\InputArgument; |
17 use Symfony\Component\Console\Input\InputInterface; |
16 use Symfony\Component\Console\Input\InputInterface; |
18 use Symfony\Component\Console\Input\InputOption; |
17 use Symfony\Component\Console\Input\InputOption; |
19 use Symfony\Component\Console\Output\OutputInterface; |
18 use Symfony\Component\Console\Output\OutputInterface; |
20 |
19 |
21 class QueryWikipediaCommand extends ContainerAwareCommand |
20 class QueryWikipediaCommand extends ProgressContainerAwareCommand |
22 { |
21 { |
23 |
22 |
24 private function showProgress(OutputInterface $output, $current, $total, $label, $width) |
|
25 { |
|
26 $percent = (floatval($current)/floatval($total)) * 100.0; |
|
27 $marks = intval(floor(floatval($width) * ($percent / 100.0) )); |
|
28 $spaces = $width - $marks; |
|
29 |
|
30 $status_bar="\r["; |
|
31 $status_bar.=str_repeat("=", $marks); |
|
32 if($marks<$width){ |
|
33 $status_bar.=">"; |
|
34 $status_bar.=str_repeat(" ", $spaces); |
|
35 } else { |
|
36 $status_bar.="="; |
|
37 } |
|
38 |
|
39 $disp=str_pad(number_format($percent, 0),3, " ", STR_PAD_LEFT); |
|
40 |
|
41 $label = str_pad(substr($label,0,50), 50, " "); |
|
42 $current_str = str_pad($current, strlen("$total"), " ", STR_PAD_LEFT); |
|
43 |
|
44 $status_bar.="] $disp% $current_str/$total : $label"; |
|
45 |
|
46 $output->write("$status_bar "); |
|
47 |
|
48 if($current == $total) { |
|
49 $output->writeln(""); |
|
50 } |
|
51 |
|
52 } |
|
53 |
|
54 private function processTag($tag, $em) |
23 private function processTag($tag, $em) |
55 { |
24 { |
56 $tag_label_normalized = WikiTagUtils::normalizeTag($tag->getLabel()); |
25 $tag_label_normalized = WikiTagUtils::normalizeTag($tag->getLabel()); |
57 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
26 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); |
58 |
27 |
59 $new_label = $wp_response['new_label']; |
28 $tag->setWikipediaInfo($wp_response); |
60 $status = $wp_response['status']; |
|
61 $url = $wp_response['wikipedia_url']; |
|
62 $pageid = $wp_response['pageid']; |
|
63 $dbpedia_uri = $wp_response["dbpedia_uri"]; |
|
64 $wikipedia_revision_id = $wp_response['revision_id']; |
|
65 |
|
66 # We save the datas |
|
67 if($new_label!=null){ |
|
68 $tag->setLabel($new_label); |
|
69 } |
|
70 if($status!=null){ |
|
71 $tag->setUrlStatus($status); |
|
72 } |
|
73 $tag->setWikipediaUrl($url); |
|
74 $tag->setWikipediaPageId($pageid); |
|
75 $tag->setDbpediaUri($dbpedia_uri); |
|
76 |
29 |
77 // Save datas. |
30 // Save datas. |
78 $em->persist($tag); |
31 $em->persist($tag); |
79 |
32 |
80 } |
33 } |