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