migration to real dbpedia uri
authorcavaliet
Thu, 30 Jan 2014 17:52:14 +0100
changeset 108 48af4fad8a44
parent 107 22752b3d9c35
child 109 fc56f9e28cdb
migration to real dbpedia uri
.hgsubstate
app/DoctrineMigrations/Version20140129151724.php
--- a/.hgsubstate	Wed Jan 29 12:16:16 2014 +0100
+++ b/.hgsubstate	Thu Jan 30 17:52:14 2014 +0100
@@ -1,1 +1,1 @@
-085ea4dbfeee1ff9258235625ad8f4c628198080 vendor/bundles/IRI/Bundle/WikiTagBundle
+a023e0185a02e6833a3e04724b80cdf628621224 vendor/bundles/IRI/Bundle/WikiTagBundle
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/DoctrineMigrations/Version20140129151724.php	Thu Jan 30 17:52:14 2014 +0100
@@ -0,0 +1,49 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration,
+    Doctrine\DBAL\Schema\Schema,
+	IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
+
+/**
+ * Migration for WikiTagBundle <= V00.13
+ * This migration takes every tag label and search the REAL dbpedia uri associated to this label.
+ * Before, the dbpedia uri was manually generated by http://dbpedia.org/resource/ + english_label.
+ * Now we get the dbpedia uri by requesting http://LANG_CODE.dbpedia.org/sparql with the current label.
+ * 
+ */
+class Version20140129151724 extends AbstractMigration
+{
+    public function up(Schema $schema)
+    {
+        // this up() migration is autogenerated, please modify it to your needs
+        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
+        
+        // First we get all tags.
+        $em = $GLOBALS["kernel"]->getContainer()->get( 'doctrine.orm.entity_manager' );
+        $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t ORDER BY t.label ASC');//->setMaxResults(40)->setFirstResult(5000);
+        $tags = $query->getResult();
+        
+        $i = 1;
+        foreach($tags as $tag){
+        	$l = $tag->getLabel();
+        	$uri = WikiTagUtils::getDbpediaUri($tag->getLabel(), [], false);
+        	$tag->setDbpediaUri($uri);
+        	$em->persist($tag);
+        	if( $i % 50 == 0 ){
+        		$em->flush();
+        		echo "\n    FLUSH";
+        	}
+        	$i++;
+        	echo "\n$i : $l \t\t: $uri";
+        }
+        $em->flush();
+    }
+
+    public function down(Schema $schema)
+    {
+        // this down() migration is autogenerated, please modify it to your needs
+        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
+    }
+}