server/src/tests/libraries/Mergers/CocoonCollectionRdfMergerTest.php
changeset 18 f2a40bbc27f6
child 112 7a542145832c
equal deleted inserted replaced
17:ac3dc090e987 18:f2a40bbc27f6
       
     1 <?php
       
     2 
       
     3 use CorpusParole\Libraries\Mergers\CocoonCollectionRdfMerger;
       
     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 CocoonCollectionRdfMergerTest extends TestCase
       
    15 {
       
    16 
       
    17     const TEST_INPUT_DOCS = [
       
    18         'BASE' => <<<EOT
       
    19         @prefix edm: <http://www.europeana.eu/schemas/edm/> .
       
    20         @prefix dc11: <http://purl.org/dc/elements/1.1/> .
       
    21         @prefix dc: <http://purl.org/dc/terms/> .
       
    22         @prefix olac: <http://www.language-archives.org/OLAC/1.1/> .
       
    23         @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
       
    24         @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
       
    25         @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
       
    26         @prefix owl: <http://www.w3.org/2002/07/owl#> .
       
    27 
       
    28         <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000>
       
    29           a edm:Collection ;
       
    30           dc11: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 ;
       
    31           dc11:language <http://lexvo.org/id/iso639-3/gsw> ;
       
    32           dc11:publisher <http://viaf.org/viaf/142432638>, "Fédération CLESTHIA", <http://viaf.org/viaf/154862993> ;
       
    33           dc11:rights "Copyright (c) Département de dialectologie alsacienne et mosellane de l'Université de Strasbourg" ;
       
    34           dc11:type <http://purl.org/dc/dcmitype/Collection> ;
       
    35           dc:license <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
       
    36           dc11:subject <http://lexvo.org/id/iso639-3/fra> ;
       
    37           dc11:title "Corpus de Français Parlé Parisien des années 2000 (CFPP)"@fr ;
       
    38           dc:accessRights "Freely available for non-commercial use" ;
       
    39           dc:isPartOf <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ALA> ;
       
    40           olac:compiler "Branca-Rosoff, Sonia", "Fleury, Serge", "Lefeuvre, Florence", "Pires, Mat" ;
       
    41           dc11:contributor "Branca-Rosoff, Sonia", "Fleury, Serge", "Lefeuvre, Florence", "Pires, Mat", <http://viaf.org/viaf/93752300>, "Ville de Paris ", "Délégation générale à la langue française et aux langues de France " ;
       
    42           olac:data_inputter "Branca-Rosoff, Sonia", "Lefeuvre, Florence", "Pires, Mat" ;
       
    43           olac:depositor <http://viaf.org/viaf/93752300> ;
       
    44           olac:developer "Fleury, Serge" ;
       
    45           olac:interviewer "Branca-Rosoff, Sonia", "Lefeuvre, Florence", "Pires, Mat" ;
       
    46           olac:researcher "Branca-Rosoff, Sonia", "Fleury, Serge", "Lefeuvre, Florence", "Pires, Mat" ;
       
    47           olac:sponsor "Ville de Paris ", "Délégation générale à la langue française et aux langues de France " ;
       
    48           olac:transcriber "Branca-Rosoff, Sonia", "Lefeuvre, Florence", "Pires, Mat" ;
       
    49           dc:available "2013-04-12"^^dc:W3CDTF ;
       
    50           dc:created "start=1988; end=1989"^^dc:Period ;
       
    51           dc:issued "2013-04-12T22:20:23+02:00"^^dc:W3CDTF ;
       
    52           dc:modified "2014-05-10T20:16:27+02:00"^^dc:W3CDTF ;
       
    53           dc:spatial [
       
    54             a edm:Place ;
       
    55             geo:lat "48.8667"^^xsd:float ;
       
    56             geo:long "2.3333"^^xsd:float ;
       
    57             skos:note "FR"^^dc:ISO3166, "France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr ;
       
    58             owl:sameAs <http://vocab.getty.edu/tgn/7008038>
       
    59           ] .
       
    60 EOT
       
    61         ,
       
    62         'SOURCE' => <<<EOT
       
    63         @prefix edm: <http://www.europeana.eu/schemas/edm/> .
       
    64         @prefix dc11: <http://purl.org/dc/elements/1.1/> .
       
    65         @prefix dc: <http://purl.org/dc/terms/> .
       
    66         @prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
       
    67         @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
       
    68         @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
       
    69         @prefix owl: <http://www.w3.org/2002/07/owl#> .
       
    70 
       
    71         <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000>
       
    72           a edm:Collection ;
       
    73           dc11:title "Other title"@fr ;
       
    74           dc:created "start=1988; end=1989"^^dc:Period ;
       
    75           dc:issued "2013-04-12T22:20:23+02:00"^^dc:W3CDTF ;
       
    76           dc:modified "2014-05-10T20:16:27+02:00"^^dc:W3CDTF ;
       
    77           dc11:language <http://lexvo.org/id/iso639-3/gsw>, <http://lexvo.org/id/iso639-3/fra> ;
       
    78           dc:spatial [
       
    79             a edm:Place ;
       
    80             geo:lat "89.8667"^^xsd:float ;
       
    81             geo:long "55.3333"^^xsd:float ;
       
    82             skos:note "FR"^^dc:ISO3166, "France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr, "Other place very important"@fr ;
       
    83             owl:sameAs <http://vocab.getty.edu/tgn/1234567890>
       
    84           ] .
       
    85 EOT
       
    86     ];
       
    87 
       
    88     const TEST_INPUT_ID = "crdo-COLLECTION_CFPP2000";
       
    89     const TEST_GRAPH_URI = "http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-COLLECTION_CFPP2000";
       
    90     const TEST_CHO_URI = "http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000";
       
    91 
       
    92 
       
    93     private $inputGraphes = [];
       
    94     private $resGraph;
       
    95     private $merger;
       
    96 
       
    97     function __construct(string $name = null) {
       
    98         parent::__construct($name);
       
    99     }
       
   100 
       
   101     public function setUp() {
       
   102         parent::setUp();
       
   103 
       
   104         foreach(CocoonCollectionRdfMergerTest::TEST_INPUT_DOCS as $key => $inputDoc) {
       
   105             $this->inputGraphes[$key] = new Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000", $inputDoc);
       
   106         }
       
   107 
       
   108         $this->merger = new CocoonCollectionRdfMerger();
       
   109         $this->resGraph = $this->merger->mergeGraph($this->inputGraphes['BASE'], $this->inputGraphes['SOURCE']);
       
   110     }
       
   111 
       
   112     public function tearDown() {
       
   113         parent::tearDown();
       
   114     }
       
   115 
       
   116     /**
       
   117      * Just test that the construct and setup are ok
       
   118      *
       
   119      * @return void
       
   120      */
       
   121     public function testInit()
       
   122     {
       
   123         $this->assertTrue(true);
       
   124         echo $this->resGraph->serialise('turtle');
       
   125     }
       
   126 
       
   127     /**
       
   128      * test the result graph.
       
   129      *
       
   130      * @return void
       
   131      */
       
   132     public function testResGraph() {
       
   133         $this->assertNotNull($this->resGraph, "Res graph must not be null");
       
   134         $this->assertEquals("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000", $this->resGraph->getUri(), "graph uri must be equals to http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-CFPP2000_35_SOUND");
       
   135     }
       
   136 
       
   137     /**
       
   138      * test the merged Aggregation
       
   139      *
       
   140      * @return void
       
   141      */
       
   142     public function testCollectionResource() {
       
   143         $collectionResList = $this->resGraph->allOfType('http://www.europeana.eu/schemas/edm/Collection');
       
   144         $this->assertCount(1, $collectionResList, "Only one Collection node");
       
   145         $collectionRes = $collectionResList[0];
       
   146 
       
   147         $this->assertEquals("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000",$collectionRes->getUri(),"Collection node uri must be http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_CFPP2000");
       
   148 
       
   149         $singleValuesRes = [
       
   150             'http://purl.org/dc/elements/1.1/title' => ['size'=>1, 'val' => new Literal("Corpus de Français Parlé Parisien des années 2000 (CFPP)", "fr", null)],
       
   151             'http://purl.org/dc/terms/available' => ['size'=>1, 'val' => new Literal("2013-04-12", null, "dc:W3CDTF")],
       
   152             'http://purl.org/dc/terms/created' => ['size'=>1, 'val' => new Literal("start=1988; end=1989", null, "dc:Period")],
       
   153             'http://purl.org/dc/terms/issued' => ['size'=>1, 'val' => new Literal("2013-04-12T22:20:23+02:00", null, "dc:W3CDTF")],
       
   154             'http://purl.org/dc/terms/modified' => ['size'=>1, 'val' => new Literal("2014-05-10T20:16:27+02:00", null, "dc:W3CDTF")],
       
   155             'http://purl.org/dc/elements/1.1/language' => ['size' => 2, 'val' => [
       
   156                 $this->resGraph->resource("http://lexvo.org/id/iso639-3/gsw"),
       
   157                 $this->resGraph->resource("http://lexvo.org/id/iso639-3/fra"),
       
   158             ]]
       
   159         ];
       
   160 
       
   161         foreach($singleValuesRes as $property => $resVal) {
       
   162             $resList = $collectionRes->all($this->inputGraphes['BASE']->resource($property));
       
   163             $this->assertCount($resVal['size'], $resList, "$property list size $resVal[size]");
       
   164             if($resVal['size'] == 1) {
       
   165                 $this->assertEquals($resVal['val'], $resList[0], "$property size one not equals");
       
   166             }
       
   167             else {
       
   168                 $this->assertEquals($resVal['val'], $resList, "$property size more than one not equals");
       
   169             }
       
   170         }
       
   171 
       
   172     }
       
   173 
       
   174     /**
       
   175     * Test one to one mapping spatial info
       
   176     *
       
   177     * @return void
       
   178     */
       
   179     public function testProvidedCHOSpatial() {
       
   180         $collection = $this->resGraph->get('edm:Collection', '^rdf:type');
       
   181 
       
   182         $this->assertNotNull($collection);
       
   183 
       
   184         $spatials = $collection->all($this->resGraph->resource('http://purl.org/dc/terms/spatial'));
       
   185 
       
   186         $this->assertCount(1, $spatials, "Must have only one spatial node");
       
   187         $spatial = $spatials[0];
       
   188         $this->assertTrue($spatial->isBNode(),"spatial node must be blank");
       
   189         $this->assertEquals("edm:Place", $spatial->type(), "spatial node type must be edm:Place");
       
   190 
       
   191         $lats = $spatial->all('geo:lat');
       
   192         $this->assertCount(1, $lats, "One latitude");
       
   193         $this->assertInstanceOf("EasyRdf\Literal", $lats[0], "Latitude must be a litteral");
       
   194         $this->assertEquals(Literal::create("48.8667", null, 'xsd:float'), $lats[0], "lat must be '48.8667'^^xsd:float");
       
   195 
       
   196         $longs = $spatial->all('geo:long');
       
   197         $this->assertCount(1, $longs, "One longitude");
       
   198         $this->assertInstanceOf("EasyRdf\Literal", $longs[0], "Longitude must be a litteral");
       
   199         $this->assertEquals(Literal::create("2.3333", null, 'xsd:float'), $longs[0], "long must be '2.3333'^^xsd:float");
       
   200 
       
   201         $notes = $spatial->all('skos:note');
       
   202         $this->assertCount(3, $notes, "3 notes");
       
   203         $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $notes, "Notes mus be only literals");
       
   204         $this->assertEquals(Literal::create("FR", null, "dc:ISO3166"), $notes[0], "notes contains 'FR'^^dc:ISO3166");
       
   205         $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");
       
   206         $this->assertEquals(Literal::create("Other place very important", "fr", null), $notes[2], "notes contains 'Other place very important'@fr");
       
   207 
       
   208         $sameas = $spatial->all('owl:sameAs');
       
   209         $this->assertCount(1, $sameas, "1 same as");
       
   210         $this->assertContainsOnlyInstancesOf("EasyRdf\Resource", $sameas, "Notes mus be only resources");
       
   211         $this->assertEquals('http://vocab.getty.edu/tgn/7008038', $sameas[0]->getUri(), "uri must be http://vocab.getty.edu/tgn/7008038");
       
   212     }
       
   213 
       
   214 
       
   215 
       
   216 }