# HG changeset patch # User ymh # Date 1453227383 -3600 # Node ID be2d3b30b2e04fbe776ba21d932027e8e1632096 # Parent 16e1473a6a994979ee6d9f603d14e8636028fda4 change isPartOf to edm:isGatheredInto for collections diff -r 16e1473a6a99 -r be2d3b30b2e0 server/src/app/Libraries/CocoonUtils.php --- a/server/src/app/Libraries/CocoonUtils.php Fri Jan 22 17:43:25 2016 +0100 +++ b/server/src/app/Libraries/CocoonUtils.php Tue Jan 19 19:16:23 2016 +0100 @@ -1,6 +1,8 @@ getUri()), "collection", strlen(config('corpusparole.cocoon_doc_id_base_uri'))) !== FALSE); + } + } diff -r 16e1473a6a99 -r be2d3b30b2e0 server/src/app/Libraries/Mappers/CocoonAbstractRdfMapper.php --- a/server/src/app/Libraries/Mappers/CocoonAbstractRdfMapper.php Fri Jan 22 17:43:25 2016 +0100 +++ b/server/src/app/Libraries/Mappers/CocoonAbstractRdfMapper.php Tue Jan 19 19:16:23 2016 +0100 @@ -131,13 +131,11 @@ protected function mapCollections($res) { $collections = $res->all('dc:isPartOf'); foreach($collections as $coll) { - if($coll instanceof Resource) { + if(CocoonUtils::isResourceCollection($coll)) { $collUri = $coll->getUri(); - if(strpos(strtolower($collUri), "collection", strlen(config('corpusparole.cocoon_doc_id_base_uri'))) !== FALSE) { - $collectionGraph = new Graph($collUri); - $this->outputGraphes[$collUri] = $collectionGraph; - $collectionGraph->resource($collUri, 'edm:Collection'); - } + $collectionGraph = new Graph($collUri); + $this->outputGraphes[$collUri] = $collectionGraph; + $collectionGraph->resource($collUri, 'edm:Collection'); } } } diff -r 16e1473a6a99 -r be2d3b30b2e0 server/src/app/Libraries/Mappers/CocoonContentRdfMapper.php --- a/server/src/app/Libraries/Mappers/CocoonContentRdfMapper.php Fri Jan 22 17:43:25 2016 +0100 +++ b/server/src/app/Libraries/Mappers/CocoonContentRdfMapper.php Tue Jan 19 19:16:23 2016 +0100 @@ -81,6 +81,15 @@ $providedCHOResource->add('http://purl.org/dc/terms/references', $value); } + protected function propertyCollectionMap($providedCHOResource, $prop, $value) { + // if this is a collection, we use the edm:isGatheredInto property + if(CocoonUtils::isResourceCollection($value)) { + $providedCHOResource->add('http://www.europeana.eu/schemas/edm/isGatheredInto', $value); + } else { + $providedCHOResource->add($prop, $value); + } + } + /** * Build the provided CHO. */ @@ -109,7 +118,7 @@ ['http://purl.org/dc/elements/1.1/language', null], ['http://purl.org/dc/terms/accessRights', 'propertyTrimMap'], ['http://purl.org/dc/terms/extent', null], - ['http://purl.org/dc/terms/isPartOf', null], + ['http://purl.org/dc/terms/isPartOf', 'propertyCollectionMap'], ['http://purl.org/dc/terms/abstract', null], ['http://purl.org/dc/elements/1.1/source', null], ['http://purl.org/dc/terms/medium', null], diff -r 16e1473a6a99 -r be2d3b30b2e0 server/src/tests/libraries/Mappers/CocoonSoundRdfMapperTest.php --- a/server/src/tests/libraries/Mappers/CocoonSoundRdfMapperTest.php Fri Jan 22 17:43:25 2016 +0100 +++ b/server/src/tests/libraries/Mappers/CocoonSoundRdfMapperTest.php Tue Jan 19 19:16:23 2016 +0100 @@ -36,7 +36,7 @@ , ; " Freely available for non-commercial use" ; ; - , ; + , , ; "PT0H47M16S" ; "1969-04-11"^^ ; "FR"^^ , , "France, Centre, Loiret, Orléans"@fr ; @@ -272,7 +272,6 @@ 'http://purl.org/dc/elements/1.1/type', 'http://purl.org/dc/elements/1.1/language', 'http://purl.org/dc/terms/medium', - 'http://purl.org/dc/terms/isPartOf', 'http://purl.org/dc/elements/1.1/source', 'http://purl.org/dc/terms/alternative', 'http://purl.org/dc/terms/modified', @@ -305,10 +304,40 @@ } /** - * Test one to one mapping spatial info - * - * @return void - */ + * Test mapping for isPartOf + * + * @return void + */ + public function testOneToOneProvidedCHOIsPartOf() { + $providedCHO = $this->resGraphes['BASE']->get('edm:ProvidedCHO', '^rdf:type'); + $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type'); + + $this->assertNotNull($providedCHO); + $this->assertNotNull($sourceNode); + + $isGatheredInto = $providedCHO->all($this->resGraphes['BASE']->resource('http://www.europeana.eu/schemas/edm/isGatheredInto')); + $this->assertCount(2, $isGatheredInto, "Must have two collection node"); + + $ispartOf = $providedCHO->all($this->resGraphes['BASE']->resource('http://purl.org/dc/terms/isPartOf')); + $this->assertCount(1, $ispartOf, "Must have one collection node"); + + $outputValuesStr = []; + foreach($providedCHO->all($this->resGraphes['BASE']->resource('http://www.europeana.eu/schemas/edm/isGatheredInto')) as $outputValue) { + array_push($outputValuesStr, strval($outputValue)); + } + $this->assertNotEmpty($outputValuesStr, "we must found some values to test isGatheredInto"); + + $this->assertContains("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE", $outputValuesStr, "http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE not found in output graph"); + $this->assertContains("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ESLO1", $outputValuesStr, "http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ESLO1 not found in output graph"); + + $this->assertEquals("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ESLO1_ENT_010", strval($providedCHO->get($this->resGraphes['BASE']->resource('http://purl.org/dc/terms/isPartOf'))), "the isPartOf mus equals http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ESLO1_ENT_010"); + } + + /** + * Test one to one mapping spatial info + * + * @return void + */ public function testOneToOneProvidedCHOSpatial() { $providedCHO = $this->resGraphes['BASE']->get('edm:ProvidedCHO', '^rdf:type'); $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type'); @@ -468,7 +497,6 @@ } - /** * Test collection graph creation * @return void