[PATCH 05 of 14 eac] Add the support for the <conventionDeclaration> Tag

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Tue Jul 2 14:53:54 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1560955816 -7200
#      Wed Jun 19 16:50:16 2019 +0200
# Node ID 1ff1ed4d83b3377a1c2dc786402e5887dd7107b0
# Parent  cbc571e95ad888774c79fb5e99c56e9cc35b9d7b
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 1ff1ed4d83b3
Add the support for the <conventionDeclaration> Tag

Add the support of a new tag, by the creation of the `Convention` entity. I choose to stick to the style of the schema and made the entity a child of `AuthorityRecord`. Also updated the `has_citation` relation definition so the new `Convention` entity can handle a `Citation` child.

Not sure about how I use the filtering decorators. I think I use them too much.

Differential Revision: https://phab.logilab.fr/D3514

diff -r cbc571e95ad8 -r 1ff1ed4d83b3 cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Mon Jun 17 11:13:39 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Wed Jun 19 16:50:16 2019 +0200
@@ -40,7 +40,7 @@
 TYPE_MAPPING['human'] = u'person'
 
 ETYPES_ORDER_HINT = ('AgentKind', 'PhoneNumber', 'PostalAddress', 'AuthorityRecord',
-                     'AgentPlace', 'Mandate', 'LegalStatus', 'History', 'Event',
+                     'Convention', 'AgentPlace', 'Mandate', 'LegalStatus', 'History', 'Event',
                      'Structure', 'AgentFunction', 'Occupation', 'GeneralContext',
                      'AssociationRelation', 'ChronologicalRelation', 'HierarchicalRelation',
                      'EACResourceRelation', 'ExternalUri', 'EACSource',
@@ -613,9 +613,7 @@
                 date_range = self._elem_find(citem, 'eac:dateRange')
                 event = self._elem_find(citem, 'eac:event')
                 if event is not None and event.text:
-                    sentences = [text_type(line.strip()) for line in event.text.split('\n')]
-                    filtered = [e for e in sentences if e != '']
-                    values['event'] = set(["".join(filtered)])
+                    values['event'] = set([text_type(event.text)])
                     if date is None and date_range:
                         date_range = self.parse_daterange(date_range)
                         values.update(date_range)
@@ -889,6 +887,10 @@
                                   namespaces=self.namespaces):
             for extentity in self.build_maintenance_event(elem):
                 yield extentity
+        for elem in control.xpath('eac:conventionDeclaration',
+                                  namespaces=self.namespaces):
+            for extentity in self.build_convention(elem):
+                yield extentity
 
     def build_maintenance_event(self, elem):
         """Parse a `maintenanceEvent` tag, yielding a prov:Activity external
@@ -917,6 +919,19 @@
             values['agent'] = set([text_type(agent.text)])
         yield ExtEntity('Activity', self._gen_extid(), values)
 
+    @filter_none
+    @filter_empty
+    @elem_maybe_none
+    @relate_to_record_through('Convention', 'convention_of')
+    @add_child_for('Convention', 'has_citation')
+    def build_convention(self, elem):
+        """Build a `Convention` external entity"""
+        values = self.parse_tag_description(elem)
+        abbrev = self._elem_find(elem, 'eac:abbreviation')
+        if abbrev is not None and abbrev.text:
+            values['abbrev'] = set([text_type(abbrev.text)])
+        yield ExtEntity('Convention', self._gen_extid(), values)
+
     @elem_maybe_none
     def parse_event_type(self, elem):
         """Parse an `eventType` element and try to match a prov:type to build a
diff -r cbc571e95ad8 -r 1ff1ed4d83b3 cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Mon Jun 17 11:13:39 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Wed Jun 19 16:50:16 2019 +0200
@@ -1,2 +1,3 @@
 add_attribute('History', 'abstract')
 add_entity_type('Event')
+add_entity_type('Convention')
diff -r cbc571e95ad8 -r 1ff1ed4d83b3 cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Mon Jun 17 11:13:39 2019 +0200
+++ b/cubicweb_eac/schema.py	Wed Jun 19 16:50:16 2019 +0200
@@ -179,6 +179,13 @@
     fulltext_container = 'object'
 
 
+class convention_of(RelationDefinition):
+    subject = 'Convention'
+    object = 'AuthorityRecord'
+    cardinality = '1*'
+    composite = 'object'
+
+
 class _agent_relation(RelationDefinition):
     """Abstract relation between authority record"""
     subject = None
@@ -259,6 +266,12 @@
     description = RichString(fulltextindexed=True)
 
 
+class Convention(EntityType):
+    "Rules or conventions applied in creating the EAC-CPF instance"
+    abbrev = String(fulltextindexed=True)
+    description = RichString(fulltextindexed=True)
+
+
 class History(EntityType):
     """Biographical or historical information"""
     abstract = RichString(fulltextindexed=True)
