| author | ymh <ymh.work@gmail.com> |
| Fri, 11 Oct 2013 15:01:52 +0200 | |
| changeset 152 | ab9832ca5ca6 |
| parent 137 | bb8bf2688d7e |
| permissions | -rw-r--r-- |
| 107 | 1 |
# -*- coding: utf-8 -*- |
| 126 | 2 |
# |
| 131 | 3 |
# Copyright IRI (c) 2013 |
| 126 | 4 |
# |
5 |
# contact@iri.centrepompidou.fr |
|
6 |
# |
|
7 |
# This software is governed by the CeCILL-B license under French law and |
|
8 |
# abiding by the rules of distribution of free software. You can use, |
|
9 |
# modify and/ or redistribute the software under the terms of the CeCILL-B |
|
10 |
# license as circulated by CEA, CNRS and INRIA at the following URL |
|
11 |
# "http://www.cecill.info". |
|
12 |
# |
|
13 |
# As a counterpart to the access to the source code and rights to copy, |
|
14 |
# modify and redistribute granted by the license, users are provided only |
|
15 |
# with a limited warranty and the software's author, the holder of the |
|
16 |
# economic rights, and the successive licensors have only limited |
|
17 |
# liability. |
|
18 |
# |
|
19 |
# In this respect, the user's attention is drawn to the risks associated |
|
20 |
# with loading, using, modifying and/or developing or reproducing the |
|
21 |
# software by the user in light of its specific status of free software, |
|
22 |
# that may mean that it is complicated to manipulate, and that also |
|
23 |
# therefore means that it is reserved for developers and experienced |
|
24 |
# professionals having in-depth computer knowledge. Users are therefore |
|
25 |
# encouraged to load and test the software's suitability as regards their |
|
26 |
# requirements in conditions enabling the security of their systems and/or |
|
27 |
# data to be ensured and, more generally, to use and operate it in the |
|
28 |
# same conditions as regards security. |
|
29 |
# |
|
30 |
# The fact that you are presently reading this means that you have had |
|
31 |
# knowledge of the CeCILL-B license and that you accept its terms. |
|
32 |
# |
|
| 107 | 33 |
|
34 |
from rdflib.plugins.sparql.processor import prepareQuery |
|
35 |
from rdflib.term import URIRef |
|
36 |
from p4l.models.data import Language, Record |
|
| 119 | 37 |
from p4l.models import signals |
| 107 | 38 |
|
39 |
||
40 |
class QueryCache(object): |
|
41 |
def __init__(self, *args, **kwargs): |
|
42 |
self.__query_cache = {} |
|
43 |
||
44 |
def get_sparql_query(self, query, namespaces_dict): |
|
45 |
return self.__query_cache.get(query, False) \ |
|
46 |
or self.__query_cache.setdefault(query, prepareQuery(query, initNs=namespaces_dict)) |
|
47 |
||
48 |
||
49 |
def convert_bool(val): |
|
50 |
if val == True or val == False: |
|
51 |
return val |
|
52 |
if val is None: |
|
53 |
return False |
|
54 |
if isinstance(val, basestring): |
|
55 |
if len(val) == 0: |
|
56 |
return False |
|
57 |
if val[0].lower() in ['t','y','1','o']: |
|
58 |
return True |
|
59 |
else: |
|
60 |
return False |
|
61 |
return bool(val) |
|
62 |
||
63 |
class RecordParser(object): |
|
64 |
||
65 |
||
66 |
def __init__(self, query_cache = None): |
|
67 |
self.query_cache = None |
|
68 |
if self.query_cache is None: |
|
69 |
self.query_cache = QueryCache() |
|
70 |
||
|
137
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
71 |
|
| 107 | 72 |
def extract_single_value_form_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None, default=None): |
|
137
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
73 |
''' |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
74 |
Extract a single value form an rdf graph. |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
75 |
|
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
76 |
:param graph: the rdflib.Graph object to parse |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
77 |
:param q: the SPARQL query used to extact the data from the graph |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
78 |
:param bindings: Optional binding values for the query |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
79 |
:param index: zero based index of the result to extract |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
80 |
:param convert: Either a single method of a map of method to apply to the data to extract |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
81 |
:param default: The default value to return if no result is returned by the query |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
82 |
|
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
83 |
@return: None or a single value |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
84 |
''' |
| 107 | 85 |
return next(self.extract_multiple_values_from_graph(graph, q, bindings, index, convert), default) |
86 |
||
|
137
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
87 |
|
| 107 | 88 |
def extract_multiple_values_from_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None): |
|
137
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
89 |
''' |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
90 |
Extract multiple values from a rdf graph. |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
91 |
|
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
92 |
:param graph: the rdflib.Graph object to parse |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
93 |
:param q: the SPARQL query used to extact the data from the graph |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
94 |
:param bindings: Optional binding values for the query |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
95 |
:param index: zero based index of the result to extract |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
96 |
:param convert: The default value to return if no result is returned by the query |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
97 |
|
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
98 |
@return: an iterator on the extracted values |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
99 |
''' |
| 107 | 100 |
index_list = index |
101 |
if isinstance(index, int): |
|
102 |
index_list = range(index+1) |
|
103 |
||
104 |
if hasattr(convert, '__call__'): |
|
105 |
convert_dict = dict((k, convert) for k in index_list) |
|
106 |
else: |
|
107 |
convert_dict = convert |
|
108 |
||
109 |
convert_dict = dict((k, f if hasattr(f,'__call__') else lambda v:unicode(v) if v is not None else None) for k,f in convert_dict.iteritems()) |
|
110 |
||
111 |
for row in graph.query(self.query_cache.get_sparql_query(q, dict(graph.namespaces())), initBindings=bindings): |
|
112 |
if len(row) < len(index_list): |
|
113 |
break |
|
114 |
else: |
|
115 |
res = dict([ (k, convert_dict.get(k, lambda v:unicode(v) if v is not None else None)(v)) for k, v in zip(index_list, row)]) |
|
116 |
if isinstance(index, int): |
|
117 |
yield res[index] |
|
118 |
else: |
|
119 |
yield res |
|
120 |
||
121 |
||
122 |
def convert_bool(self, val): |
|
123 |
if val == True or val == False: |
|
124 |
return val |
|
125 |
if val is None: |
|
126 |
return False |
|
127 |
if isinstance(val, basestring): |
|
128 |
if len(val) == 0: |
|
129 |
return False |
|
130 |
if val[0].lower() in ['t','y','1','o']: |
|
131 |
return True |
|
132 |
else: |
|
133 |
return False |
|
134 |
return bool(val) |
|
135 |
||
136 |
||
137 |
def add_to_related_collection(self, coll, graph, fields, q, bindings={}, convert=lambda v: unicode(v) if v is not None else None, through_fields=None): |
|
|
137
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
138 |
''' |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
139 |
This method add new object to a related object collection by extracting data from an rdflib.Graph. |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
140 |
|
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
141 |
|
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
142 |
:param coll: The collection to add the new objects into. This must be a related collection (cf. django) |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
143 |
:param graph: The graph from wich data is extracted |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
144 |
:param fields: The list of fields to extract |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
145 |
:param q: The SPAQL query. The order and number of the binding parameters of the query must be equals to the one descibed in the ``fields`` parameter. |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
146 |
:param bindings: Binding for the SPARQL qery |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
147 |
:param convert: map of methods or simple method to convert data extracted form the graph. |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
148 |
:param through_fields: the list (in order) of the througt table used to make a relation between the main object and an "external" object. |
|
bb8bf2688d7e
- Finish and correct documentation
ymh <ymh.work@gmail.com>
parents:
131
diff
changeset
|
149 |
''' |
| 107 | 150 |
|
151 |
for val in self.extract_multiple_values_from_graph(graph, q, bindings=bindings, index=fields, convert=convert): |
|
152 |
||
153 |
if through_fields: |
|
154 |
new_obj_val = dict([(k,v) for k,v in val.iteritems() if k not in through_fields]) |
|
155 |
else: |
|
156 |
new_obj_val = val |
|
157 |
||
158 |
if hasattr(coll, 'through'): |
|
159 |
new_obj_rel, _ = coll.model.objects.get_or_create(**new_obj_val) |
|
160 |
if through_fields: |
|
161 |
through_vals = {coll.source_field_name: coll.instance, coll.target_field_name: new_obj_rel} |
|
162 |
through_vals.update(dict([(k,v) for k,v in val.iteritems() if k in through_fields])) |
|
163 |
coll.through.objects.create(**through_vals) |
|
164 |
new_obj = None |
|
165 |
else: |
|
166 |
new_obj = new_obj_rel |
|
167 |
||
168 |
else: |
|
169 |
new_obj = coll.create(**new_obj_val) |
|
170 |
||
171 |
if new_obj: |
|
172 |
coll.add(new_obj) |
|
173 |
||
174 |
||
175 |
||
176 |
||
177 |
def build_record(self, graph, delete=True): |
|
178 |
||
179 |
record_uri = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?s WHERE { ?s rdf:type iiep:Record .}") |
|
180 |
record_identifier = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:identifier ?o .}", bindings={'s':URIRef(record_uri)}) |
|
181 |
||
182 |
if delete: |
|
183 |
Record.objects.filter(identifier=record_identifier).delete() |
|
184 |
||
185 |
record = Record() |
|
186 |
record.uri = record_uri |
|
187 |
record.identifier = record_identifier |
|
188 |
record.notes = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:notes ?o .}", bindings={'s':URIRef(record.uri)}) |
|
189 |
record.recordType = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:type ?o .}", bindings={'s':URIRef(record.uri)}) |
|
190 |
record.isDocumentPart = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:isDocumentPart ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool, default=False) |
|
191 |
record.hidden = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:hidden ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool, default=False) |
|
192 |
record.restricted = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:restricted ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool, default=False) |
|
193 |
record.editionStatement = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:editionStatement ?o .}", bindings={'s':URIRef(record.uri)}) |
|
194 |
record.corporateAuthorLabel = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:corporateAuthorLabel ?o .}", bindings={'s':URIRef(record.uri)}) |
|
195 |
||
196 |
language = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:language ?o .}", bindings={'s':URIRef(record.uri)}) |
|
197 |
if language: |
|
198 |
record.language, _ = Language.objects.get_or_create(uri=language) |
|
199 |
||
200 |
record.save() |
|
201 |
||
202 |
self.add_to_related_collection(record.otherLanguages, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:otherLanguage ?o .}", bindings={'s':URIRef(record.uri)}) |
|
203 |
self.add_to_related_collection(record.subjects, graph, ['uri'], "SELECT ?o WHERE { ?s dct:subject ?o .}", bindings={'s':URIRef(record.uri)}) |
|
204 |
self.add_to_related_collection(record.themes, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:theme ?o .}", bindings={'s':URIRef(record.uri)}) |
|
205 |
self.add_to_related_collection(record.countries, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:country ?o .}", bindings={'s':URIRef(record.uri)}) |
|
206 |
self.add_to_related_collection(record.authors, graph, ['name'], "SELECT ?o WHERE { ?s iiep:author ?o .}", bindings={'s':URIRef(record.uri)}) |
|
207 |
self.add_to_related_collection(record.subjectPersons, graph, ['name'], "SELECT ?o WHERE { ?s iiep:subjectPerson ?o .}", bindings={'s':URIRef(record.uri)}) |
|
208 |
self.add_to_related_collection(record.projectNames, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:projectName ?o . }") |
|
209 |
self.add_to_related_collection(record.audiences, graph, ['uri'], "SELECT ?o WHERE { ?s dct:audience ?o .}", bindings={'s':URIRef(record.uri)}) |
|
210 |
||
211 |
self.add_to_related_collection( |
|
212 |
record.periodicals, |
|
213 |
graph, |
|
214 |
['label','lang'], |
|
215 |
"SELECT DISTINCT ?o ( lang(?o) as ?l) WHERE { ?s iiep:periodical ?o .}", |
|
216 |
bindings={'s':URIRef(record.uri)} |
|
217 |
) |
|
218 |
||
219 |
self.add_to_related_collection( |
|
220 |
record.meetings, |
|
221 |
graph, |
|
222 |
['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear', 'lang'], |
|
223 |
"SELECT ?l ?mn ?mp ?md ?my (lang(COALESCE(?l,?nm, ?mp,?md,?my)) as ?lang) WHERE { [iiep:meeting ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:meetingNumber ?mn }. OPTIONAL { ?bnode iiep:meetingPlace ?mp }. OPTIONAL { ?bnode iiep:meetingDate ?md }. OPTIONAL { ?bnode iiep:meetingYear ?my }}", |
|
224 |
convert={'meetingYear' : lambda y: int(y) if y is not None else None} |
|
225 |
) |
|
226 |
||
227 |
self.add_to_related_collection( |
|
228 |
record.series, |
|
229 |
graph, |
|
230 |
['title', 'volume', 'lang'], |
|
231 |
"SELECT ?t ?vol (lang(COALESCE(?t,?vol)) as ?lang) WHERE { [iiep:serie ?bnode]. OPTIONAL { ?bnode dct:title ?t }. OPTIONAL { ?bnode iiep:volume ?vol } }", |
|
232 |
) |
|
233 |
||
234 |
self.add_to_related_collection( |
|
235 |
record.subjectCorporateBodies, |
|
236 |
graph, |
|
237 |
['uri'], |
|
238 |
"SELECT ?o WHERE { ?s iiep:subjectCorporateBody ?o. }", |
|
239 |
bindings={'s':URIRef(record.uri)} |
|
240 |
) |
|
241 |
||
242 |
self.add_to_related_collection( |
|
243 |
record.subjectMeetings, |
|
244 |
graph, |
|
245 |
['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'], |
|
246 |
"SELECT ?l ?mn ?mp ?md ?my WHERE { [iiep:subjectMeeting ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:meetingNumber ?mn }. OPTIONAL { ?bnode iiep:meetingPlace ?mp }. OPTIONAL { ?bnode iiep:meetingDate ?md }. OPTIONAL { ?bnode iiep:meetingYear ?my }}", |
|
247 |
convert={'meetingYear' : lambda y: int(y) if y is not None else None} |
|
248 |
) |
|
249 |
||
250 |
self.add_to_related_collection( |
|
251 |
record.corporateAuthors, |
|
252 |
graph, |
|
253 |
['uri'], |
|
254 |
"SELECT ?o WHERE { ?s iiep:corporateAuthor ?o.}", |
|
255 |
bindings={'s':URIRef(record.uri)} |
|
256 |
) |
|
257 |
||
258 |
self.add_to_related_collection( |
|
259 |
record.issns, |
|
260 |
graph, |
|
261 |
['issn', 'lang'], |
|
262 |
"SELECT ?issn (lang(COALESCE(?issn)) as ?lang) WHERE { ?s iiep:issn ?issn . }", |
|
263 |
bindings={'s':URIRef(record.uri)}, |
|
264 |
) |
|
265 |
||
266 |
self.add_to_related_collection( |
|
267 |
record.isbns, |
|
268 |
graph, |
|
269 |
['isbn', 'lang'], |
|
270 |
"SELECT ?isbn (lang(COALESCE(?isbn)) as ?lang) WHERE { ?s iiep:isbn ?isbn . }", |
|
271 |
bindings={'s':URIRef(record.uri)}, |
|
272 |
) |
|
273 |
||
274 |
self.add_to_related_collection( |
|
275 |
record.documentCodes, |
|
276 |
graph, |
|
277 |
['documentCode', 'lang'], |
|
278 |
"SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:documentCode ?c . }", |
|
279 |
bindings={'s':URIRef(record.uri)}, |
|
280 |
) |
|
281 |
||
282 |
self.add_to_related_collection( |
|
283 |
record.titles, |
|
284 |
graph, |
|
285 |
['title', 'lang'], |
|
286 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:title ?t . }", |
|
287 |
bindings={'s':URIRef(record.uri)}, |
|
288 |
) |
|
289 |
||
290 |
self.add_to_related_collection( |
|
291 |
record.abstracts, |
|
292 |
graph, |
|
293 |
['abstract', 'lang'], |
|
294 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:abstract ?t . }", |
|
295 |
bindings={'s':URIRef(record.uri)}, |
|
296 |
) |
|
297 |
||
298 |
self.add_to_related_collection( |
|
299 |
record.addedTitles, |
|
300 |
graph, |
|
301 |
['title', 'lang'], |
|
302 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:addedTitle ?t . }", |
|
303 |
bindings={'s':URIRef(record.uri)}, |
|
304 |
) |
|
305 |
||
306 |
self.add_to_related_collection( |
|
307 |
record.titlesMainDocument, |
|
308 |
graph, |
|
309 |
['title', 'lang'], |
|
310 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:titleMainDocument ?t . }", |
|
311 |
bindings={'s':URIRef(record.uri)}, |
|
312 |
) |
|
313 |
||
314 |
self.add_to_related_collection( |
|
315 |
record.imprints, |
|
316 |
graph, |
|
317 |
['imprintCity', 'publisher', 'imprintDate', 'lang'], |
|
318 |
"SELECT ?c ?p ?d (lang(COALESCE(?c, ?p, ?d)) as ?lang) WHERE { [ iiep:imprint ?bnode ]. OPTIONAL { ?bnode iiep:imprintCity ?c }. OPTIONAL { ?bnode dct:publisher ?p }. OPTIONAL { ?bnode iiep:imprintDate ?d }}", |
|
319 |
) |
|
320 |
||
321 |
self.add_to_related_collection( |
|
322 |
record.collations, |
|
323 |
graph, |
|
324 |
['collation', 'lang'], |
|
325 |
"SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:collation ?c . }", |
|
326 |
bindings={'s':URIRef(record.uri)}, |
|
327 |
) |
|
328 |
||
329 |
self.add_to_related_collection( |
|
330 |
record.volumeIssues, |
|
331 |
graph, |
|
332 |
['volume', 'number', 'lang'], |
|
333 |
"SELECT ?v ?n (lang(COALESCE(?v, ?n)) as ?lang) WHERE { [ iiep:volumeIssue ?bnode ]. OPTIONAL { ?bnode iiep:volume ?v }. OPTIONAL { ?bnode iiep:number ?n }}", |
|
334 |
) |
|
335 |
||
336 |
self.add_to_related_collection( |
|
337 |
record.urls, |
|
338 |
graph, |
|
339 |
['address', 'display'], |
|
340 |
"SELECT ?a ?d WHERE { [ iiep:url ?bnode ]. OPTIONAL { ?bnode iiep:address ?a }. OPTIONAL { ?bnode iiep:display ?d }.}", |
|
341 |
) |
|
| 119 | 342 |
|
343 |
signals.record_saved.send(Record, instance=record, created=True) |
|
| 107 | 344 |
|
345 |
return record |