|
108
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace Application\Migrations; |
|
|
4 |
|
|
|
5 |
use Doctrine\DBAL\Migrations\AbstractMigration, |
|
|
6 |
Doctrine\DBAL\Schema\Schema, |
|
|
7 |
IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils; |
|
|
8 |
|
|
|
9 |
/** |
|
|
10 |
* Migration for WikiTagBundle <= V00.13 |
|
|
11 |
* This migration takes every tag label and search the REAL dbpedia uri associated to this label. |
|
|
12 |
* Before, the dbpedia uri was manually generated by http://dbpedia.org/resource/ + english_label. |
|
|
13 |
* Now we get the dbpedia uri by requesting http://LANG_CODE.dbpedia.org/sparql with the current label. |
|
|
14 |
* |
|
|
15 |
*/ |
|
|
16 |
class Version20140129151724 extends AbstractMigration |
|
|
17 |
{ |
|
|
18 |
public function up(Schema $schema) |
|
|
19 |
{ |
|
|
20 |
// this up() migration is autogenerated, please modify it to your needs |
|
|
21 |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); |
|
|
22 |
|
|
109
|
23 |
|
|
108
|
24 |
// First we get all tags. |
|
|
25 |
$em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' ); |
|
109
|
26 |
// Avoid php annoying memory leaks |
|
|
27 |
$em->getConnection()->getConfiguration()->setSQLLogger(null); |
|
|
28 |
|
|
|
29 |
// First step : we populate the dbpedia uris thanks to the dbpedia-owl:wikiPageID |
|
|
30 |
echo "\nFIRST STEP"; |
|
110
|
31 |
$query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE t.wikipediaPageId IS NOT NULL ORDER BY t.label ASC');//->setMaxResults(240)->setFirstResult(500); |
|
108
|
32 |
$tags = $query->getResult(); |
|
|
33 |
$i = 1; |
|
109
|
34 |
$nb_set = 0; |
|
110
|
35 |
echo "\n".count($tags)." tags to search."; |
|
108
|
36 |
foreach($tags as $tag){ |
|
|
37 |
$l = $tag->getLabel(); |
|
109
|
38 |
$uri = WikiTagUtils::getDbpediaUri($tag->getWikipediaPageId(), [], false, "pageid"); |
|
108
|
39 |
$tag->setDbpediaUri($uri); |
|
|
40 |
$em->persist($tag); |
|
109
|
41 |
if($uri!=NULL && $uri!=""){ |
|
|
42 |
$nb_set++; |
|
|
43 |
} |
|
108
|
44 |
if( $i % 50 == 0 ){ |
|
|
45 |
$em->flush(); |
|
|
46 |
echo "\n FLUSH"; |
|
|
47 |
} |
|
|
48 |
$i++; |
|
|
49 |
echo "\n$i : $l \t\t: $uri"; |
|
|
50 |
} |
|
|
51 |
$em->flush(); |
|
109
|
52 |
echo "\nFIRST STEP : $nb_set uris found"; |
|
|
53 |
|
|
|
54 |
|
|
|
55 |
// Second step : we populate the dbpedia uris not found thanks to the foaf:isPrimaryTopicOf |
|
|
56 |
echo "\nSECOND STEP"; |
|
110
|
57 |
$query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE (t.wikipediaUrl!=\'\' AND t.wikipediaUrl IS NOT NULL AND (t.dbpediaUri=\'\' OR t.dbpediaUri IS NULL)) ORDER BY t.label ASC');//->setMaxResults(240); |
|
109
|
58 |
$tags = $query->getResult(); |
|
|
59 |
$i = 1; |
|
|
60 |
$nb_set = 0; |
|
110
|
61 |
echo "\n".count($tags)." tags to search."; |
|
109
|
62 |
foreach($tags as $tag){ |
|
|
63 |
$l = $tag->getLabel(); |
|
|
64 |
$uri = WikiTagUtils::getDbpediaUri($tag->getWikipediaUrl(), [], false, "wikiurl"); |
|
|
65 |
$tag->setDbpediaUri($uri); |
|
|
66 |
$em->persist($tag); |
|
|
67 |
if($uri!=NULL && $uri!=""){ |
|
|
68 |
$nb_set++; |
|
|
69 |
} |
|
|
70 |
if( $i % 50 == 0 ){ |
|
|
71 |
$em->flush(); |
|
|
72 |
echo "\n FLUSH"; |
|
|
73 |
} |
|
|
74 |
$i++; |
|
|
75 |
echo "\n$i : $l \t\t: $uri"; |
|
|
76 |
} |
|
|
77 |
$em->flush(); |
|
|
78 |
echo "\nSECOND STEP : $nb_set uris found"; |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
// Third step : we populate the dbpedia uris not found thanks to the rdfs:label |
|
|
82 |
echo "\nTHIRD STEP"; |
|
110
|
83 |
$query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE (t.wikipediaUrl!=\'\' AND t.wikipediaUrl IS NOT NULL AND (t.dbpediaUri=\'\' OR t.dbpediaUri IS NULL)) ORDER BY t.label ASC');//->setMaxResults(240); |
|
109
|
84 |
$tags = $query->getResult(); |
|
|
85 |
$i = 1; |
|
|
86 |
$nb_set = 0; |
|
110
|
87 |
echo "\n".count($tags)." tags to search."; |
|
109
|
88 |
foreach($tags as $tag){ |
|
|
89 |
$l = $tag->getLabel(); |
|
|
90 |
$uri = WikiTagUtils::getDbpediaUri($tag->getLabel(), [], false); |
|
|
91 |
$tag->setDbpediaUri($uri); |
|
|
92 |
$em->persist($tag); |
|
|
93 |
if($uri!=NULL && $uri!=""){ |
|
|
94 |
$nb_set++; |
|
|
95 |
} |
|
|
96 |
if( $i % 50 == 0 ){ |
|
|
97 |
$em->flush(); |
|
|
98 |
echo "\n FLUSH"; |
|
|
99 |
} |
|
|
100 |
$i++; |
|
|
101 |
echo "\n$i : $l \t\t: $uri"; |
|
|
102 |
} |
|
|
103 |
$em->flush(); |
|
|
104 |
echo "\nTHIRD STEP : $nb_set uris found"; |
|
108
|
105 |
} |
|
|
106 |
|
|
|
107 |
public function down(Schema $schema) |
|
|
108 |
{ |
|
|
109 |
// this down() migration is autogenerated, please modify it to your needs |
|
|
110 |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); |
|
|
111 |
} |
|
|
112 |
} |