|
1 <?php |
|
2 namespace CorpusParole\Libraries\Mappers; |
|
3 |
|
4 use CorpusParole\Libraries\CocoonUtils; |
|
5 |
|
6 use EasyRdf\Graph; |
|
7 use EasyRdf\Literal; |
|
8 use EasyRdf\Resource; |
|
9 |
|
10 |
|
11 abstract class CocoonContentRdfMapper extends CocoonAbstractRdfMapper { |
|
12 |
|
13 |
|
14 protected function mapResource($res, $outputGraph) { |
|
15 $this->mapMainGraph($res, $outputGraph); |
|
16 //map collection |
|
17 $this->mapCollections($res); |
|
18 } |
|
19 |
|
20 abstract protected function mapWebResources($res, $outputGraph); |
|
21 |
|
22 protected function mapMainGraph($res, $outputGraph) { |
|
23 $this->mapAggregationNode($res, $outputGraph); |
|
24 $this->mapProvidedCHO($res, $outputGraph); |
|
25 $this->mapWebResources($res, $outputGraph); |
|
26 } |
|
27 |
|
28 /** |
|
29 * Build the aggregation node |
|
30 */ |
|
31 protected function mapAggregationNode($res, $outputGraph) { |
|
32 $resId = CocoonUtils::getIdFromUri($this->getResourceBaseId($res)); |
|
33 $resUri = CocoonUtils::getCorpusUriFromId($resId); |
|
34 |
|
35 $aggregationNode = $outputGraph->resource($resUri, 'ore:Aggregation'); |
|
36 |
|
37 $aggregationResource = $aggregationNode->addResource('edm:aggregatedCHO', $this->getResourceBaseId($res)); |
|
38 |
|
39 $aggregationNode->addLiteral('edm:provider', config('corpusparole.edm_provider'), 'fr'); |
|
40 |
|
41 $publishersInputs = $res->all($this->inputGraph->resource('http://purl.org/dc/elements/1.1/publisher')); |
|
42 if(count($publishersInputs) == 0) { |
|
43 $provider = Literal::create(config('corpusparole.edm_provider'), 'fr'); |
|
44 } |
|
45 else { |
|
46 $provider = $publishersInputs[0]; |
|
47 //TODO: if this is a resource, get id from it (viaf) |
|
48 } |
|
49 $aggregationNode->add('edm:dataProvider', $provider); |
|
50 |
|
51 $aggregationNode->addResource('edm:isShownAt', CocoonUtils::getCocoonPubUrl($resId)); |
|
52 |
|
53 $master = null; |
|
54 $masterList = $res->all($this->inputGraph->resource('http://crdo.risc.cnrs.fr/schemas/master')); |
|
55 if(count($masterList)==0) { |
|
56 $masterList = $res->all($this->inputGraph->resource('http://purl.org/dc/terms/isFormatOf')); |
|
57 } |
|
58 if(count($masterList)>0) { |
|
59 $aggregationNode->add('edm:isShownBy', $masterList[0]); |
|
60 } |
|
61 |
|
62 $license = $res->get('dc:license'); |
|
63 $matches = []; |
|
64 |
|
65 if( ($license instanceof Resource) && |
|
66 (preg_match('/http\:\/\/creativecommons\.org\/licenses\/([a-z-]+)\/[\d\.]+\//', $license->getUri(), $matches) > 0) ) { |
|
67 $license = "http://creativecommons.org/licenses/$matches[1]/4.0/"; |
|
68 } |
|
69 else { |
|
70 $license = config('corpusparole.corpus_doc_default_cc_rights'); |
|
71 } |
|
72 |
|
73 $aggregationNode->addResource('edm:rights', $license); |
|
74 } |
|
75 |
|
76 protected function propertyTypeMap($providedCHOResource, $prop, $value) { |
|
77 $providedCHOResource->add($prop, $value); |
|
78 } |
|
79 |
|
80 protected function propertyReferenceCorrectMap($providedCHOResource, $prop, $value) { |
|
81 $providedCHOResource->add('http://purl.org/dc/terms/references', $value); |
|
82 } |
|
83 |
|
84 /** |
|
85 * Build the provided CHO. |
|
86 */ |
|
87 private function mapProvidedCHO($res, $outputGraph) { |
|
88 |
|
89 $providedCHOResource = $outputGraph->resource($this->getResourceBaseId($res), 'edm:ProvidedCHO'); |
|
90 |
|
91 $this->addCHOResourceProperties($providedCHOResource, $res, $outputGraph); |
|
92 |
|
93 $this->addDateProperties($providedCHOResource, $res, $outputGraph); |
|
94 $this->addSpatialProperties($providedCHOResource, $res, $outputGraph); |
|
95 |
|
96 } |
|
97 |
|
98 protected function addCHOResourceProperties($providedCHOResource, $res, $outputGraph) { |
|
99 $this->applyPropertiesToRes($res, $providedCHOResource, [ |
|
100 ['http://purl.org/dc/terms/tableOfContents', null], |
|
101 ['http://purl.org/dc/elements/1.1/description', null], |
|
102 ['http://purl.org/dc/elements/1.1/language', null], |
|
103 ['http://purl.org/dc/elements/1.1/publisher', null], |
|
104 ['http://purl.org/dc/elements/1.1/rights', null], |
|
105 ['http://purl.org/dc/elements/1.1/type', 'propertyTypeMap'], |
|
106 ['http://purl.org/dc/terms/license', null], |
|
107 ['http://purl.org/dc/elements/1.1/subject', null], |
|
108 ['http://purl.org/dc/elements/1.1/title', null], |
|
109 ['http://purl.org/dc/elements/1.1/language', null], |
|
110 ['http://purl.org/dc/terms/accessRights', 'propertyTrimMap'], |
|
111 ['http://purl.org/dc/terms/extent', null], |
|
112 ['http://purl.org/dc/terms/isPartOf', null], |
|
113 ['http://purl.org/dc/elements/1.1/source', null], |
|
114 ['http://purl.org/dc/terms/medium', null], |
|
115 ['http://purl.org/dc/terms/alternative', null], |
|
116 ['http://purl.org/dc/terms/bibliographicCitation', null], |
|
117 ['http://purl.org/dc/elements/1.1/identifier', null], |
|
118 ['http://purl.org/dc/terms/references', null], |
|
119 ['http://purl.org/dc/elements/1.1/reference', 'propertyReferenceCorrectMap'], |
|
120 ['http://purl.org/dc/elements/1.1/coverage', null], |
|
121 ['http://purl.org/dc/elements/1.1/relation', null], |
|
122 ['http://purl.org/dc/elements/1.1/creator', null], |
|
123 ['http://www.language-archives.org/OLAC/1.1/annotator', 'propertyOlacRoleMap'], |
|
124 ['http://www.language-archives.org/OLAC/1.1/author', 'propertyOlacRoleMap'], |
|
125 ['http://www.language-archives.org/OLAC/1.1/compiler', 'propertyOlacRoleMap'], |
|
126 ['http://www.language-archives.org/OLAC/1.1/consultant', 'propertyOlacRoleMap'], |
|
127 ['http://www.language-archives.org/OLAC/1.1/data_inputter', 'propertyOlacRoleMap'], |
|
128 ['http://www.language-archives.org/OLAC/1.1/depositor', 'propertyOlacRoleMap'], |
|
129 ['http://www.language-archives.org/OLAC/1.1/developer', 'propertyOlacRoleMap'], |
|
130 ['http://www.language-archives.org/OLAC/1.1/editor', 'propertyOlacRoleMap'], |
|
131 ['http://www.language-archives.org/OLAC/1.1/illustrator', 'propertyOlacRoleMap'], |
|
132 ['http://www.language-archives.org/OLAC/1.1/interpreter', 'propertyOlacRoleMap'], |
|
133 ['http://www.language-archives.org/OLAC/1.1/interviewer', 'propertyOlacRoleMap'], |
|
134 ['http://www.language-archives.org/OLAC/1.1/participant', 'propertyOlacRoleMap'], |
|
135 ['http://www.language-archives.org/OLAC/1.1/performer', 'propertyOlacRoleMap'], |
|
136 ['http://www.language-archives.org/OLAC/1.1/photographer', 'propertyOlacRoleMap'], |
|
137 ['http://www.language-archives.org/OLAC/1.1/recorder', 'propertyOlacRoleMap'], |
|
138 ['http://www.language-archives.org/OLAC/1.1/researcher', 'propertyOlacRoleMap'], |
|
139 ['http://www.language-archives.org/OLAC/1.1/research_participant', 'propertyOlacRoleMap'], |
|
140 ['http://www.language-archives.org/OLAC/1.1/responder', 'propertyOlacRoleMap'], |
|
141 ['http://www.language-archives.org/OLAC/1.1/signer', 'propertyOlacRoleMap'], |
|
142 ['http://www.language-archives.org/OLAC/1.1/singer', 'propertyOlacRoleMap'], |
|
143 ['http://www.language-archives.org/OLAC/1.1/speaker', 'propertyOlacRoleMap'], |
|
144 ['http://www.language-archives.org/OLAC/1.1/sponsor', 'propertyOlacRoleMap'], |
|
145 ['http://www.language-archives.org/OLAC/1.1/transcriber', 'propertyOlacRoleMap'], |
|
146 ['http://www.language-archives.org/OLAC/1.1/translator', 'propertyOlacRoleMap'], |
|
147 ]); |
|
148 |
|
149 } |
|
150 |
|
151 protected function addDateToWebResource($sourceRes, $targetRes) { |
|
152 |
|
153 $this->applyPropertiesToRes($sourceRes, $targetRes, [ |
|
154 ['http://purl.org/dc/terms/created', null], |
|
155 ['http://purl.org/dc/terms/issued', null], |
|
156 ]); |
|
157 } |
|
158 |
|
159 } |