server/src/app/Console/Commands/ImportCocoonRDF.php
changeset 2 00e2916104fe
parent 1 01a844d292ac
child 3 2b3247d02769
equal deleted inserted replaced
1:01a844d292ac 2:00e2916104fe
     1 <?php namespace App\Console\Commands;
     1 <?php
     2 
     2 
       
     3 namespace CorpusParole\Console\Commands;
       
     4 
       
     5 use Config;
     3 use Illuminate\Console\Command;
     6 use Illuminate\Console\Command;
     4 use Symfony\Component\Console\Input\InputOption;
     7 use Symfony\Component\Console\Input\InputOption;
     5 use Symfony\Component\Console\Input\InputArgument;
     8 use Symfony\Component\Console\Input\InputArgument;
       
     9 use Phpoaipmh\Client;
       
    10 use Phpoaipmh\Endpoint;
     6 
    11 
     7 class ImportCocoonRDF extends Command {
    12 class ImportCocoonRDF extends Command
       
    13 {
       
    14     /**
       
    15      * The console command name.
       
    16      *
       
    17      * @var string
       
    18      */
       
    19     protected $name = 'corpus-parole:importRDF';
     8 
    20 
     9 	/**
    21     /**
    10 	 * The console command name.
    22      * The console command description.
    11 	 *
    23      *
    12 	 * @var string
    24      * @var string
    13 	 */
    25      */
    14 	protected $name = 'corpus-parole:importRDF';
    26     protected $description = 'Command description.';
    15 
    27 
    16 	/**
    28     /**
    17 	 * The console command description.
    29      * Create a new command instance.
    18 	 *
    30      */
    19 	 * @var string
    31     public function __construct()
    20 	 */
    32     {
    21 	protected $description = 'Command description.';
    33         parent::__construct();
       
    34     }
    22 
    35 
    23 	/**
    36     /**
    24 	 * Create a new command instance.
    37      * Execute the console command.
    25 	 *
    38      *
    26 	 * @return void
    39      * @return mixed
    27 	 */
    40      */
    28 	public function __construct()
    41     public function fire()
    29 	{
    42     {
    30 		parent::__construct();
    43         echo("hello\n");
    31 	}
    44         libxml_use_internal_errors(true);
    32 
    45 
    33 	/**
    46         $gs = new \EasyRdf_GraphStore(Config::get('corpusparole.sesame_update_url'));
    34 	 * Execute the console command.
       
    35 	 *
       
    36 	 * @return mixed
       
    37 	 */
       
    38 	public function fire()
       
    39 	{
       
    40 		echo("hello\n");
       
    41 		$doc = new \EasyRdf_Graph("http://cocoon.huma-num.fr/exist/crdo/rdf/crdo-ESLO1_ENTCONT_203");
       
    42 		$doc->load();
       
    43 
    47 
    44 		echo $doc->dump('text');
    48         //$doc = new \EasyRdf_Graph("http://cocoon.huma-num.fr/exist/crdo/rdf/crdo-ESLO1_ENTCONT_203");
       
    49         //$doc->load();
    45 
    50 
    46 		echo(join(', ', $doc->allOfType('foaf:Agent')));
    51         $client = new Client(Config::get('corpusparole.cocoon_oaipmh_url'));
    47 	}
    52         //$client = new Client('http://memory.loc.gov/cgi-bin/oai2_0');
       
    53         $endpoint = new Endpoint($client);
    48 
    54 
    49 	/**
    55         $recs = $endpoint->listRecords('olac', null, null, 'LanguesDeFrance');
    50 	 * Get the console command arguments.
    56         //$recs = $endpoint->listRecords('oai_dc', null, null, 'mussm');
    51 	 *
       
    52 	 * @return array
       
    53 	 */
       
    54 	protected function getArguments()
       
    55 	{
       
    56 		return [
       
    57 			['example', InputArgument::REQUIRED, 'An example argument.'],
       
    58 		];
       
    59 	}
       
    60 
    57 
    61 	/**
    58         foreach ($recs as $item) {
    62 	 * Get the console command options.
    59             if ($recs->getNumRequests() > 1) {
    63 	 *
    60                 break;
    64 	 * @return array
    61             }
    65 	 */
    62             $identifier = (string) $item->xpath('/record/header/identifier')[0];
    66 	protected function getOptions()
    63             $docRdfUrl = Config::get('corpusparole.cocoon_rdf_base_uri').substr($identifier, strlen(Config::get('corpusparole.cocoon_doc_id_base')));
    67 	{
    64             print("Processing $identifier : $docRdfUrl\n");
    68 		return [
    65             $doc = new \EasyRdf_Graph($docRdfUrl);
    69 			//['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
    66             $doc->load();
    70 		];
    67             $subjects = $doc->resourcesMatching('foaf:primaryTopic');
    71 	}
    68             $subject = reset($subjects)->getUri();
       
    69             $gs->insert($doc, $subject);
       
    70         }
       
    71     }
    72 
    72 
       
    73     /**
       
    74      * Get the console command arguments.
       
    75      *
       
    76      * @return array
       
    77      */
       
    78     protected function getArguments()
       
    79     {
       
    80         return [
       
    81             ['example', InputArgument::REQUIRED, 'An example argument.'],
       
    82         ];
       
    83     }
       
    84 
       
    85     /**
       
    86      * Get the console command options.
       
    87      *
       
    88      * @return array
       
    89      */
       
    90     protected function getOptions()
       
    91     {
       
    92         return [
       
    93             //['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
       
    94         ];
       
    95     }
    73 }
    96 }