@@ -349,7 +362,7 @@
 
 class has_citation(RelationDefinition):
     subject = ('GeneralContext', 'Mandate', 'Occupation', 'History',
-               'AgentFunction', 'LegalStatus', 'AgentPlace')
+               'AgentFunction', 'LegalStatus', 'AgentPlace', 'Convention')
     object = 'Citation'
     cardinality = '*1'
     composite = 'subject'
diff -r cbc571e95ad8 -r 1ff1ed4d83b3 doc/supported.rst
--- a/doc/supported.rst	Mon Jun 17 11:13:39 2019 +0200
+++ b/doc/supported.rst	Wed Jun 19 16:50:16 2019 +0200
@@ -24,12 +24,12 @@
   x         alternativeSet      
   .         authorizedForm      
   .            biogHist         
-  x           chronItem         
-  x           chronList         
+  .           chronItem
+  .           chronList
   .            citation         
   x         componentEntry      
   .            control          
-  x     conventionDeclaration   
+  .     conventionDeclaration
   .         cpfDescription      
   .          cpfRelation        
   .              date           
@@ -40,7 +40,7 @@
   .            eac-cpf          
   .            entityId         
   .           entityType        
-  x             event           
+  .             event
   .         eventDateTime       
   .        eventDescription     
   .           eventType         
diff -r cbc571e95ad8 -r 1ff1ed4d83b3 test/test_dataimport.py
--- a/test/test_dataimport.py	Mon Jun 17 11:13:39 2019 +0200
+++ b/test/test_dataimport.py	Wed Jun 19 16:50:16 2019 +0200
@@ -124,6 +124,29 @@
               'agent': set([u'Delphine Jamet'])
              },
             ),
+            ('Convention', _gen_extid(),
+             {'convention_of': ['FRAD033_EAC_00001'],
+              'abbrev': set([u'ISAAR(CPF)']),
+              'has_citation': ['8'],
+              'description_format': set([u'text/html']),
+              'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">Norme ISAAR(CPF) du Conseil international des archives, 2e \xe9dition, 1996.</p>']), # noqa
+             },
+            ),
+            ('Citation', _gen_extid(),
+             {'uri': set([u'http://www.ica.org']),
+             },
+            ),
+            ('Convention', _gen_extid(),
+             {'convention_of': ['FRAD033_EAC_00001'],
+              'description_format': set([u'text/html']),
+              'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">AFNOR NF Z 44-060, octobre 1983, Catalogue d\u2019auteurs et d\u2019anonymes : forme et\n          structure des vedettes des collectivit\xe9s auteurs.</p>']), # noqa
+             },
+            ),
+            ('Convention', _gen_extid(),
+             {'convention_of': ['FRAD033_EAC_00001'],
+              'description_format': set([u'text/html']), 'description': set([u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">Norme ISO 8601 :2004 \xc9l\xe9ments de donn\xe9es et formats d\u2019\xe9change -- \xc9change\n          d\u2019information -- Repr\xe9sentation de la date et de l\u2019heure.</p>']), # noqa
+             },
+            ),
             ('AgentKind', 'agentkind/authority',
              {'name': set([u'authority'])},
             ),
@@ -149,8 +172,8 @@
              {'name': set([u'Bordeaux (Gironde, France)']),
               'role': set([u'siege']),
               'place_agent': set(['FRAD033_EAC_00001']),
-              'place_address': set(['9']),
-              'equivalent_concept': set([u'http://catalogue.bnf.fr/ark:/12148/cb152418385']),
+              'place_address': set(['13']),
+              'equivalent_concept': set(['http://catalogue.bnf.fr/ark:/12148/cb152418385']),
              },
             ),
             ('AgentPlace', _gen_extid(),
@@ -192,8 +215,8 @@
               ]),
               'text_format': set([u'text/html']),
               'history_agent': set(['FRAD033_EAC_00001']),
