app/DoctrineMigrations/Version20140129151724.php
changeset 121 ada5f3d8b5b4
parent 119 a1cf7fac5c2d
equal deleted inserted replaced
120:a87d5900e6d6 121:ada5f3d8b5b4
    41         $evm = $em->getEventManager();
    41         $evm = $em->getEventManager();
    42         $evm->removeEventListener(array('onFlush', 'preRemove', 'postPersist', 'postUpdate',  'postRemove'), $listenerInst);
    42         $evm->removeEventListener(array('onFlush', 'preRemove', 'postPersist', 'postUpdate',  'postRemove'), $listenerInst);
    43         
    43         
    44         // First step : we populate the dbpedia uris thanks to the dbpedia-owl:wikiPageID
    44         // First step : we populate the dbpedia uris thanks to the dbpedia-owl:wikiPageID
    45         echo "\nFIRST STEP";
    45         echo "\nFIRST STEP";
    46         $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE t.wikipediaPageId IS NOT NULL ORDER BY t.label ASC');//->setMaxResults(240)->setFirstResult(500);
    46         $query = $em->createQuery('SELECT count(t) FROM WikiTagBundle:Tag t WHERE t.wikipediaPageId IS NOT NULL');//->setMaxResults(240)->setFirstResult(500);
    47         $tags = $query->getResult();
    47         $nb = $query->getResult();
    48         $i = 1;
    48         $nb = $nb[0][1];
    49         $nb_set = 0;
    49         $nb_batch = 50;
    50         echo "\n".count($tags)." tags to search.";
    50         $nb_loops = ceil($nb / $nb_batch);
    51         foreach($tags as $tag){
    51 	    $i = 1;
    52         	$l = $tag->getLabel();
    52 	    $nb_set = 0;
    53         	$uri = WikiTagUtils::getDbpediaUri($tag->getWikipediaPageId(), array(), false, "pageid");
    53 	    echo "\n".$nb." tags to search.";
    54         	$tag->setDbpediaUri($uri);
    54         for($il=0; $il<$nb_loops; $il++){
    55         	$em->persist($tag);
    55 	        $query = $em->createQuery('SELECT t FROM WikiTagBundle:Tag t WHERE t.wikipediaPageId IS NOT NULL ORDER BY t.id ASC')->setMaxResults($nb_batch)->setFirstResult($il*$nb_batch);
    56 	        if($uri!=NULL && $uri!=""){
    56 	        $tags = $query->getResult();
    57 	            $nb_set++;
    57 	        foreach($tags as $tag){
       
    58 	        	$l = $tag->getLabel();
       
    59 	        	$uri = WikiTagUtils::getDbpediaUri($tag->getWikipediaPageId(), array(), false, "pageid");
       
    60 	        	$tag->setDbpediaUri($uri);
       
    61 	        	$em->persist($tag);
       
    62 		        if($uri!=NULL && $uri!=""){
       
    63 		            $nb_set++;
       
    64 		        }
       
    65 	        	$i++;
       
    66 	        	echo "\n$i : $l \t\t: $uri";
    58 	        }
    67 	        }
    59         	if( $i % 50 == 0 ){
    68 	        echo "\n    FLUSH";
    60         		$em->flush();
    69 	        $em->flush();
    61         		echo "\n    FLUSH";
    70 	        $em->clear();
    62         	}
    71     	}
    63         	$i++;
       
    64         	echo "\n$i : $l \t\t: $uri";
       
    65         }
       
    66         $em->flush();
       
    67         echo "\nFIRST STEP : $nb_set uris found";
    72         echo "\nFIRST STEP : $nb_set uris found";
    68         
    73         
    69         
    74         
    70         // Second step : we populate the dbpedia uris not found thanks to the foaf:isPrimaryTopicOf
    75         // Second step : we populate the dbpedia uris not found thanks to the foaf:isPrimaryTopicOf
    71         echo "\nSECOND STEP";
    76         echo "\nSECOND STEP";
   115         	$i++;
   120         	$i++;
   116         	echo "\n$i : $l \t\t: $uri";
   121         	echo "\n$i : $l \t\t: $uri";
   117         }
   122         }
   118         $em->flush();
   123         $em->flush();
   119         echo "\nTHIRD STEP : $nb_set uris found";
   124         echo "\nTHIRD STEP : $nb_set uris found";
       
   125         echo "\n\nTHIS IS THE END";
   120     }
   126     }
   121 
   127 
   122     public function down(Schema $schema)
   128     public function down(Schema $schema)
   123     {
   129     {
   124         // this down() migration is autogenerated, please modify it to your needs
   130         // this down() migration is autogenerated, please modify it to your needs