[PATCH 06 of 14 eac] Add support for <languageDeclaration>

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


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1561039222 -7200
#      Thu Jun 20 16:00:22 2019 +0200
# Node ID 81fab457faebf1851f7d5e7cc0826684f64fba1f
# Parent  1ff1ed4d83b3377a1c2dc786402e5887dd7107b0
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 81fab457faeb
Add support for <languageDeclaration>

Basic adding of a new entity: `LanguageDec`.
It is added as a child of AuthorityRecord.

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

diff -r 1ff1ed4d83b3 -r 81fab457faeb cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Wed Jun 19 16:50:16 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Thu Jun 20 16:00:22 2019 +0200
@@ -40,11 +40,11 @@
 TYPE_MAPPING['human'] = u'person'
 
 ETYPES_ORDER_HINT = ('AgentKind', 'PhoneNumber', 'PostalAddress', 'AuthorityRecord',
-                     'Convention', 'AgentPlace', 'Mandate', 'LegalStatus', 'History', 'Event',
-                     'Structure', 'AgentFunction', 'Occupation', 'GeneralContext',
-                     'AssociationRelation', 'ChronologicalRelation', 'HierarchicalRelation',
-                     'EACResourceRelation', 'ExternalUri', 'EACSource',
-                     'Activity')
+                     'Convention', 'LanguageDec', 'AgentPlace', 'Mandate', 'LegalStatus',
+                     'History', 'Event', 'Structure', 'AgentFunction', 'Occupation',
+                     'GeneralContext', 'AssociationRelation', 'ChronologicalRelation',
+                     'HierarchicalRelation', 'EACResourceRelation', 'ExternalUri',
+                     'EACSource', 'Activity')
 
 
 class InvalidEAC(RuntimeError):
@@ -887,6 +887,10 @@
                                   namespaces=self.namespaces):
             for extentity in self.build_maintenance_event(elem):
                 yield extentity
+        for elem in control.xpath('eac:languageDeclaration',
+                                  namespaces=self.namespaces):
+            for extentity in self.build_language_declaration(elem):
+                yield extentity
         for elem in control.xpath('eac:conventionDeclaration',
                                   namespaces=self.namespaces):
             for extentity in self.build_convention(elem):
@@ -919,11 +923,25 @@
             values['agent'] = set([text_type(agent.text)])
         yield ExtEntity('Activity', self._gen_extid(), values)
 
+    @relate_to_record_through('LanguageDec', 'language_declaration_of')
+    @filter_empty
+    @elem_maybe_none
+    def build_language_declaration(self, elem):
+        """Build a `LanguageDec` external entity"""
+        values = self.parse_tag_description(elem)
+        language = self._elem_find(elem, 'eac:language')
+        script = self._elem_find(elem, 'eac:script')
+        if language is not None and language.text:
+            values['language'] = set([text_type(etree.tostring(language).strip())])
+        if script is not None and script.text:
+            values['script'] = set([text_type(etree.tostring(script).strip())])
+        yield ExtEntity('LanguageDec', self._gen_extid(), values)
+
+    @relate_to_record_through('Convention', 'convention_of')
+    @add_child_for('Convention', 'has_citation')
     @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)
diff -r 1ff1ed4d83b3 -r 81fab457faeb cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Wed Jun 19 16:50:16 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Thu Jun 20 16:00:22 2019 +0200
@@ -1,3 +1,4 @@
 add_attribute('History', 'abstract')
 add_entity_type('Event')
 add_entity_type('Convention')
+add_entity_type('LanguageDec')
diff -r 1ff1ed4d83b3 -r 81fab457faeb cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Wed Jun 19 16:50:16 2019 +0200
+++ b/cubicweb_eac/schema.py	Thu Jun 20 16:00:22 2019 +0200
@@ -186,6 +186,13 @@
     composite = 'object'
 
 
+class language_declaration_of(RelationDefinition):
+    subject = 'LanguageDec'
+    object = 'AuthorityRecord'
+    cardinality = '1*'
+    composite = 'object'
+
+
 class _agent_relation(RelationDefinition):
     """Abstract relation between authority record"""
     subject = None
@@ -266,6 +273,12 @@
     description = RichString(fulltextindexed=True)
 
 
