[PATCH eac] Add support of <useDates><dateSet>

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Thu Sep 5 09:30:39 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1565341841 -7200
#      Fri Aug 09 11:10:41 2019 +0200
# Node ID 8c3de859843a16a4d36e49b77b9e1f731d808f74
# Parent  31c5c8e8a1d9e8d64c60603dc8a9e76da7c595b0
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 8c3de859843a
Add support of <useDates><dateSet>

diff -r 31c5c8e8a1d9 -r 8c3de859843a cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Tue Aug 06 17:41:19 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Fri Aug 09 11:10:41 2019 +0200
@@ -482,11 +482,15 @@
     @elem_maybe_none
     def build_date_entry(self, elem):
         """Build DateEntitys linked to a parent entity"""
-        for extentity in self.extract_dates_from(elem, 'eac:useDates'):
-            yield extentity
-        for date_set in self._elem_findall(elem, 'eac:dateSet'):
-            for extentity in self.extract_dates_from(date_set, 'eac:dateSet'):
+        for usedates in self._elem_findall(elem, 'eac:useDates'):
+            for extentity in self.build_date_entry(usedates):
                 yield extentity
+        if self._elem_find(elem, 'eac:dateSet'):
+            for date_set in self._elem_findall(elem, 'eac:dateSet'):
+                for extentity in self.extract_dates_from(date_set, 'eac:dateSet'):
+                    yield extentity
+        for entity in self.extract_dates_from(elem, 'eac:test'):
+            yield entity
 
     @filter_empty
     @filter_none
diff -r 31c5c8e8a1d9 -r 8c3de859843a test/data/FRAD033_EAC_00001_simplified.xml
--- a/test/data/FRAD033_EAC_00001_simplified.xml	Tue Aug 06 17:41:19 2019 +0200
+++ b/test/data/FRAD033_EAC_00001_simplified.xml	Fri Aug 09 11:10:41 2019 +0200
@@ -155,13 +155,29 @@
 	</nameEntry>
 
 	<useDates>
-	  <dateRange localType="open">
+	  <dateSet>
+	    <dateRange localType="open">
 	    <fromDate
 		standardDate="1949">1949
 	    </fromDate>
 	    <toDate>open
 	    </toDate>
 	  </dateRange>
+	  <dateRange localType="open">
+	    <fromDate
+		standardDate="1950">1950
+	    </fromDate>
+	    <toDate>open
+	    </toDate>
+	  </dateRange>
+	  <dateRange localType="open">
+	    <fromDate
+		standardDate="1950">1950
+	    </fromDate>
+	    <toDate>open
+	    </toDate>
+	  </dateRange>
+	  </dateSet>
 	  </useDates>	  
 	</nameEntryParallel>
     </identity>
diff -r 31c5c8e8a1d9 -r 8c3de859843a test/test_dataimport.py
--- a/test/test_dataimport.py	Tue Aug 06 17:41:19 2019 +0200
+++ b/test/test_dataimport.py	Fri Aug 09 11:10:41 2019 +0200
@@ -95,7 +95,7 @@
         return importer.external_entities()
 
     def test_parse_FRAD033_EAC_00001(self):
-        _gen_extid = map(str, (x for x in count() if x not in (2, 36))).next
+        _gen_extid = map(str, (x for x in count() if x not in (2, 38))).next
         expected = [
             ('EACOtherRecordId', _gen_extid(),
              {'eac_other_record_id_of': set(['authorityrecord-FRAD033_EAC_00001']),
@@ -215,14 +215,22 @@
              ),
             ('ParallelNames', _gen_extid(),
              {'parallel_names_of': set(['authorityrecord-FRAD033_EAC_00001']),
-              'date_relation': set(['17']),
-              'simple_name_relation': set(['20', '19', '18'])
+              'date_relation': set(['17', '18', '19']),
+              'simple_name_relation': set(['20', '21', '22'])
               },
              ),
             ('DateEntity', _gen_extid(),
              {'start_date': set([datetime.date(1949, 1, 1)])
               },
              ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1950, 1, 1)])
