server/src/tests/Libraries/Mappers/CocoonCollectionRdfMapperTest.php
changeset 152 dd6b3adde73b
parent 145 49b75287c30b
equal deleted inserted replaced
151:95dfb40ff3d2 152:dd6b3adde73b
       
     1 <?php
       
     2 
       
     3 use CorpusParole\Libraries\Mappers\CocoonCollectionRdfMapper;
       
     4 use CorpusParole\Libraries\CocoonUtils;
       
     5 
       
     6 use EasyRdf\Graph;
       
     7 use EasyRdf\Resource;
       
     8 use EasyRdf\Literal;
       
     9 
       
    10 use Illuminate\Foundation\Testing\WithoutMiddleware;
       
    11 use Illuminate\Foundation\Testing\DatabaseMigrations;
       
    12 use Illuminate\Foundation\Testing\DatabaseTransactions;
       
    13 
       
    14 class CocoonCollectionRdfMapperTest extends TestCase
       
    15 {
       
    16 
       
    17     const TEST_INPUT_DOCS = [
       
    18         'BASE' => <<<EOT
       
    19         @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
       
    20         @prefix owl: <http://www.w3.org/2002/07/owl#> .
       
    21         @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
       
    22         @prefix fn: <http://www.w3.org/2005/xpath-functions#> .
       
    23         @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
       
    24         @prefix sesame: <http://www.openrdf.org/schema/sesame#> .
       
    25         @prefix v: <http://rdf.data-vocabulary.org/#> .
       
    26         <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000> a <http://crdo.risc.cnrs.fr/schemas/Resource> ;
       
    27             <http://purl.org/dc/elements/1.1/description> "Corpus de Français Parlé Parisien des années 2000."@fr , "Le Corpus de Français Parlé Parisien (CFPP2000) est composé d'un ensemble d'interviews non directives sur les quartiers de Paris et de la proche banlieue. Les entretiens, transcrits en orthographe et alignés au tour de parole, sont disponibles sur le net ; ils sont librement employables en échange de la mention dans la bibliographie des travaux qui en seraient tirés d'une part de l'adresse du site: http://cfpp2000.univ-paris3.fr/ et d'autre part du document de présentation suivant : Branca-Rosoff S., Fleury S., Lefeuvre F., Pires M., 2012, \"Discours sur la ville. Présentation du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)\". En février 2013, ce corpus comprenait environ 550 000 mots. Un certain nombre d'outils en ligne, notamment un concordancier et  des outils textométriques permettent de mener des requêtes lexicales et grammaticales. CFPP2000 est particulièrement destiné à des analyses sur le français oral. Le projet sous-jacent au corpus est par ailleurs l'étude des modifications et des variations qui interviennent dans ce qu'on peut considérer comme un parisien véhiculaire en tension entre le pôle du standard et le pôle du vernaculaire. Par ailleurs, il comporte des activités linguistiques diversifiées (description de quartier, anecdotes, argumentation…) et on peut par conséquent travailler sur la syntaxe propre à ces différentes utilisations du langage. Il permet enfin d'opposer dialogues (entre enquêteur et enquêtés) et multilogues (où la présence de plusieurs enquêtés favorise le passage à un registre familier).  CFPP2000 est constitué d'interviews longues (d'une heure en moyenne) intégralement transcrites. Il est donc utilisable pour examiner les singularités qui reviennent à l'idiolecte propre à une personne donnée, par opposition aux variantes diffusées dans des groupes plus larges (quartiers, groupes socio-culturels, classe d'âge, etc.). Le corpus constitue enfin un ensemble de témoignages intéressants sur les représentations de Paris et de sa proche banlieue qui est susceptible d'intéresser des analystes du discours, des sociologues, ou tout simplement des curieux de la ville."@fr ;
       
    28             <http://purl.org/dc/elements/1.1/type> <http://purl.org/dc/dcmitype/Collection> ;
       
    29             <http://purl.org/dc/elements/1.1/subject> <http://lexvo.org/id/iso639-3/fra> ;
       
    30             <http://purl.org/dc/elements/1.1/language> <http://lexvo.org/id/iso639-3/gsw> ;
       
    31             <http://purl.org/dc/terms/created> "start=1988; end=1989"^^<http://purl.org/dc/terms/Period> ;
       
    32             <http://purl.org/dc/elements/1.1/rights> "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ;
       
    33             <http://www.language-archives.org/OLAC/1.1/depositor> <http://viaf.org/viaf/93752300> ;
       
    34             <http://purl.org/dc/elements/1.1/publisher> <http://viaf.org/viaf/142432638> , "Fédération CLESTHIA" , <http://viaf.org/viaf/154862993> ;
       
    35             <http://purl.org/dc/elements/1.1/title> "Corpus de Français Parlé Parisien des années 2000 (CFPP)"@fr ;
       
    36             <http://www.language-archives.org/OLAC/1.1/interviewer> "Branca-Rosoff, Sonia" , "Lefeuvre, Florence" , "Pires, Mat" ;
       
    37             <http://purl.org/dc/terms/accessRights> "Freely available for non-commercial use" ;
       
    38             <http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
       
    39             <http://purl.org/dc/terms/spatial> "FR"^^<http://purl.org/dc/terms/ISO3166> , "France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , <http://vocab.getty.edu/tgn/7008038> ;
       
    40             <http://purl.org/dc/terms/available> "2013-04-12"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    41             <http://purl.org/dc/terms/issued> "2013-04-12T22:20:23+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    42             <http://purl.org/dc/terms/modified> "2014-05-10T20:16:27+02:00"^^<http://purl.org/dc/terms/W3CDTF> ;
       
    43             <http://www.language-archives.org/OLAC/1.1/transcriber> "Branca-Rosoff, Sonia" , "Lefeuvre, Florence" , "Pires, Mat" ;
       
    44             <http://www.w3.org/2003/01/geo/wgs84_pos#long> "2.3333"^^xsd:float ;
       
    45             <http://www.w3.org/2003/01/geo/wgs84_pos#lat> "48.8667"^^xsd:float ;
       
    46             <http://www.language-archives.org/OLAC/1.1/compiler> "Branca-Rosoff, Sonia" , "Fleury, Serge" , "Lefeuvre, Florence" , "Pires, Mat" ;
       
    47             <http://www.language-archives.org/OLAC/1.1/data_inputter> "Branca-Rosoff, Sonia" , "Lefeuvre, Florence" , "Pires, Mat" ;
       
    48             <http://www.language-archives.org/OLAC/1.1/researcher> "Branca-Rosoff, Sonia" , "Fleury, Serge" , "Lefeuvre, Florence" , "Pires, Mat" ;
       
    49             <http://www.language-archives.org/OLAC/1.1/sponsor> "Ville de Paris " , "Délégation générale à la langue française et aux langues de France " ;
       
    50             <http://www.language-archives.org/OLAC/1.1/developer> "Fleury, Serge" ;
       
    51             <http://purl.org/dc/terms/isPartOf> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ALA> .
       
    52 EOT
       
    53     ];
       
    54 
       
    55     const TEST_INPUT_ID = "crdo-COLLECTION_CFPP2000";
       
    56 
       
    57     private $inputGraphes = [];
       
    58     private $resGraphes = [];
       
    59     private $mappers = [];
       
    60 
       
    61     function __construct(string $name = null) {
       
    62         parent::__construct($name);
       
    63     }
       
    64 
       
    65     public function setUp() {
       
    66         parent::setUp();
       
    67 
       
    68         $this->testGraphUri = config('corpusparole.corpus_doc_id_base_uri').CocoonCollectionRdfMapperTest::TEST_INPUT_ID;
       
    69 
       
    70         foreach(CocoonCollectionRdfMapperTest::TEST_INPUT_DOCS as $key => $inputDoc) {
       
    71             $this->inputGraphes[$key] = new Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000", $inputDoc);
       
    72             $this->mappers[$key] = new CocoonCollectionRdfMapper($this->inputGraphes[$key]);
       
    73             $this->mappers[$key]->mapGraph();
       
    74             $this->resGraphes[$key] = $this->mappers[$key]->getOutputGraphes()[$this->inputGraphes[$key]->getUri()];
       
    75         }
       
    76     }
       
    77 
       
    78     public function tearDown() {
       
    79         parent::tearDown();
       
    80     }
       
    81 
       
    82     /**
       
    83      * Just test that the construct and setup are ok
       
    84      *
       
    85      * @return void
       
    86      */
       
    87     public function testInit()
       
    88     {
       
    89         $this->assertTrue(true);
       
    90     }
       
    91 
       
    92     /**
       
    93      * Test that the returned graph has the same uri that the original.
       
    94      *
       
    95      * @return void
       
    96      */
       
    97     public function testUri() {
       
    98 
       
    99         //echo $this->resGraphes['BASE']->serialise('turtle');
       
   100         //echo var_export($this->resGraphes['BASE']->toRdfPhp());
       
   101 
       
   102         $this->assertNotNull($this->resGraphes['BASE']);
       
   103         $this->assertEquals($this->testGraphUri, $this->resGraphes['BASE']->getUri(), "URIS must be translated");
       
   104      }
       
   105 
       
   106     /**
       
   107       * Test that the return graph has one edm:Collection resource
       
   108       *
       
   109       * @return void
       
   110       */
       
   111     public function testAggregationResource() {
       
   112 
       
   113         $resources = $this->resGraphes['BASE']->allOfType('edm:Collection');
       
   114 
       
   115         $this->assertCount(1, $resources, "Must found only one resources of type edm:Collection");
       
   116         $this->assertEquals($this->testGraphUri,$resources[0]);
       
   117     }
       
   118 
       
   119     /**
       
   120     * Test one to one mapping spatial info
       
   121     *
       
   122     * @return void
       
   123     */
       
   124     public function testSpatial() {
       
   125 
       
   126         $coll = $this->resGraphes['BASE']->get('edm:Collection', '^rdf:type');
       
   127         $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type');
       
   128 
       
   129         $this->assertNotNull($coll);
       
   130         $this->assertNotNull($sourceNode);
       
   131 
       
   132         $spatials = $coll->all($this->resGraphes['BASE']->resource('http://purl.org/dc/terms/spatial'));
       
   133 
       
   134         $this->assertCount(1, $spatials, "Must have only one spatial node");
       
   135         $spatial = $spatials[0];
       
   136         $this->assertTrue($spatial->isBNode(),"spatial node must be blank");
       
   137         $this->assertEquals("edm:Place", $spatial->type(), "spatial node type must be edm:Place");
       
   138 
       
   139         $lats = $spatial->all('geo:lat');
       
   140         $this->assertCount(1, $lats, "One latitude");
       
   141         $this->assertInstanceOf("EasyRdf\Literal", $lats[0], "Latitude must be a litteral");
       
   142         $this->assertEquals(Literal::create("48.8667", null, 'xsd:float'), $lats[0], "lat must be '48.8667'^^xsd:float");
       
   143 
       
   144         $longs = $spatial->all('geo:long');
       
   145         $this->assertCount(1, $longs, "One longitude");
       
   146         $this->assertInstanceOf("EasyRdf\Literal", $longs[0], "Longitude must be a litteral");
       
   147         $this->assertEquals(Literal::create("2.3333", null, 'xsd:float'), $longs[0], "long must be '1.90'^^xsd:float");
       
   148 
       
   149         $notes = $spatial->all('skos:note');
       
   150         $this->assertCount(2, $notes, "2 notes");
       
   151         $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $notes, "Notes mus be only literals");
       
   152         $this->assertEquals(Literal::create("FR", null, "dc:ISO3166"), $notes[0], "notes contains 'FR'^^dc:ISO3166");
       
   153         $this->assertEquals(Literal::create("France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier", "fr", null), $notes[1], "notes contains 'France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier'@fr");
       
   154 
       
   155         $sameas = $spatial->all('owl:sameAs');
       
   156         $this->assertCount(1, $sameas, "1 same as");
       
   157         $this->assertContainsOnlyInstancesOf("EasyRdf\Resource", $sameas, "Notes mus be only resources");
       
   158         $this->assertEquals('http://vocab.getty.edu/tgn/7008038', $sameas[0]->getUri(), "uri must be http://vocab.getty.edu/tgn/7008038");
       
   159     }
       
   160 
       
   161     /**
       
   162      * Test one to one mapping
       
   163      *
       
   164      * @return void
       
   165      */
       
   166     public function testOneToOnePropsIdentity() {
       
   167 
       
   168         $properties = [
       
   169             'http://purl.org/dc/elements/1.1/description',
       
   170             'http://purl.org/dc/elements/1.1/language',
       
   171             'http://purl.org/dc/elements/1.1/publisher',
       
   172             'http://purl.org/dc/elements/1.1/rights',
       
   173             'http://purl.org/dc/terms/license',
       
   174             'http://purl.org/dc/elements/1.1/subject',
       
   175             'http://purl.org/dc/elements/1.1/title',
       
   176             'http://purl.org/dc/terms/available',
       
   177             'http://purl.org/dc/terms/created',
       
   178             'http://purl.org/dc/terms/issued',
       
   179             'http://purl.org/dc/elements/1.1/type',
       
   180             'http://purl.org/dc/elements/1.1/language',
       
   181             'http://purl.org/dc/terms/modified',
       
   182         ];
       
   183 
       
   184         $coll = $this->resGraphes['BASE']->get('edm:Collection', '^rdf:type');
       
   185         $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type');
       
   186 
       
   187         $this->assertNotNull($coll);
       
   188         $this->assertNotNull($sourceNode);
       
   189 
       
   190         foreach ($properties as $prop) {
       
   191             $outputValuesStr = [];
       
   192             foreach($coll->all($this->resGraphes['BASE']->resource($prop)) as $outputValue) {
       
   193                 array_push($outputValuesStr, strval($outputValue));
       
   194             }
       
   195             $this->assertNotEmpty($outputValuesStr, "we must found some values to test $prop");
       
   196             foreach ($sourceNode->all($this->inputGraphes['BASE']->resource($prop)) as $value) {
       
   197                 $this->assertContains(strval($value), $outputValuesStr, "$prop not found in output graph");
       
   198             }
       
   199         }
       
   200 
       
   201     }
       
   202 
       
   203     public function testLinkToCocoonCollection() {
       
   204         $coll = $this->resGraphes['BASE']->get('edm:Collection', '^rdf:type');
       
   205         $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type');
       
   206 
       
   207         $this->assertNotNull($coll);
       
   208         $this->assertNotNull($sourceNode);
       
   209 
       
   210         $versionOfRes = $coll->all("<http://purl.org/dc/terms/isVersionOf>");
       
   211         $this->assertCount(1, $versionOfRes, "Must have only on isVersionOf");
       
   212         $versionOfRes = $versionOfRes[0];
       
   213         $this->assertInstanceOf("EasyRdf\Resource", $versionOfRes, "version Res must be a resource");
       
   214         $this->assertEquals($sourceNode->getUri(), $versionOfRes->getUri(), "versionof res uri must be sams than source");
       
   215 
       
   216     }
       
   217 
       
   218     /**
       
   219      * Test mapping for isPartOf
       
   220      *
       
   221      * @return void
       
   222      */
       
   223     public function testOneToOneCollectionIsPartOf() {
       
   224         $collection = $this->resGraphes['BASE']->get('edm:Collection', '^rdf:type');
       
   225         $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type');
       
   226 
       
   227         $this->assertNotNull($collection);
       
   228         $this->assertNotNull($sourceNode);
       
   229 
       
   230         $ispartOf = $collection->all('<http://www.europeana.eu/schemas/edm/isGatheredInto>');
       
   231         $this->assertCount(1, $ispartOf, "Must have one collection node");
       
   232 
       
   233         $this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-COLLECTION_ALA", strval($collection->get('<http://www.europeana.eu/schemas/edm/isGatheredInto>')), "the isPartOf mus equals ".config('corpusparole.corpus_doc_id_base_uri')."crdo-COLLECTION_ALA");
       
   234     }
       
   235 
       
   236 
       
   237 }