-              'has_citation': set(['16', '17']),
-              'has_event': set(['18', '19']),
+              'has_citation': set(['20', '21']),
+              'has_event': set(['22', '23']),
              },
             ),
             ('Citation', _gen_extid(),
@@ -203,15 +226,12 @@
              {'uri': set(['http://pifgadget']), 'note': set(['Voir aussi pifgadget'])},
             ),
             ('Event', _gen_extid(),
-             {'event': [u'Left Mer and moved to the mainland.'
-                        u'Worked at various jobs including canecutter'
-                        u'and railway labourer.'],
+             {'event': [u'Left Mer and moved to the mainland.\n\t      Worked at various jobs including canecutter\n\t      and railway labourer.\n\t      '], # noqa
               'end_date': set([datetime.date(1957, 1, 1)]),
               'start_date': set([datetime.date(1957, 1, 1)])}
             ),
             ('Event', _gen_extid(),
-             {'event': set([u'Union representative, Townsville-'
-                            u'Mount Isa rail construction project.']),
+             {'event': set([u'Union representative, Townsville-\n\t      Mount Isa rail construction project.\n\t      ']), # noqa
               'end_date': set([datetime.date(1961, 1, 1)]),
               'start_date': set([datetime.date(1960, 1, 1)])}
             ),
@@ -252,7 +272,7 @@
               'description': set([u'Organisation des réunions ...']),
               'description_format': set([u'text/plain']),
               'occupation_agent': set(['FRAD033_EAC_00001']),
-              'has_citation': set(['25']),
+              'has_citation': set(['29']),
               'equivalent_concept': set(['http://pifgadget.com']),
              },
             ),
@@ -265,7 +285,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(['27']),
+              'has_citation': set(['31']),
               'general_context_of': set(['FRAD033_EAC_00001']),
               }
             ),
@@ -350,7 +370,7 @@
              {'uri': set([u'http://catalogue.bnf.fr/ark:/12148/cb152418385']),
               'cwuri': set([u'http://catalogue.bnf.fr/ark:/12148/cb152418385'])},
            ),
-            ('ExternalUri', 'http://pifgadget.com',
+             ('ExternalUri', 'http://pifgadget.com',
              {'uri': set([u'http://pifgadget.com']),
               'cwuri': set([u'http://pifgadget.com'])},
             ),
@@ -377,7 +397,6 @@
                           'publicationStatus': set([14]),
                           'maintenanceAgency': set([16]),
                           'languageDeclaration': set([21]),
-                          'conventionDeclaration': set([25, 35, 44]),
                           'localControl': set([54]),
                           'source': set([76]),  # empty.
                           'structureOrGenealogy': set([189]),  # empty.
@@ -479,7 +498,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), 41)
+            self.assertEqual(len(created), 45)
             self.assertEqual(updated, set())
             rset = cnx.find('AuthorityRecord', isni=u'22330001300016')
             self.assertEqual(len(rset), 1)
@@ -514,6 +533,16 @@
                                                     format=u'text/plain').strip(),
                          u'Pour accomplir ses missions ...')
 
+    def _check_convention(self, cnx, record):
+        rset = cnx.find('History', convention_of=record)
+        self.assertEqual(len(rset), 3)
+        self.assertEqual(rset.one().printable_value('description', format=u'text/plain').strip(),
+                         u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">Norme ISAAR(CPF) du Conseil international des archives, 2e \xe9dition, 1996.</p>') # noqa
+        self.assertEqual(rset.one().printable_value('description', format=u'text/plain').strip(),
+                         u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">AFNOR NF Z 44-060, octobre 1983, Catalogue d\u2019auteurs et d\u2019anonymes : forme et\n          structure des vedettes des collectivit\xe9s auteurs.</p>') # noqa
+        self.assertEqual(rset.one().printable_value('description', format=u'text/plain').strip(),
+                         u'<p xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">Norme ISO 8601 :2004 \xc9l\xe9ments de donn\xe9es et formats d\u2019\xe9change -- \xc9change\n          d\u2019information -- Repr\xe9sentation de la date et de l\u2019heure.</p>') # noqa
+
     def _check_history(self, cnx, record):
         rset = cnx.find('History', history_agent=record)
         self.assertEqual(rset.one().printable_value('abstract', format=u'text/plain').strip(),
diff -r cbc571e95ad8 -r 1ff1ed4d83b3 test/test_schema.py
--- a/test/test_schema.py	Mon Jun 17 11:13:39 2019 +0200
+++ b/test/test_schema.py	Wed Jun 19 16:50:16 2019 +0200
@@ -101,12 +101,13 @@
             'AgentPlace': {('place_agent', 'subject'): set(['AuthorityRecord'])},
             'Citation': {('has_citation', 'object'): set([
                 'GeneralContext', 'Mandate', 'Occupation', 'AgentFunction',
-                'AgentPlace', 'History', 'LegalStatus',
+                'AgentPlace', 'History', 'LegalStatus', 'Convention',
             ])},
             'EACOtherRecordId': {('eac_other_record_id_of', 'subject'):
                                  set(['AuthorityRecord'])},
             'EACResourceRelation': {('resource_relation_agent', 'subject'):
                                     set(['AuthorityRecord'])},
+            'Convention': {('convention_of', 'subject'): set(['AuthorityRecord'])},
             'EACSource': {('source_agent', 'subject'): set(['AuthorityRecord'])},
             'Event': {('has_event', 'object'): set(['History'])},
             'GeneralContext': {('general_context_of', 'subject'): set(['AuthorityRecord'])},


More information about the saem-devel mailing list