src/p4l/management/commands/import_record.py
changeset 14 52fa6990e0bb
parent 13 6296aa12fd71
child 22 48ff361f96c8
equal deleted inserted replaced
13:6296aa12fd71 14:52fa6990e0bb
   137         record.uri = record_uri
   137         record.uri = record_uri
   138         record.identifier = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:identifier ?o .}", bindings={'s':URIRef(record.uri)})
   138         record.identifier = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:identifier ?o .}", bindings={'s':URIRef(record.uri)})
   139         record.notes = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:notes ?o .}", bindings={'s':URIRef(record.uri)})
   139         record.notes = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:notes ?o .}", bindings={'s':URIRef(record.uri)})
   140         record.recordType = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:type ?o .}", bindings={'s':URIRef(record.uri)})
   140         record.recordType = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:type ?o .}", bindings={'s':URIRef(record.uri)})
   141         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)
   141         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)
       
   142         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)        
   142         record.editionStatement = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:editionStatement ?o .}", bindings={'s':URIRef(record.uri)})
   143         record.editionStatement = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:editionStatement ?o .}", bindings={'s':URIRef(record.uri)})
   143 
   144 
   144         language = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:language ?o .}", bindings={'s':URIRef(record.uri)})
   145         language = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:language ?o .}", bindings={'s':URIRef(record.uri)})
   145         if language:
   146         if language:
   146             record.language, _ = Language.objects.get_or_create(language=language)
   147             record.language, _ = Language.objects.get_or_create(uri=language)
   147 
   148 
   148         record.save()
   149         record.save()
   149 
   150 
   150         self.add_to_related_collection(record.otherLanguages, graph,  ['language'], "SELECT ?o WHERE { ?s iiep:otherLanguage ?o .}", bindings={'s':URIRef(record.uri)})
   151         self.add_to_related_collection(record.otherLanguages, graph,  ['uri'], "SELECT ?o WHERE { ?s iiep:otherLanguage ?o .}", bindings={'s':URIRef(record.uri)})
   151         self.add_to_related_collection(record.subjects, graph, ['subject'], "SELECT ?o WHERE { ?s dct:subject ?o .}", bindings={'s':URIRef(record.uri)})
   152         self.add_to_related_collection(record.subjects, graph, ['uri'], "SELECT ?o WHERE { ?s dct:subject ?o .}", bindings={'s':URIRef(record.uri)})
   152         self.add_to_related_collection(record.themes, graph, ['theme'], "SELECT ?o WHERE { ?s iiep:theme ?o .}", bindings={'s':URIRef(record.uri)})
   153         self.add_to_related_collection(record.themes, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:theme ?o .}", bindings={'s':URIRef(record.uri)})
   153         self.add_to_related_collection(record.countries, graph,  ['country'], "SELECT ?o WHERE { ?s iiep:country ?o .}", bindings={'s':URIRef(record.uri)})
   154         self.add_to_related_collection(record.countries, graph,  ['uri'], "SELECT ?o WHERE { ?s iiep:country ?o .}", bindings={'s':URIRef(record.uri)})
   154         self.add_to_related_collection(record.authors, graph, ['name'], "SELECT ?o WHERE { ?s iiep:author ?o .}", bindings={'s':URIRef(record.uri)})
   155         self.add_to_related_collection(record.authors, graph, ['name'], "SELECT ?o WHERE { ?s iiep:author ?o .}", bindings={'s':URIRef(record.uri)})
   155         self.add_to_related_collection(record.subjectPersons, graph, ['name'], "SELECT ?o WHERE { ?s iiep:subjectPerson ?o .}", bindings={'s':URIRef(record.uri)})
   156         self.add_to_related_collection(record.subjectPersons, graph, ['name'], "SELECT ?o WHERE { ?s iiep:subjectPerson ?o .}", bindings={'s':URIRef(record.uri)})
   156         self.add_to_related_collection(record.projectNames, graph, ['label','acronym'], "SELECT ?l ?a WHERE { [ iiep:projectName ?bnode ]. ?bnode rdfs:label ?l. OPTIONAL { ?bnode iiep:acronym ?a } }")
   157         self.add_to_related_collection(record.projectNames, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:projectName ?o . }")
   157 
   158 
   158         self.add_to_related_collection(
   159         self.add_to_related_collection(
   159             record.periodicals,
   160             record.periodicals,
   160             graph, 
   161             graph, 
   161             ['label','lang'],
   162             ['label','lang'],
   182         )
   183         )
   183 
   184 
   184         self.add_to_related_collection(
   185         self.add_to_related_collection(
   185             record.subjectCorporateBodies,
   186             record.subjectCorporateBodies,
   186             graph,
   187             graph,
   187             ['label', 'acronym'],
   188             ['uri'],
   188             "SELECT ?l ?a WHERE { [iiep:subjectCorporateBody ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:acronym ?a } }",
   189             "SELECT ?o WHERE { ?s iiep:subjectCorporateBody ?o. }",
       
   190             bindings={'s':URIRef(record.uri)}
   189         )
   191         )
   190 
   192 
   191         self.add_to_related_collection(
   193         self.add_to_related_collection(
   192             record.subjectMeetings,
   194             record.subjectMeetings,
   193             graph,
   195             graph,
   197         )
   199         )
   198 
   200 
   199         self.add_to_related_collection(
   201         self.add_to_related_collection(
   200             record.corporateAuthors,
   202             record.corporateAuthors,
   201             graph,
   203             graph,
   202             ['label', 'acronym'],
   204             ['uri'],
   203             "SELECT ?l ?a WHERE { [iiep:corporateAuthor ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:acronym ?a } }",            
   205             "SELECT ?o WHERE { ?s iiep:corporateAuthor ?o.}",
       
   206             bindings={'s':URIRef(record.uri)}            
   204         )
   207         )
   205 
   208 
   206         self.add_to_related_collection(
   209         self.add_to_related_collection(
   207             record.issns,
   210             record.issns,
   208             graph,
   211             graph,