+class LanguageDec(EntityType):
+    language = String(fulltextindexed=True)
+    script = String(fulltextindexed=True)
+    description = RichString(fulltextindexed=True)
+
+
 class Convention(EntityType):
     "Rules or conventions applied in creating the EAC-CPF instance"
     abbrev = String(fulltextindexed=True)
diff -r 1ff1ed4d83b3 -r 81fab457faeb test/test_dataimport.py
--- a/test/test_dataimport.py	Wed Jun 19 16:50:16 2019 +0200
+++ b/test/test_dataimport.py	Thu Jun 20 16:00:22 2019 +0200
@@ -124,10 +124,16 @@
               'agent': set([u'Delphine Jamet'])
              },
             ),
+            ('LanguageDec', _gen_extid(),
+             {'language_declaration_of': ['FRAD033_EAC_00001'],
+              'language': set([u'<language xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" languageCode="fre">français</language>']), # noqa
+              'script': set([u'<script xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" scriptCode="Latn">latin</script>']) # noqa
+             },
+            ),
             ('Convention', _gen_extid(),
              {'convention_of': ['FRAD033_EAC_00001'],
               'abbrev': set([u'ISAAR(CPF)']),
-              'has_citation': ['8'],
+              'has_citation': ['9'],
               '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
              },
@@ -172,7 +178,7 @@
              {'name': set([u'Bordeaux (Gironde, France)']),
               'role': set([u'siege']),
               'place_agent': set(['FRAD033_EAC_00001']),
-              'place_address': set(['13']),
+              'place_address': set(['14']),
               'equivalent_concept': set(['http://catalogue.bnf.fr/ark:/12148/cb152418385']),
              },
             ),
@@ -215,8 +221,8 @@
               ]),
               'text_format': set([u'text/html']),
               'history_agent': set(['FRAD033_EAC_00001']),
-              'has_citation': set(['20', '21']),
-              'has_event': set(['22', '23']),
+              'has_citation': set(['21', '22']),
+              'has_event': set(['24', '23']),
              },
             ),
             ('Citation', _gen_extid(),
@@ -272,7 +278,7 @@
               'description': set([u'Organisation des réunions ...']),
               'description_format': set([u'text/plain']),
               'occupation_agent': set(['FRAD033_EAC_00001']),
-              'has_citation': set(['29']),
+              'has_citation': set(['30']),
               'equivalent_concept': set(['http://pifgadget.com']),
              },
             ),
@@ -285,7 +291,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(['31']),
+              'has_citation': set(['32']),
               'general_context_of': set(['FRAD033_EAC_00001']),
               }
             ),
@@ -396,7 +402,6 @@
                          {'maintenanceStatus': set([12]),
                           'publicationStatus': set([14]),
                           'maintenanceAgency': set([16]),
-                          'languageDeclaration': set([21]),
                           'localControl': set([54]),
                           'source': set([76]),  # empty.
                           'structureOrGenealogy': set([189]),  # empty.
@@ -498,7 +503,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), 45)
+            self.assertEqual(len(created), 46)
             self.assertEqual(updated, set())
             rset = cnx.find('AuthorityRecord', isni=u'22330001300016')
             self.assertEqual(len(rset), 1)
@@ -543,6 +548,14 @@
         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_language_declaration(self, cnx, record):
+        rset = cnx.find('LanguageDec', language_declaration_of=record)
+        self.assertEqual(len(rset), 1)
+        self.assertEqual(rset.one().printable_value('language', format=u'text/plain').strip(),
+                         u'<language xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" languageCode="fre">français</language>') # noqa
+        self.assertEqual(rset.one().printable_value('script', format=u'text/plain').strip(),
+                         u'<script xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" scriptCode="Latn">latin</script>') # 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 1ff1ed4d83b3 -r 81fab457faeb test/test_schema.py
--- a/test/test_schema.py	Wed Jun 19 16:50:16 2019 +0200
+++ b/test/test_schema.py	Thu Jun 20 16:00:22 2019 +0200
@@ -108,6 +108,7 @@
             'EACResourceRelation': {('resource_relation_agent', 'subject'):
                                     set(['AuthorityRecord'])},
             'Convention': {('convention_of', 'subject'): set(['AuthorityRecord'])},
+            'LanguageDec': {('language_declaration_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