+              },
+             ),
+            ('DateEntity', _gen_extid(),
+             {'start_date': set([datetime.date(1950, 1, 1)])
+              },
+             ),
             ('NameEntry', _gen_extid(),
              {'parts': [u'Federal Chancellery\n\t  of Germany\n\t  ']
               },
@@ -244,8 +252,8 @@
             ('AgentPlace', _gen_extid(),
              {'role': set([u'siege']),
               'place_agent': set(['authorityrecord-FRAD033_EAC_00001']),
-              'place_entry_relation': set(['23']),
-              'place_address': set(['21']),
+              'place_entry_relation': set(['25']),
+              'place_address': set(['23']),
               },
              ),
             ('PlaceEntry', _gen_extid(),
@@ -255,7 +263,7 @@
              ),
             ('AgentPlace', _gen_extid(),
              {'place_agent': set(['authorityrecord-FRAD033_EAC_00001']),
-              'place_entry_relation': set(['25']),
+              'place_entry_relation': set(['27']),
               'role': set([u'domicile']),
               },
              ),
@@ -269,7 +277,7 @@
             ('AgentPlace', _gen_extid(),
              {'place_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               'role': set([u'dodo']),
-              'place_entry_relation': set(['27']),
+              'place_entry_relation': set(['29']),
               },
              ),
             ('PlaceEntry', _gen_extid(),
@@ -278,7 +286,7 @@
              ),
             ('LegalStatus', _gen_extid(),
              {'term': set([u'Collectivité territoriale']),
-              'date_relation': set(['29']),
+              'date_relation': set(['31']),
               'description': set([u'Description du statut']),
               'description_format': set([u'text/plain']),
               'legal_status_agent': set(['authorityrecord-FRAD033_EAC_00001']),
@@ -298,8 +306,8 @@
              ),
             ('History', _gen_extid(),
              {'abstract': set([u'Test of an abstract element']),
-              'has_citation': set(['37', '38']),
-              'has_event': set(['32', '34']),
+              'has_citation': set(['39', '40']),
+              'has_event': set(['34', '36']),
               'text': set(["\n".join((
                   u'<p xmlns="urn:isbn:1-931666-33-4" '
                   u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -323,7 +331,7 @@
               },
              ),
             ('HistoricalEvent', _gen_extid(),
-             {'date_relation': set(['33']),
+             {'date_relation': set(['35']),
               'event': [u'Left Mer and moved to the mainland.\n\t      '
                         u'Worked at various jobs including canecutter\n\t      '
                         u'and railway labourer.\n\t      '],
@@ -334,7 +342,7 @@
               'start_date': [datetime.date(1957, 1, 1)]}
              ),
             ('HistoricalEvent', _gen_extid(),
-             {'date_relation': set(['35']),
+             {'date_relation': set(['37']),
               'event': set([u'Union representative, Townsville-\n\t      '
                             u'Mount Isa rail construction project.\n\t      ']),
               },
@@ -356,7 +364,7 @@
                                   u'xmlns:xlink="http://www.w3.org/1999/xlink">Pour accomplir '
                                   u'ses missions ...</p>']),
               'description_format': set([u'text/html']),
-              'has_citation': set(['40']),
+              'has_citation': set(['42']),
               'structure_agent': set(['authorityrecord-FRAD033_EAC_00001']),
               },
              ),
@@ -398,11 +406,11 @@
              ),
             ('Occupation', _gen_extid(),
              {'term': set([u'Réunioniste']),
-              'date_relation': set(['45']),
+              'date_relation': set(['47']),
               'description': set([u'Organisation des réunions ...']),
               'description_format': set([u'text/plain']),
               'occupation_agent': set(['authorityrecord-FRAD033_EAC_00001']),
-              'has_citation': set(['46']),
+              'has_citation': set(['48']),
               'equivalent_concept': set(['http://pifgadget.com']),
               },
              ),
@@ -420,7 +428,7 @@
                               u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
                               u'xmlns:xlink="http://www.w3.org/1999/xlink">very famous</p>']),
               'content_format': set([u'text/html']),
-              'has_citation': set(['48']),
+              'has_citation': set(['50']),
               'general_context_of': set(['authorityrecord-FRAD033_EAC_00001']),
               }
              ),
