[PATCH eac V3] Add support for the <conventionDeclaration> Tag

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Fri Aug 2 12:04:35 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1564734036 -7200
#      Fri Aug 02 10:20:36 2019 +0200
# Node ID a2f882169ffed6331d9ac796f589d5e17c68b9cb
# Parent  a1b035dea4bd1b4148ae947b686bc89165d6486f
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r a2f882169ffe
Add support for the <conventionDeclaration> Tag

Add 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`.

diff -r a1b035dea4bd -r a2f882169ffe cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Fri Aug 02 10:19:29 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Fri Aug 02 10:20:36 2019 +0200
@@ -40,11 +40,11 @@
 TYPE_MAPPING['human'] = u'person'
 
 ETYPES_ORDER_HINT = ('AgentKind', 'PhoneNumber', 'PostalAddress', 'AuthorityRecord',
-                     'AgentPlace', 'Mandate', 'LegalStatus', 'History', 'HistoricalEvent',
-                     'Structure', 'AgentFunction', 'Occupation', 'GeneralContext',
-                     'AssociationRelation', 'ChronologicalRelation', 'HierarchicalRelation',
-                     'EACResourceRelation', 'ExternalUri', 'EACSource',
-                     'Activity')
+                     'Convention', 'AgentPlace', 'Mandate', 'LegalStatus',
+                     'History', 'HistoricalEvent', 'Structure', 'AgentFunction', 'Occupation',
+                     'GeneralContext', 'AssociationRelation', 'ChronologicalRelation',
+                     'HierarchicalRelation', 'EACResourceRelation', 'ExternalUri',
+                     'EACSource', 'Activity')
 
 
 class InvalidEAC(RuntimeError):
@@ -889,6 +889,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 +921,19 @@
             values['agent'] = set([text_type(agent.text)])
         yield ExtEntity('Activity', self._gen_extid(), values)
 
+    @relate_to_record_through('Convention', 'convention_of')
+    @add_citations_for('Convention')
+    @filter_none
+    @filter_empty
+    @elem_maybe_none
+    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 a1b035dea4bd -r a2f882169ffe cubicweb_eac/i18n/en.po
--- a/cubicweb_eac/i18n/en.po	Fri Aug 02 10:19:29 2019 +0200
+++ b/cubicweb_eac/i18n/en.po	Fri Aug 02 10:20:36 2019 +0200
@@ -72,6 +72,10 @@
 msgid "Citation"
 msgstr ""
 
+msgctxt "inlined:Convention.has_citation.subject"
+msgid "Citation"
+msgstr ""
+
 msgctxt "inlined:GeneralContext.has_citation.subject"
 msgid "Citation"
 msgstr ""
@@ -95,6 +99,12 @@
 msgid "Citation_plural"
 msgstr "Citations"
 
+msgid "Convention"
+msgstr ""
+
+msgid "Convention_plural"
+msgstr ""
+
 msgid "EAC export"
 msgstr ""
 
@@ -234,6 +244,9 @@
 msgid "New Citation"
 msgstr "New citation"
 
+msgid "New Convention"
+msgstr ""
+
 msgid "New EACOtherRecordId"
 msgstr "New alternative identifier"
 
@@ -298,6 +311,9 @@
 "EAC-CPF model."
 msgstr ""
 
+msgid "Rules or conventions applied in creating the EAC-CPF instance"
+msgstr ""
+
 msgid "Structure"
 msgstr "Piece of Structure information"
 
@@ -349,6 +365,12 @@
 msgid "This Citation:"
 msgstr "This citation:"
 
+msgid "This Convention"
+msgstr ""
+
+msgid "This Convention:"
+msgstr ""
+
 msgid "This EACOtherRecordId"
 msgstr "This alternative identifier"
 
@@ -426,6 +448,15 @@
 
 # subject and object forms for each relation type
 # (no object form for final or symmetric relation types)
+msgid "abbrev"
+msgstr ""
+
+msgctxt "Convention"
+msgid "abbrev"
+msgstr ""
+
+# subject and object forms for each relation type
+# (no object form for final or symmetric relation types)
 msgid "abstract"
 msgstr ""
 
@@ -440,6 +471,9 @@
 msgid "abstract_format"
 msgstr ""
 
+msgid "add Convention convention_of AuthorityRecord object"
+msgstr ""
+
 msgid "add History has_event HistoricalEvent subject"
 msgstr ""
 
@@ -472,6 +506,10 @@
 msgid "add a Citation"
 msgstr ""
 
+msgctxt "inlined:Convention.has_citation.subject"
+msgid "add a Citation"
+msgstr ""
+
 msgctxt "inlined:GeneralContext.has_citation.subject"
 msgid "add a Citation"
 msgstr ""
@@ -492,6 +530,9 @@
 msgid "add a Citation"
 msgstr ""
 
+msgid "add a Convention"
+msgstr ""
+
 msgid "add a EACOtherRecordId"
 msgstr "add an alternative identifier"
 
@@ -670,6 +711,20 @@
 "contextual role the address has in relation with the agent (e.g. \"home\")"
 msgstr ""
 
+msgid "convention_of"
+msgstr ""
+
+msgctxt "Convention"
+msgid "convention_of"
+msgstr ""
+
+msgid "convention_of_object"
+msgstr ""
+
+msgctxt "AuthorityRecord"
+msgid "convention_of_object"
+msgstr ""
+
 #, python-format
 msgid "could not parse a year from date element %(e)s"
 msgstr ""
@@ -682,6 +737,10 @@
 msgid "could not parse date from %s"
 msgstr ""
 
+msgid ""
+"creating Convention (Convention convention_of AuthorityRecord %(linkto)s)"
+msgstr ""
+
 msgid "creating HistoricalEvent (History %(linkto)s has_event HistoricalEvent)"
 msgstr ""
 
@@ -703,6 +762,10 @@
 msgid "description"
 msgstr ""
 
+msgctxt "Convention"
+msgid "description"
+msgstr ""
+
 msgctxt "EACResourceRelation"
 msgid "description"
 msgstr ""
@@ -743,6 +806,10 @@
 msgid "description_format"
 msgstr ""
 
+msgctxt "Convention"
+msgid "description_format"
+msgstr ""
+
 msgctxt "EACResourceRelation"
 msgid "description_format"
 msgstr ""
@@ -998,6 +1065,10 @@
 msgid "has_citation"
 msgstr ""
 
+msgctxt "Convention"
+msgid "has_citation"
+msgstr ""
+
 msgctxt "GeneralContext"
 msgid "has_citation"
 msgstr ""
diff -r a1b035dea4bd -r a2f882169ffe cubicweb_eac/i18n/fr.po
--- a/cubicweb_eac/i18n/fr.po	Fri Aug 02 10:19:29 2019 +0200
+++ b/cubicweb_eac/i18n/fr.po	Fri Aug 02 10:20:36 2019 +0200
@@ -95,9 +95,19 @@
 msgid "Citation"
 msgstr ""
 
+msgctxt "inlined:Convention.has_citation.subject"
+msgid "Citation"
+msgstr "
+
 msgid "Citation_plural"
 msgstr "Citations"
 
+msgid "Convention"
+msgstr ""
+
+msgid "Convention_plural"
+msgstr "Conventions"
+
 msgid "EAC export"
 msgstr "export EAC"
 
@@ -237,6 +247,9 @@
 msgid "New Citation"
 msgstr "Nouvelle citation"
 
+msgid "New Convention"
+msgstr "Nouvelle convention"
+
 msgid "New EACOtherRecordId"
 msgstr "Nouvel identifiant alternatif"
 
@@ -303,6 +316,9 @@
 "Représente une relation entre une notice et une ressource distante dans le "
 "modèle EAC-CPF."
 
+msgid "Rules or conventions applied in creating the EAC-CPF instance"
+msgstr "Règles ou conventions a appliquer lors de la création de la notice"
+
 msgid "Structure"
 msgstr "Élément d'organisation interne"
 
@@ -354,6 +370,12 @@
 msgid "This Citation:"
 msgstr "Cette citation :"
 
+msgid "This Convention"
+msgstr "Cette convention"
+
+msgid "This Convention:"
+msgstr "Cette convention:"
+
 msgid "This EACOtherRecordId"
 msgstr "Cet identifiant alternatif"
 
@@ -431,6 +453,13 @@
 
 # subject and object forms for each relation type
 # (no object form for final or symmetric relation types)
+msgid "abbrev"
+msgstr ""
+
+msgctxt "Convention"
+msgid "abbrev"
+msgstr "abbréviation"
+
 msgid "abstract"
 msgstr ""
 
@@ -445,6 +474,9 @@
 msgid "abstract_format"
 msgstr ""
 
+msgid "add Convention convention_of AuthorityRecord object"
+msgstr "ajouter une convention"
+
 msgid "add History has_event HistoricalEvent subject"
 msgstr "ajouter un événement historique"
 
@@ -676,6 +708,20 @@
 msgstr ""
 "rôle contextuel de l'adresse vis-à-vis de l'agent (par ex. \"domicile\")"
 
+msgid "convention_of"
+msgstr "convention de"
+
+msgctxt "Convention"
+msgid "convention_of"
+msgstr "convention de"
+
+msgid "convention_of_object"
+msgstr "Convention de cet objet"
+
+msgctxt "AuthorityRecord"
+msgid "convention_of_object"
+msgstr "Convention de cette notive"
+
 #, python-format
 msgid "could not parse a year from date element %(e)s"
 msgstr "ne peux identifier une année dans la date %(e)s"
@@ -688,6 +734,10 @@
 msgid "could not parse date from %s"
 msgstr "impossible de décoder une date à partir de %s"
 
+msgid ""
+"creating Convention (Convention convention_of AuthorityRecord %(linkto)s)"
+msgstr ""
+
 msgid "creating HistoricalEvent (History %(linkto)s has_event HistoricalEvent)"
 msgstr ""
 
@@ -709,6 +759,10 @@
 msgid "description"
 msgstr ""
 
+msgctxt "Convention"
+msgid "description"
+msgstr ""
+
 msgctxt "EACResourceRelation"
 msgid "description"
 msgstr ""
@@ -749,6 +803,10 @@
 msgid "description_format"
 msgstr ""
 
+msgctxt "Convention"
+msgid "description_format"
+msgstr ""
+
 msgctxt "EACResourceRelation"
 msgid "description_format"
 msgstr ""
@@ -1016,6 +1074,10 @@
 msgid "has_citation"
 msgstr ""
 
+msgctxt "Convention"
+msgid "has_citation"
+msgstr ""
+
 msgctxt "GeneralContext"
 msgid "has_citation"
 msgstr ""
diff -r a1b035dea4bd -r a2f882169ffe cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Fri Aug 02 10:19:29 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Fri Aug 02 10:20:36 2019 +0200
@@ -1,2 +1,3 @@
 add_attribute('History', 'abstract')
 add_entity_type('HistoricalEvent')
+add_entity_type('Convention')
diff -r a1b035dea4bd -r a2f882169ffe cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Fri Aug 02 10:19:29 2019 +0200
+++ b/cubicweb_eac/schema.py	Fri Aug 02 10:20:36 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)
@@ -348,7 +361,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 a1b035dea4bd -r a2f882169ffe doc/supported.rst
--- a/doc/supported.rst	Fri Aug 02 10:19:29 2019 +0200
+++ b/doc/supported.rst	Fri Aug 02 10:20:36 2019 +0200
@@ -29,7 +29,7 @@
   .            citation         
   x         componentEntry      
   .            control          
-  x     conventionDeclaration   
+  .     conventionDeclaration
   .         cpfDescription      
   .          cpfRelation        
   .              date           
diff -r a1b035dea4bd -r a2f882169ffe test/test_dataimport.py
--- a/test/test_dataimport.py	Fri Aug 02 10:19:29 2019 +0200
+++ b/test/test_dataimport.py	Fri Aug 02 10:20:36 2019 +0200
@@ -124,6 +124,45 @@
               '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" '
+                                  u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+                                  u'xmlns:xlink="http://www.w3.org/1999/xlink">Norme '
+                                  u'ISAAR(CPF) du Conseil international des archives, '
+                                  u'2e \xe9dition, 1996.</p>']),
+             },
+            ),
+            ('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" '
+                                  u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+                                  u'xmlns:xlink="http://www.w3.org/1999/xlink">AFNOR '
+                                  u'NF Z 44-060, octobre 1983, Catalogue '
+                                  u'd\u2019auteurs et d\u2019anonymes : forme et\n          '
+                                  u'structure des vedettes des collectivit\xe9s auteurs.</p>']),
+             },
+            ),
+            ('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" '
+                                  u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+                                  u'xmlns:xlink="http://www.w3.org/1999/xlink">Norme ISO 8601 '
+                                  u':2004 \xc9l\xe9ments de donn\xe9es et formats '
+                                  u'd\u2019\xe9change -- \xc9change\n          '
+                                  u'd\u2019information -- Repr\xe9sentation de la date et '
+                                  u'de l\u2019heure.</p>']),
+             },
+            ),
             ('AgentKind', 'agentkind/authority',
              {'name': set([u'authority'])},
             ),
@@ -149,8 +188,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 +231,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(),
@@ -261,7 +300,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']),
              },
             ),
@@ -274,7 +313,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']),
               }
             ),
@@ -386,7 +425,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.
@@ -488,7 +526,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)
@@ -511,7 +549,7 @@
             self.assertEqual(len(record.reverse_function_agent), 3)
             for related in ('structure', 'history', 'mandate', 'occupation',
                             'generalcontext', 'legal_status', 'eac_relations',
-                            'equivalent_concept', 'control'):
+                            'equivalent_concept', 'control', 'convention'):
                 with self.subTest(related=related):
                     checker = getattr(self, '_check_' + related)
                     checker(cnx, record)
@@ -523,6 +561,14 @@
                                                     format=u'text/plain').strip(),
                          u'Pour accomplir ses missions ...')
 
+    def _check_convention(self, cnx, record):
+        rset = cnx.find('Convention', convention_of=record).sorted_rset(lambda x: x.eid)
+        self.assertEqual(len(rset), 3)
+        self.assertEqual(rset.get_entity(0, 0)
+                         .printable_value('description', format=u'text/plain').strip(),
+                         u'Norme ISAAR(CPF) du Conseil international des archives, '
+                         u'2e \xe9dition, 1996.')
+
     def _check_history(self, cnx, record):
         rset = cnx.find('History', history_agent=record)
         self.assertEqual(len(rset), 1)
diff -r a1b035dea4bd -r a2f882169ffe test/test_schema.py
--- a/test/test_schema.py	Fri Aug 02 10:19:29 2019 +0200
+++ b/test/test_schema.py	Fri Aug 02 10:20:36 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'])},
             'HistoricalEvent': {('has_event', 'object'): set(['History'])},
             'GeneralContext': {('general_context_of', 'subject'): set(['AuthorityRecord'])},


More information about the saem-devel mailing list