--- 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 @@
<?php
namespace CorpusParole\Libraries;
+use EasyRdf\Resource;
+
class CocoonUtils {
const OLAC_ROLES = [
@@ -61,4 +63,9 @@
return rtrim(config('corpusparole.cocoon_doc_pub_base_uri'), '/')."/$id";
}
+ public static function isResourceCollection($res) {
+ return $res instanceof Resource &&
+ (strpos(strtolower($res->getUri()), "collection", strlen(config('corpusparole.cocoon_doc_id_base_uri'))) !== FALSE);
+ }
+
}
--- 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');
}
}
}
--- 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],
--- 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 @@
<http://purl.org/dc/terms/isFormatOf> <http://cocoon.huma-num.fr/data/eslo/ESLO1_ENT_019_22km.wav> , <http://cocoon.huma-num.fr/data/eslo/ESLO1_ENT_019.mp3> ;
<http://purl.org/dc/terms/accessRights> " Freely available for non-commercial use" ;
<http://purl.org/dc/terms/license> <http://creativecommons.org/licenses/by-nc-sa/3.0/> ;
- <http://purl.org/dc/terms/isPartOf> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE> , <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ESLO1> ;
+ <http://purl.org/dc/terms/isPartOf> <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_LANGUESDEFRANCE> , <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-COLLECTION_ESLO1>, <http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ESLO1_ENT_010> ;
<http://purl.org/dc/terms/extent> "PT0H47M16S" ;
<http://purl.org/dc/terms/created> "1969-04-11"^^<http://purl.org/dc/terms/W3CDTF> ;
<http://purl.org/dc/terms/spatial> "FR"^^<http://purl.org/dc/terms/ISO3166> , <http://vocab.getty.edu/tgn/7008337> , "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