@@ -436,7 +444,7 @@
             ('HierarchicalRelation', _gen_extid(),
              {'entry': set([u"Gironde. Conseil général. Direction de l'administration et de "
                             u"la sécurité juridique"]),
-              'date_relation': set(['50']),
+              'date_relation': set(['52']),
               'description': set([u'Coucou']),
               'description_format': set([u'text/plain']),
               'hierarchical_parent': set(['CG33-DIRADSJ']),
@@ -461,7 +469,7 @@
             ('ChronologicalRelation', _gen_extid(),
              {'chronological_predecessor': set(['whatever']),
               'chronological_successor': set(['authorityrecord-FRAD033_EAC_00001']),
-              'date_relation': set(['52']),
+              'date_relation': set(['54']),
               'entry': set([u'CG32']),
               },
              ),
@@ -473,7 +481,7 @@
             ('ChronologicalRelation', _gen_extid(),
              {'chronological_predecessor': set(['authorityrecord-FRAD033_EAC_00001']),
               'chronological_successor': set(['/dev/null']),
-              'date_relation': set(['54']),
+              'date_relation': set(['56']),
               'xml_wrap': set(['<gloups xmlns="urn:isbn:1-931666-33-4"'
                                u' xmlns:xsi="http://www.w3.org/2001/XML'
                                u'Schema-instance" xmlns:xlink="http://'
@@ -486,7 +494,7 @@
               },
              ),
             ('IdentityRelation', _gen_extid(),
-             {'date_relation': ['56'],
+             {'date_relation': ['58'],
               'entry': [u'Trash'],
               'identity_from': ['authorityrecord-FRAD033_EAC_00001'],
               'identity_to': ['/dev/null'],
@@ -498,7 +506,7 @@
              {'start_date': [datetime.date(2042, 1, 1)]}
              ),
             ('FamilyRelation', _gen_extid(),
-             {'date_relation': ['58'],
+             {'date_relation': ['60'],
               'entry': [u'CG32'],
               'family_from': ['authorityrecord-FRAD033_EAC_00001'],
               'family_to': ['whatever']}
@@ -514,7 +522,7 @@
              ),
             ('EACResourceRelation', _gen_extid(),
              {'agent_role': set([u'creatorOf']),
-              'date_relation': set(['61']),
+              'date_relation': set(['63']),
               'xml_attributes': set([u'{"{http://www.w3.org/1999/xlink}actuate": "onRequest", '
                                      u'"{http://www.w3.org/1999/xlink}show": "new", '
                                      u'"{http://www.w3.org/1999/xlink}type": "simple"}']),
@@ -576,7 +584,7 @@
                                   'and abolishment of schools.\n\t  </p>']),
               'r_type': set([u'controls']),
               'description_format': set([u'text/html']),
-              'date_relation': set(['64']),
+              'date_relation': set(['66']),
               'relation_entry': set([u'Establishment and abolishment\n\tof schools\n\t']),
               'xml_attributes': set([u'{}'])
               },
@@ -597,7 +605,7 @@
               'description_format': set([u'text/html']),
               'relation_entry': set([u'Some relation entry\n          ']),
               'xml_attributes': set([u'{}']),
-              'date_relation': ['66'],
+              'date_relation': ['68'],
               },
              ),
             ('DateEntity', _gen_extid(),
@@ -616,7 +624,7 @@
               'description_format': set([u'text/html']),
               'relation_entry': set([u'Some relation entry\n          ']),
               'xml_attributes': set([u'{}']),
-              'date_relation': ['68'],
+              'date_relation': ['70'],
               },
              ),
             ('DateEntity', _gen_extid(),
@@ -690,11 +698,11 @@
                           'recordId': set([8]),
                           'maintenanceAgency': set([16]),
                           'languageDeclaration': set([21]),
-                          'languageUsed': set([172, 179]),
+                          'languageUsed': set([188, 195]),
                           'localControl': set([54]),
                           'source': set([76]),  # empty.
-                          'structureOrGenealogy': set([252]),  # empty.
-                          'biogHist': set([312, 315]),  # empty.
+                          'structureOrGenealogy': set([268]),  # empty.
+                          'biogHist': set([328, 331]),  # empty.
                           })
 
     def check_order_entities(self, entities, expected):
@@ -828,7 +836,7 @@
                                cwuri=u'http://data.culture.fr/thesaurus/page/ark:/67717/T1-1074')
             cnx.commit()
             created, updated = testutils.eac_import(cnx, fpath)
-            self.assertEqual(len(created), 78)
+            self.assertEqual(len(created), 80)
             self.assertEqual(updated, set())
             rset = cnx.find('AuthorityRecord', isni=u'22330001300016')
             self.assertEqual(len(rset), 1)
@@ -987,7 +995,7 @@
         p_entity = rset.get_entity(1, 0)
         self.assertEqual(p_entity.parallel_names_of[0], record)
         self.assertEqual(len(p_entity.simple_name_relation), 3)
-        self.assertEqual(len(p_entity.date_relation), 1)
+        self.assertEqual(len(p_entity.date_relation), 3)
 
     def _check_equivalent_concept(self, cnx, record):
         functions = dict((f.name, f) for f in record.reverse_function_agent)


More information about the saem-devel mailing list