server/src/tests/libraries/Mappers/CocoonCollectionRdfMapperTest.php
changeset 18 f2a40bbc27f6
child 114 8af5ed0521a2
equal deleted inserted replaced
17:ac3dc090e987 18:f2a40bbc27f6
       
     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     const TEST_GRAPH_URI = "http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000";
       
    57 
       
    58     private $inputGraphes = [];
       
    59     private $resGraphes = [];
       
    60     private $mappers = [];
       
    61 
       
    62     function __construct(string $name = null) {
       
    63         parent::__construct($name);
       
    64     }
       
    65 
       
    66     public function setUp() {
       
    67         parent::setUp();
       
    68 
       
    69         foreach(CocoonCollectionRdfMapperTest::TEST_INPUT_DOCS as $key => $inputDoc) {
       
    70             $this->inputGraphes[$key] = new Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000", $inputDoc);
       
    71             $this->mappers[$key] = new CocoonCollectionRdfMapper($this->inputGraphes[$key]);
       
    72             $this->mappers[$key]->mapGraph();
       
    73             $this->resGraphes[$key] = $this->mappers[$key]->getOutputGraphes()[$this->inputGraphes[$key]->getUri()];
       
    74         }
       
    75     }
       
    76 
       
    77     public function tearDown() {
       
    78         parent::tearDown();
       
    79     }
       
    80 
       
    81     /**
       
    82      * Just test that the construct and setup are ok
       
    83      *
       
    84      * @return void
       
    85      */
       
    86     public function testInit()
       
    87     {
       
    88         $this->assertTrue(true);
       
    89     }
       
    90 
       
    91     /**
       
    92      * Test that the returned graph has the same uri that the original.
       
    93      *
       
    94      * @return void
       
    95      */
       
    96     public function testUri() {
       
    97 
       
    98         echo $this->resGraphes['BASE']->serialise('turtle');
       
    99         //echo var_export($this->resGraphes['BASE']->toRdfPhp());
       
   100 
       
   101         $this->assertNotNull($this->resGraphes['BASE']);
       
   102         $this->assertEquals(CocoonCollectionRdfMapperTest::TEST_GRAPH_URI, $this->resGraphes['BASE']->getUri(), "URIS must be translated");
       
   103      }
       
   104 
       
   105     /**
       
   106       * Test that the return graph has one edm:Collection resource
       
   107       *
       
   108       * @return void
       
   109       */
       
   110     public function testAggregationResource() {
       
   111 
       
   112         $resources = $this->resGraphes['BASE']->allOfType('edm:Collection');
       
   113 
       
   114         $this->assertCount(1, $resources, "Must found only one resources of type edm:Collection");
       
   115         $this->assertEquals(CocoonCollectionRdfMapperTest::TEST_GRAPH_URI,$resources[0]);
       
   116     }
       
   117 
       
   118     /**
       
   119     * Test one to one mapping spatial info
       
   120     *
       
   121     * @return void
       
   122     */
       
   123     public function testSpatial() {
       
   124 
       
   125         $coll = $this->resGraphes['BASE']->get('edm:Collection', '^rdf:type');
       
   126         $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type');
       
   127 
       
   128         $this->assertNotNull($coll);
       
   129         $this->assertNotNull($sourceNode);
       
   130 
       
   131         $spatials = $coll->all($this->resGraphes['BASE']->resource('http://purl.org/dc/terms/spatial'));
       
   132 
       
   133         $this->assertCount(1, $spatials, "Must have only one spatial node");
       
   134         $spatial = $spatials[0];
       
   135         $this->assertTrue($spatial->isBNode(),"spatial node must be blank");
       
   136         $this->assertEquals("edm:Place", $spatial->type(), "spatial node type must be edm:Place");
       
   137 
       
   138         $lats = $spatial->all('geo:lat');
       
   139         $this->assertCount(1, $lats, "One latitude");
       
   140         $this->assertInstanceOf("EasyRdf\Literal", $lats[0], "Latitude must be a litteral");
       
   141         $this->assertEquals(Literal::create("48.8667", null, 'xsd:float'), $lats[0], "lat must be '48.8667'^^xsd:float");
       
   142 
       
   143         $longs = $spatial->all('geo:long');
       
   144         $this->assertCount(1, $longs, "One longitude");
       
   145         $this->assertInstanceOf("EasyRdf\Literal", $longs[0], "Longitude must be a litteral");
       
   146         $this->assertEquals(Literal::create("2.3333", null, 'xsd:float'), $longs[0], "long must be '1.90'^^xsd:float");
       
   147 
       
   148         $notes = $spatial->all('skos:note');
       
   149         $this->assertCount(2, $notes, "2 notes");
       
   150         $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $notes, "Notes mus be only literals");
       
   151         $this->assertEquals(Literal::create("FR", null, "dc:ISO3166"), $notes[0], "notes contains 'FR'^^dc:ISO3166");
       
   152         $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");
       
   153 
       
   154         $sameas = $spatial->all('owl:sameAs');
       
   155         $this->assertCount(1, $sameas, "1 same as");
       
   156         $this->assertContainsOnlyInstancesOf("EasyRdf\Resource", $sameas, "Notes mus be only resources");
       
   157         $this->assertEquals('http://vocab.getty.edu/tgn/7008038', $sameas[0]->getUri(), "uri must be http://vocab.getty.edu/tgn/7008038");
       
   158     }
       
   159 
       
   160     /**
       
   161      * Test one to one mapping
       
   162      *
       
   163      * @return void
       
   164      */
       
   165     public function testOneToOnePropsIdentity() {
       
   166 
       
   167         $properties = [
       
   168             'http://purl.org/dc/elements/1.1/description',
       
   169             'http://purl.org/dc/elements/1.1/language',
       
   170             'http://purl.org/dc/elements/1.1/publisher',
       
   171             'http://purl.org/dc/elements/1.1/rights',
       
   172             'http://purl.org/dc/terms/license',
       
   173             'http://purl.org/dc/elements/1.1/subject',
       
   174             'http://purl.org/dc/elements/1.1/title',
       
   175             'http://purl.org/dc/terms/available',
       
   176             'http://purl.org/dc/terms/created',
       
   177             'http://purl.org/dc/terms/issued',
       
   178             'http://purl.org/dc/elements/1.1/type',
       
   179             'http://purl.org/dc/elements/1.1/language',
       
   180             'http://purl.org/dc/terms/isPartOf',
       
   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 }