| author | ymh <ymh.work@gmail.com> |
| Fri, 20 Sep 2013 00:03:31 +0200 | |
| changeset 101 | 71532a54d1c4 |
| parent 22 | 48ff361f96c8 |
| child 102 | 53c9233a7684 |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
|
101
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
3 |
import logging |
|
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
4 |
from optparse import make_option |
|
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
5 |
|
| 6 | 6 |
from django.core.management import BaseCommand |
7 |
from django.db import reset_queries, transaction |
|
|
101
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
8 |
from rdflib import BNode, URIRef |
|
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
9 |
from rdflib.plugins.sparql import prepareQuery |
|
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
10 |
|
|
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
11 |
from p4l.management.constants import get_empty_graph, IIEP |
| 6 | 12 |
from p4l.models import Record, Language |
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
13 |
from p4l.utils import show_progress |
| 0 | 14 |
import xml.etree.cElementTree as ET |
15 |
||
|
101
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
16 |
|
| 0 | 17 |
logger = logging.getLogger(__name__) |
18 |
||
19 |
||
20 |
DEFAULT_LANGUAGE_URI = "http://psi.oasis-open.org/iso/639/#eng" |
|
21 |
||
22 |
DEFAULT_LANGUAGE_QUERY = """SELECT ( COALESCE(?lang, ?other_lang) as ?main_lang) WHERE { |
|
23 |
OPTIONAL { ?s dct:language ?lang }. |
|
24 |
OPTIONAL { ?s iiep:otherLanguage ?other_lang }. |
|
25 |
}""" |
|
26 |
||
27 |
||
28 |
class Command(BaseCommand): |
|
29 |
||
30 |
args = "record_url ..." |
|
31 |
||
32 |
help = "Import p4l record rdf format" |
|
33 |
||
34 |
option_list = BaseCommand.option_list + ( |
|
35 |
make_option('-b', '--batch-size', |
|
36 |
dest= 'batch_size', |
|
37 |
type='int', |
|
38 |
default= 50, |
|
39 |
help= 'number of object to import in bulk operations' |
|
40 |
), |
|
41 |
) |
|
42 |
||
43 |
def __init__(self, *args, **kwargs): |
|
44 |
super(Command, self).__init__(*args, **kwargs) |
|
45 |
self.__query_cache = {} |
|
46 |
||
47 |
||
48 |
def __get_sparql_query(self, query, namespaces): |
|
49 |
||
50 |
return self.__query_cache[query] \ |
|
51 |
if query in self.__query_cache \ |
|
52 |
else self.__query_cache.setdefault(query, prepareQuery(query, initNs=namespaces)) |
|
53 |
||
54 |
||
55 |
def extract_single_value_form_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None): |
|
56 |
return next(self.extract_multiple_values_from_graph(graph, q, bindings, index, convert), None) |
|
57 |
||
58 |
def extract_multiple_values_from_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None): |
|
59 |
||
60 |
index_list = index |
|
61 |
if isinstance(index, int): |
|
62 |
index_list = range(index+1) |
|
63 |
||
64 |
if hasattr(convert, '__call__'): |
|
65 |
convert_dict = dict((k, convert) for k in index_list) |
|
66 |
else: |
|
67 |
convert_dict = convert |
|
68 |
||
69 |
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()) |
|
70 |
||
71 |
for row in graph.query(self.__get_sparql_query(q, dict(graph.namespaces())), initBindings=bindings): |
|
72 |
if len(row) < len(index_list): |
|
73 |
break |
|
74 |
else: |
|
75 |
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)]) |
|
76 |
if isinstance(index, int): |
|
77 |
yield res[index] |
|
78 |
else: |
|
79 |
yield res |
|
80 |
||
81 |
||
82 |
def convert_bool(self, val): |
|
83 |
if val == True or val == False: |
|
84 |
return val |
|
85 |
if val is None: |
|
86 |
return False |
|
87 |
if isinstance(val, basestring): |
|
88 |
if len(val) == 0: |
|
89 |
return False |
|
90 |
if val[0].lower() in ['t','y','1','o']: |
|
91 |
return True |
|
92 |
else: |
|
93 |
return False |
|
94 |
return bool(val) |
|
95 |
||
96 |
||
97 |
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): |
|
98 |
||
99 |
for val in self.extract_multiple_values_from_graph(graph, q, bindings=bindings, index=fields, convert=convert): |
|
100 |
||
101 |
if through_fields: |
|
102 |
new_obj_val = dict([(k,v) for k,v in val.iteritems() if k not in through_fields]) |
|
103 |
else: |
|
104 |
new_obj_val = val |
|
105 |
||
106 |
if hasattr(coll, 'through'): |
|
107 |
new_obj_rel, _ = coll.model.objects.get_or_create(**new_obj_val) |
|
108 |
if through_fields: |
|
109 |
through_vals = {coll.source_field_name: coll.instance, coll.target_field_name: new_obj_rel} |
|
110 |
through_vals.update(dict([(k,v) for k,v in val.iteritems() if k in through_fields])) |
|
111 |
coll.through.objects.create(**through_vals) |
|
112 |
new_obj = None |
|
113 |
else: |
|
114 |
new_obj = new_obj_rel |
|
115 |
||
116 |
else: |
|
117 |
new_obj = coll.create(**new_obj_val) |
|
118 |
||
119 |
if new_obj: |
|
120 |
coll.add(new_obj) |
|
121 |
||
122 |
||
123 |
||
124 |
||
125 |
def build_record(self, graph): |
|
126 |
||
127 |
record_uri = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?s WHERE { ?s rdf:type iiep:Record .}") |
|
128 |
||
129 |
record = Record() |
|
130 |
record.uri = record_uri |
|
131 |
record.identifier = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:identifier ?o .}", bindings={'s':URIRef(record.uri)}) |
|
132 |
record.notes = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:notes ?o .}", bindings={'s':URIRef(record.uri)}) |
|
133 |
record.recordType = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:type ?o .}", bindings={'s':URIRef(record.uri)}) |
|
134 |
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) |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
135 |
record.isMultilingual = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:isMultilingual ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool) |
| 0 | 136 |
record.editionStatement = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:editionStatement ?o .}", bindings={'s':URIRef(record.uri)}) |
137 |
||
138 |
language = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:language ?o .}", bindings={'s':URIRef(record.uri)}) |
|
139 |
if language: |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
140 |
record.language, _ = Language.objects.get_or_create(uri=language) |
| 0 | 141 |
|
142 |
record.save() |
|
143 |
||
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
144 |
self.add_to_related_collection(record.otherLanguages, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:otherLanguage ?o .}", bindings={'s':URIRef(record.uri)}) |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
145 |
self.add_to_related_collection(record.subjects, graph, ['uri'], "SELECT ?o WHERE { ?s dct:subject ?o .}", bindings={'s':URIRef(record.uri)}) |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
146 |
self.add_to_related_collection(record.themes, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:theme ?o .}", bindings={'s':URIRef(record.uri)}) |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
147 |
self.add_to_related_collection(record.countries, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:country ?o .}", bindings={'s':URIRef(record.uri)}) |
| 0 | 148 |
self.add_to_related_collection(record.authors, graph, ['name'], "SELECT ?o WHERE { ?s iiep:author ?o .}", bindings={'s':URIRef(record.uri)}) |
149 |
self.add_to_related_collection(record.subjectPersons, graph, ['name'], "SELECT ?o WHERE { ?s iiep:subjectPerson ?o .}", bindings={'s':URIRef(record.uri)}) |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
150 |
self.add_to_related_collection(record.projectNames, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:projectName ?o . }") |
| 0 | 151 |
|
152 |
self.add_to_related_collection( |
|
153 |
record.periodicals, |
|
154 |
graph, |
|
155 |
['label','lang'], |
|
156 |
"SELECT DISTINCT ?o ( lang(?o) as ?l) WHERE { ?s iiep:periodical ?o .}", |
|
| 22 | 157 |
bindings={'s':URIRef(record.uri)} |
| 0 | 158 |
) |
159 |
||
160 |
self.add_to_related_collection( |
|
161 |
record.meetings, |
|
162 |
graph, |
|
163 |
['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear', 'lang'], |
|
164 |
"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 }}", |
|
| 22 | 165 |
convert={'meetingYear' : lambda y: int(y) if y is not None else None} |
| 0 | 166 |
) |
167 |
||
168 |
self.add_to_related_collection( |
|
169 |
record.series, |
|
170 |
graph, |
|
171 |
['title', 'volume', 'lang'], |
|
172 |
"SELECT ?t ?vol (lang(COALESCE(?t,?vol)) as ?lang) WHERE { [iiep:serie ?bnode]. OPTIONAL { ?bnode dct:title ?t }. OPTIONAL { ?bnode iiep:volume ?vol } }", |
|
173 |
) |
|
174 |
||
175 |
self.add_to_related_collection( |
|
176 |
record.subjectCorporateBodies, |
|
177 |
graph, |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
178 |
['uri'], |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
179 |
"SELECT ?o WHERE { ?s iiep:subjectCorporateBody ?o. }", |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
180 |
bindings={'s':URIRef(record.uri)} |
| 0 | 181 |
) |
182 |
||
183 |
self.add_to_related_collection( |
|
184 |
record.subjectMeetings, |
|
185 |
graph, |
|
186 |
['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'], |
|
| 7 | 187 |
"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 }}", |
| 0 | 188 |
convert={'meetingYear' : lambda y: int(y) if y is not None else None} |
189 |
) |
|
190 |
||
191 |
self.add_to_related_collection( |
|
192 |
record.corporateAuthors, |
|
193 |
graph, |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
194 |
['uri'], |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
195 |
"SELECT ?o WHERE { ?s iiep:corporateAuthor ?o.}", |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
196 |
bindings={'s':URIRef(record.uri)} |
| 0 | 197 |
) |
198 |
||
199 |
self.add_to_related_collection( |
|
200 |
record.issns, |
|
201 |
graph, |
|
202 |
['issn', 'lang'], |
|
203 |
"SELECT ?issn (lang(COALESCE(?issn)) as ?lang) WHERE { ?s iiep:issn ?issn . }", |
|
204 |
bindings={'s':URIRef(record.uri)}, |
|
205 |
) |
|
206 |
||
207 |
self.add_to_related_collection( |
|
208 |
record.isbns, |
|
209 |
graph, |
|
210 |
['isbn', 'lang'], |
|
211 |
"SELECT ?isbn (lang(COALESCE(?isbn)) as ?lang) WHERE { ?s iiep:isbn ?isbn . }", |
|
212 |
bindings={'s':URIRef(record.uri)}, |
|
213 |
) |
|
214 |
||
215 |
self.add_to_related_collection( |
|
216 |
record.documentCodes, |
|
217 |
graph, |
|
218 |
['documentCode', 'lang'], |
|
219 |
"SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:documentCode ?c . }", |
|
220 |
bindings={'s':URIRef(record.uri)}, |
|
221 |
) |
|
222 |
||
223 |
self.add_to_related_collection( |
|
224 |
record.titles, |
|
225 |
graph, |
|
226 |
['title', 'lang'], |
|
227 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:title ?t . }", |
|
228 |
bindings={'s':URIRef(record.uri)}, |
|
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
229 |
) |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
230 |
|
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
231 |
self.add_to_related_collection( |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
232 |
record.abstracts, |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
233 |
graph, |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
234 |
['abstract', 'lang'], |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
235 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:abstract ?t . }", |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
236 |
bindings={'s':URIRef(record.uri)}, |
| 0 | 237 |
) |
238 |
||
239 |
self.add_to_related_collection( |
|
240 |
record.addedTitles, |
|
241 |
graph, |
|
242 |
['title', 'lang'], |
|
243 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:addedTitle ?t . }", |
|
244 |
bindings={'s':URIRef(record.uri)}, |
|
245 |
) |
|
246 |
||
247 |
self.add_to_related_collection( |
|
248 |
record.titlesMainDocument, |
|
249 |
graph, |
|
250 |
['title', 'lang'], |
|
251 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:titleMainDocument ?t . }", |
|
252 |
bindings={'s':URIRef(record.uri)}, |
|
253 |
) |
|
254 |
||
255 |
self.add_to_related_collection( |
|
256 |
record.imprints, |
|
257 |
graph, |
|
258 |
['imprintCity', 'publisher', 'imprintDate', 'lang'], |
|
259 |
"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 }}", |
|
260 |
) |
|
261 |
||
262 |
self.add_to_related_collection( |
|
263 |
record.collations, |
|
264 |
graph, |
|
265 |
['collation', 'lang'], |
|
266 |
"SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:collation ?c . }", |
|
267 |
bindings={'s':URIRef(record.uri)}, |
|
268 |
) |
|
269 |
||
270 |
self.add_to_related_collection( |
|
271 |
record.volumeIssues, |
|
272 |
graph, |
|
273 |
['volume', 'number', 'lang'], |
|
| 6 | 274 |
"SELECT ?v ?n (lang(COALESCE(?v, ?n)) as ?lang) WHERE { [ iiep:volumeIssue ?bnode ]. OPTIONAL { ?bnode iiep:volume ?v }. OPTIONAL { ?bnode iiep:number ?n }}", |
| 0 | 275 |
) |
276 |
||
277 |
self.add_to_related_collection( |
|
278 |
record.urls, |
|
279 |
graph, |
|
280 |
['address', 'display', 'accessLevel'], |
|
281 |
"SELECT ?a ?d ?al WHERE { [ iiep:url ?bnode ]. OPTIONAL { ?bnode iiep:address ?a }. OPTIONAL { ?bnode iiep:display ?d }. OPTIONAL { ?bnode iiep:accessLevel ?al }.}", |
|
282 |
) |
|
283 |
||
284 |
return record |
|
285 |
||
286 |
||
287 |
def filter_node(self, node, graph, res_graph): |
|
288 |
for p,o in graph[node]: |
|
289 |
res_graph.add((node,p,o)) |
|
290 |
if isinstance(o, BNode): |
|
291 |
self.filter_node(o, graph, res_graph) |
|
292 |
||
293 |
||
294 |
||
295 |
def calculate_records_nb(self, records_url): |
|
296 |
context = ET.iterparse(records_url, events=("end",)) |
|
297 |
i = 0 |
|
298 |
for _,elem in context: |
|
299 |
if elem.tag == "{%s}Record" % IIEP: |
|
300 |
i += 1 |
|
301 |
return i |
|
302 |
||
303 |
def process_url(self, records_url, options): |
|
304 |
||
305 |
total_records = self.calculate_records_nb(records_url) |
|
306 |
writer = None |
|
307 |
errors=[] |
|
308 |
||
309 |
context = ET.iterparse(records_url, events=("end",)) |
|
310 |
i = 0 |
|
| 6 | 311 |
for _,elem in context: |
| 0 | 312 |
if elem.tag == "{%s}Record" % IIEP: |
313 |
i += 1 |
|
314 |
writer = show_progress(i, total_records, "Processing record nb %d " % i, 50, writer=writer) |
|
315 |
try: |
|
|
101
71532a54d1c4
update virtualenv + implement record serialization
ymh <ymh.work@gmail.com>
parents:
22
diff
changeset
|
316 |
record_graph = get_empty_graph() |
| 0 | 317 |
record_graph.parse(data=ET.tostring(elem, encoding='utf-8'), format='xml') |
318 |
# add transaction management |
|
319 |
self.build_record(record_graph) |
|
320 |
except Exception as e: |
|
321 |
transaction.rollback() |
|
322 |
msg = "Error processing resource %d in %s : %s" % (i, records_url, repr(e)) |
|
323 |
logger.exception(msg) |
|
324 |
errors.append((i, records_url, msg)) |
|
325 |
else: |
|
326 |
transaction.commit() |
|
327 |
||
328 |
if i%self.batch_size == 0: |
|
329 |
reset_queries() |
|
330 |
||
331 |
return errors |
|
332 |
||
333 |
||
334 |
# def process_url(self, records_url, options): |
|
335 |
# #open graph with rdflib |
|
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
336 |
# |
| 0 | 337 |
# g = Graph() |
338 |
# print("Loading %s" % records_url) |
|
339 |
# g.parse(records_url) |
|
340 |
# print("Parsing %s done" % records_url) |
|
341 |
# for i,record_uri in enumerate(g[:RDF.type:IIEP.Record]): |
|
342 |
# print(i, repr(record_uri)) |
|
343 |
# record_graph = self.get_empty_graph() |
|
344 |
# self.filter_node(record_uri, g, record_graph) |
|
345 |
# self.build_record(record_graph) |
|
346 |
# if i > 3: |
|
347 |
# break |
|
348 |
||
349 |
||
350 |
||
351 |
||
352 |
def handle(self, *args, **options): |
|
353 |
||
354 |
self.batch_size = options.get('batch_size', 50) |
|
355 |
transaction.enter_transaction_management() |
|
356 |
transaction.managed(True) |
|
357 |
||
358 |
for records_url in args: |
|
359 |
print("Processing %s" % records_url) |
|
360 |
errors = self.process_url(records_url, options) |
|
361 |
print("Processing %s Done" % records_url) |
|
362 |
if errors: |
|
363 |
print("%d error(s) when processing %s, check your log file." % (len(errors), records_url)) |
|
364 |
||
365 |
transaction.leave_transaction_management() |
|
366 |