23 parent::__construct($uri, $graph); |
23 parent::__construct($uri, $graph); |
24 } |
24 } |
25 |
25 |
26 private $id = null; |
26 private $id = null; |
27 |
27 |
|
28 // memoization |
|
29 private $providedCHO = null; |
|
30 private $title = false; |
|
31 private $publishers = null; |
|
32 private $mediaArray = null; |
|
33 private $issued = null; |
|
34 private $modified = null; |
|
35 |
|
36 public function getProvidedCHO() { |
|
37 if(is_null($this->providedCHO)) { |
|
38 $this->providedCHO = $this->get("<http://www.europeana.eu/schemas/edm/aggregatedCHO>"); |
|
39 } |
|
40 return $this->providedCHO; |
|
41 } |
|
42 |
|
43 private function clearMemoizationCache() { |
|
44 $this->providedCHO = null; |
|
45 $this->title = false; |
|
46 $this->publishers = null; |
|
47 $this->mediaArray = null; |
|
48 $this->issued = null; |
|
49 $this->modified = null; |
|
50 } |
|
51 |
28 public function getId() { |
52 public function getId() { |
29 if(is_null($this->id)) { |
53 if(is_null($this->id)) { |
30 $this->id = CocoonUtils::getIdFromUri($this->uri); |
54 $this->id = CocoonUtils::getIdFromCorpusUri($this->uri); |
31 } |
55 } |
32 return $this->id; |
56 return $this->id; |
33 } |
57 } |
34 |
58 |
35 public function getTitle() { |
59 public function getTitle() { |
36 try { |
60 if($this->title === false) { |
37 return $this->getLiteral('<http://purl.org/dc/elements/1.1/title>'); |
61 try { |
38 } catch(\Exception $e) { |
62 $this->title = $this->getProvidedCHO()->getLiteral('<http://purl.org/dc/elements/1.1/title>'); |
39 return null; |
63 } catch(\Exception $e) { |
40 } |
64 $this->title = null; |
|
65 } |
|
66 } |
|
67 return $this->title; |
41 } |
68 } |
42 |
69 |
43 public function getPublishers() { |
70 public function getPublishers() { |
44 try { |
71 if(is_null($this->publishers)) { |
45 return $this->allLiterals('dc11:publisher'); |
72 try { |
46 } catch(\Exception $e) { |
73 $this->publishers = $this->getProvidedCHO()->all('dc11:publisher'); |
47 return []; |
74 } catch(\Exception $e) { |
48 } |
75 $this->publishers = []; |
|
76 } |
|
77 } |
|
78 return $this->publishers; |
|
79 } |
|
80 |
|
81 public function getIssued() { |
|
82 if(is_null($this->issued)) { |
|
83 try { |
|
84 $this->issued = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/issued>"); |
|
85 } catch(\Exception $e) { |
|
86 $this->issued = null; |
|
87 } |
|
88 } |
|
89 return $this->issued; |
|
90 } |
|
91 |
|
92 public function getModified() { |
|
93 if(is_null($this->modified)) { |
|
94 try { |
|
95 $this->modified = $this->getProvidedCHO()->getLiteral("<http://purl.org/dc/terms/modified>"); |
|
96 if(is_null($this->modified)) { |
|
97 $this->modified = $this->getIssued(); |
|
98 } |
|
99 else { |
|
100 $this->modified = $this->modified->getValue(); |
|
101 } |
|
102 } catch(\Exception $e) { |
|
103 $this->modified = null; |
|
104 } |
|
105 } |
|
106 return $this->modified; |
49 } |
107 } |
50 |
108 |
51 public function getMediaArray() { |
109 public function getMediaArray() { |
52 |
110 |
53 //TODO: add media type |
111 if(is_null($this->mediaArray)) { |
54 $res = []; |
112 //TODO: add media type |
55 $formats = []; |
113 $this->mediaArray = []; |
56 try { |
114 |
57 $formats = $this->allResources("dc:isFormatOf"); |
115 $master = $this->get('<http://www.europeana.eu/schemas/edm/isShownBy>'); |
58 } catch(\Exception $e) { |
116 $masterUrl = is_null($master)?null:$master->getUri(); |
59 // do nothing |
117 |
60 } |
118 foreach($this->graph->allOfType("<http://www.europeana.eu/schemas/edm/WebResources>") as $webResource) { |
61 foreach ($formats as $f) { |
119 $extent = $webResource->getLiteral("dc:extent"); |
62 $uri = $f->getUri(); |
120 $extent = is_null($extent)?null:$extent->getValue(); |
63 $mimetype = Utils::getMimetype($uri); |
121 $extent_ms = Utils::iso8601IntervalToMillis($extent); |
64 array_push($res, ["url" => $uri, "format" => $mimetype]); |
122 $format = $webResource->getLiteral("dc11:format"); |
65 } |
123 |
66 |
124 $this->mediaArray[$webResource->getUri()] = [ |
67 $format = null; |
125 'url' => $webResource->getUri(), |
68 try { |
126 'format' => is_null($format)?null:$format->getValue(), |
69 $format = $this->getLiteral('dc11:format'); |
127 'extent' => $extent, |
70 } catch(\Exception $e) { |
128 'extent_ms' => $extent_ms, |
71 // do nothing |
129 'master' => (($webResource->getUri() === $masterUrl)?true:false) |
72 } |
130 ]; |
73 array_push($res, ["url" => $this->getUri(), "format" => $format]); |
131 } |
74 return $res; |
132 } |
|
133 return $this->mediaArray; |
75 } |
134 } |
76 |
135 |
77 public function getTypes() { |
136 public function getTypes() { |
78 return $this->all('dc11:type'); |
137 return $this->getProvidedCHO()->all('dc11:type'); |
79 } |
138 } |
80 |
139 |
81 public function getDiscourseTypes() { |
140 public function getDiscourseTypes() { |
82 return array_values(array_filter($this->getTypes(), function($v) { |
141 return array_values(array_filter($this->getTypes(), function($v) { |
83 return $v instanceof Literal && $v->getDatatypeUri() === Config::get('constants.OLAC_DISCOURSE_TYPE')['uri']; |
142 return $v instanceof Literal && $v->getDatatypeUri() === Config::get('corpusparole.olac_discourse_type')['uri']; |
84 })); |
143 })); |
85 } |
144 } |
86 |
145 |
87 public function getOtherTypes() { |
146 public function getOtherTypes() { |
88 $res = array_values(array_filter($this->getTypes(), function($v) { |
147 $res = array_values(array_filter($this->getTypes(), function($v) { |
89 return $v instanceof Resource || $v->getDatatypeUri() !== Config::get('constants.OLAC_DISCOURSE_TYPE')['uri']; |
148 return $v instanceof Resource || $v->getDatatypeUri() !== Config::get('corpusparole.olac_discourse_type')['uri']; |
90 })); |
149 })); |
91 return $res; |
150 return $res; |
92 } |
151 } |
93 |
152 |
|
153 /** |
|
154 * change discourse type list |
|
155 */ |
94 public function updateDiscourseTypes(array $discoursesTypes) { |
156 public function updateDiscourseTypes(array $discoursesTypes) { |
95 |
157 |
96 $this->startDelta(); |
158 $this->startDelta(); |
97 |
159 |
|
160 //delete |
98 foreach($this->getDiscourseTypes() as $discourseType) { |
161 foreach($this->getDiscourseTypes() as $discourseType) { |
99 $this->delete('dc11:type', $discourseType); |
162 $literalValue = new Literal($discourseType, null, Config::get('corpusparole.olac_discourse_type')['uri']); |
100 $this->currentDelta->getDeletedGraph()->add($this, 'dc11:type', new Literal($discourseType, null, Config::get('constants.OLAC_DISCOURSE_TYPE')['uri'])); |
163 $this->getProvidedCHO()->delete('dc11:type', $literalValue); |
101 } |
164 $this->currentDelta->getDeletedGraph()->add($this->getProvidedCHO(), 'dc11:type', new Literal($discourseType, null, Config::get('corpusparole.olac_discourse_type')['uri'])); |
102 // re-add them |
165 } |
103 |
166 |
|
167 // and re-add them |
104 foreach($discoursesTypes as $dType) { |
168 foreach($discoursesTypes as $dType) { |
105 $this->add('dc11:type', new Literal($dType, null, Config::get('constants.OLAC_DISCOURSE_TYPE')['uri'])); |
169 $this->getProvidedCHO()->add('dc11:type', new Literal($dType, null, Config::get('corpusparole.olac_discourse_type')['uri'])); |
106 $this->currentDelta->getAddedGraph()->add($this, 'dc11:type', new Literal($dType, null, Config::get('constants.OLAC_DISCOURSE_TYPE')['uri'])); |
170 $this->currentDelta->getAddedGraph()->add($this->getProvidedCHO(), 'dc11:type', new Literal($dType, null, Config::get('corpusparole.olac_discourse_type')['uri'])); |
107 } |
171 } |
|
172 |
|
173 $this->clearMemoizationCache(); |
108 } |
174 } |
109 |
175 |
110 public function isIsomorphic($doc) { |
176 public function isIsomorphic($doc) { |
111 return Isomorphic::isomorphic($this->graph, $doc->graph); |
177 return Isomorphic::isomorphic($this->graph, $doc->graph); |
112 } |
178 } |