18 public function up(Schema $schema) |
18 public function up(Schema $schema) |
19 { |
19 { |
20 // this up() migration is autogenerated, please modify it to your needs |
20 // this up() migration is autogenerated, please modify it to your needs |
21 $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); |
21 $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); |
22 |
22 |
|
23 |
23 // First we get all tags. |
24 // First we get all tags. |
24 $em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' ); |
25 $em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' ); |
25 $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t ORDER BY t.label ASC');//->setMaxResults(40)->setFirstResult(5000); |
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"; |
|
31 $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t ORDER BY t.label ASC');//->setMaxResults(240)->setFirstResult(500); |
26 $tags = $query->getResult(); |
32 $tags = $query->getResult(); |
27 |
|
28 $i = 1; |
33 $i = 1; |
|
34 $nb_set = 0; |
29 foreach($tags as $tag){ |
35 foreach($tags as $tag){ |
30 $l = $tag->getLabel(); |
36 $l = $tag->getLabel(); |
31 $uri = WikiTagUtils::getDbpediaUri($tag->getLabel(), [], false); |
37 $uri = WikiTagUtils::getDbpediaUri($tag->getWikipediaPageId(), [], false, "pageid"); |
32 $tag->setDbpediaUri($uri); |
38 $tag->setDbpediaUri($uri); |
33 $em->persist($tag); |
39 $em->persist($tag); |
|
40 if($uri!=NULL && $uri!=""){ |
|
41 $nb_set++; |
|
42 } |
34 if( $i % 50 == 0 ){ |
43 if( $i % 50 == 0 ){ |
35 $em->flush(); |
44 $em->flush(); |
36 echo "\n FLUSH"; |
45 echo "\n FLUSH"; |
37 } |
46 } |
38 $i++; |
47 $i++; |
39 echo "\n$i : $l \t\t: $uri"; |
48 echo "\n$i : $l \t\t: $uri"; |
40 } |
49 } |
41 $em->flush(); |
50 $em->flush(); |
|
51 echo "\nFIRST STEP : $nb_set uris found"; |
|
52 |
|
53 |
|
54 // Second step : we populate the dbpedia uris not found thanks to the foaf:isPrimaryTopicOf |
|
55 echo "\nSECOND STEP"; |
|
56 $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE (t.dbpediaUri=\'\' OR t.dbpediaUri IS NULL) ORDER BY t.label ASC');//->setMaxResults(240); |
|
57 $tags = $query->getResult(); |
|
58 $i = 1; |
|
59 $nb_set = 0; |
|
60 foreach($tags as $tag){ |
|
61 $l = $tag->getLabel(); |
|
62 $uri = WikiTagUtils::getDbpediaUri($tag->getWikipediaUrl(), [], false, "wikiurl"); |
|
63 $tag->setDbpediaUri($uri); |
|
64 $em->persist($tag); |
|
65 if($uri!=NULL && $uri!=""){ |
|
66 $nb_set++; |
|
67 } |
|
68 if( $i % 50 == 0 ){ |
|
69 $em->flush(); |
|
70 echo "\n FLUSH"; |
|
71 } |
|
72 $i++; |
|
73 echo "\n$i : $l \t\t: $uri"; |
|
74 } |
|
75 $em->flush(); |
|
76 echo "\nSECOND STEP : $nb_set uris found"; |
|
77 |
|
78 |
|
79 // Third step : we populate the dbpedia uris not found thanks to the rdfs:label |
|
80 echo "\nTHIRD STEP"; |
|
81 $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE (t.dbpediaUri=\'\' OR t.dbpediaUri IS NULL) ORDER BY t.label ASC');//->setMaxResults(240); |
|
82 $tags = $query->getResult(); |
|
83 $i = 1; |
|
84 $nb_set = 0; |
|
85 foreach($tags as $tag){ |
|
86 $l = $tag->getLabel(); |
|
87 $uri = WikiTagUtils::getDbpediaUri($tag->getLabel(), [], false); |
|
88 $tag->setDbpediaUri($uri); |
|
89 $em->persist($tag); |
|
90 if($uri!=NULL && $uri!=""){ |
|
91 $nb_set++; |
|
92 } |
|
93 if( $i % 50 == 0 ){ |
|
94 $em->flush(); |
|
95 echo "\n FLUSH"; |
|
96 } |
|
97 $i++; |
|
98 echo "\n$i : $l \t\t: $uri"; |
|
99 } |
|
100 $em->flush(); |
|
101 echo "\nTHIRD STEP : $nb_set uris found"; |
42 } |
102 } |
43 |
103 |
44 public function down(Schema $schema) |
104 public function down(Schema $schema) |
45 { |
105 { |
46 // this down() migration is autogenerated, please modify it to your needs |
106 // this down() migration is autogenerated, please modify it to your needs |