[PATCH eac] Add support for <languageDeclaration>

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Fri Aug 2 14:51:32 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1564500696 -7200
#      Tue Jul 30 17:31:36 2019 +0200
# Node ID ba06431cf4f74da9b74b7c5b63cf6aa043738b1c
# Parent  29a224db521a3644469c44173b2973bb398e0f12
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r ba06431cf4f7
Add support for <languageDeclaration>

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

diff -r 29a224db521a -r ba06431cf4f7 cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py	Fri Aug 02 10:20:36 2019 +0200
+++ b/cubicweb_eac/dataimport.py	Tue Jul 30 17:31:36 2019 +0200
@@ -40,7 +40,7 @@
 TYPE_MAPPING['human'] = u'person'
 
 ETYPES_ORDER_HINT = ('AgentKind', 'PhoneNumber', 'PostalAddress', 'AuthorityRecord',
-                     'Convention', 'AgentPlace', 'Mandate', 'LegalStatus',
+                     'Convention', 'LanguageDec', 'AgentPlace', 'Mandate', 'LegalStatus',
                      'History', 'HistoricalEvent', 'Structure', 'AgentFunction', 'Occupation',
                      'GeneralContext', 'AssociationRelation', 'ChronologicalRelation',
                      'HierarchicalRelation', 'EACResourceRelation', 'ExternalUri',
@@ -889,11 +889,29 @@
                                   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):
                 yield extentity
 
+    @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)
+
     def build_maintenance_event(self, elem):
         """Parse a `maintenanceEvent` tag, yielding a prov:Activity external
         entity along with necessary Records.
diff -r 29a224db521a -r ba06431cf4f7 cubicweb_eac/i18n/en.po
--- a/cubicweb_eac/i18n/en.po	Fri Aug 02 10:20:36 2019 +0200
+++ b/cubicweb_eac/i18n/en.po	Tue Jul 30 17:31:36 2019 +0200
@@ -1599,3 +1599,47 @@
 msgctxt "HierarchicalRelation"
 msgid "xml_wrap"
 msgstr ""
+
+msgid "LanguageDec"
+msgstr "language declaration"
+
+msgid "LanguageDec_plural"
+msgstr "language declarations"
+
+msgid "New LanguageDec"
+msgstr "new language declaration"
+
+msgid "This LanguageDec"
+msgstr "this language declaration"
+
+msgid "This LanguageDec:"
+msgstr "this language declaration :"
+
+msgid "language"
+msgstr ""
+
+msgid "add a LanguageDec"
+msgstr "add a language declaration"
+
+msgid "language_declaration_of"
+msgstr ""
+
+msgctxt "LanguageDec"
+msgid "language_declaration_of"
+msgstr ""
+
+msgid "language_declaration_of_object"
+msgstr ""
+
+msgctxt "AuthorityRecord"
+msgid "language_declaration_of_object"
+msgstr ""
+
+msgid ""
+"creating LanguageDec (LanguageDec language_declaration_of AuthorityRecord %(linkto)s)"
+msgstr ""
+
+msgctxt "LanguageDec"
+msgid "description"
+msgstr ""
+
diff -r 29a224db521a -r ba06431cf4f7 cubicweb_eac/i18n/fr.po
--- a/cubicweb_eac/i18n/fr.po	Fri Aug 02 10:20:36 2019 +0200
+++ b/cubicweb_eac/i18n/fr.po	Tue Jul 30 17:31:36 2019 +0200
@@ -1610,3 +1610,47 @@
 msgctxt "HierarchicalRelation"
 msgid "xml_wrap"
 msgstr ""
+
+msgid "LanguageDec"
+msgstr "langage déclaré"
+
+msgid "LanguageDec_plural"
+msgstr "langages déclarés"
+
+msgid "New LanguageDec"
+msgstr "nouveau langage déclaré"
+
+msgid "This LanguageDec"
+msgstr "ce langage déclaré"
+
+msgid "This LanguageDec:"
+msgstr "ce langage déclaré :"
+
+msgid "language"
+msgstr "langage"
+
+msgid "add a LanguageDec"
+msgstr "ajouter un language"
+
+msgid "language_declaration_of"
+msgstr "language déclaré de"
+
+msgctxt "LanguageDec"
+msgid "language_declaration_of"
+msgstr ""
+
+msgid "language_declaration_of_object"
+msgstr "language déclaré de cet objet"
+
+msgctxt "AuthorityRecord"
+msgid "language_declaration_of_object"
+msgstr "language déclaré de cette notice"
+
+msgid ""
+"creating LanguageDec (LanguageDec language_declaration_of AuthorityRecord %(linkto)s)"
+msgstr ""
+
+msgctxt "LanguageDec"
+msgid "description"
+msgstr ""
+
diff -r 29a224db521a -r ba06431cf4f7 cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py	Fri Aug 02 10:20:36 2019 +0200
+++ b/cubicweb_eac/migration/0.9.0_Any.py	Tue Jul 30 17:31:36 2019 +0200
@@ -1,3 +1,4 @@
 add_attribute('History', 'abstract')
 add_entity_type('HistoricalEvent')
 add_entity_type('Convention')
+add_entity_type('LanguageDec')
diff -r 29a224db521a -r ba06431cf4f7 cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py	Fri Aug 02 10:20:36 2019 +0200
+++ b/cubicweb_eac/schema.py	Tue Jul 30 17:31:36 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 29a224db521a -r ba06431cf4f7 test/test_dataimport.py
--- a/test/test_dataimport.py	Fri Aug 02 10:20:36 2019 +0200
+++ b/test/test_dataimport.py	Tue Jul 30 17:31:36 2019 +0200
@@ -124,10 +124,21 @@
               '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="'
+                               u'http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http:/'
+                               u'/www.w3.org/1999/xlink" languageCode="fre">français</language'
+                               u'>']),
+              'script': set([u'<script xmlns="urn:isbn:1-931666-33-4" xmlns:xsi="http://www.w3.org'
+                             u'/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/'
+                             u'xlink" scriptCode="Latn">latin</script>'])
+             },
+            ),
             ('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" '
                                   u'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
@@ -188,7 +199,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']),
              },
             ),
@@ -231,8 +242,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(),
@@ -300,7 +311,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']),
              },
             ),
@@ -313,7 +324,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']),
               }
             ),
@@ -424,7 +435,6 @@
                          {'maintenanceStatus': set([12]),
                           'publicationStatus': set([14]),
                           'maintenanceAgency': set([16]),
-                          'languageDeclaration': set([21]),
                           'localControl': set([54]),
                           'source': set([76]),  # empty.
                           'structureOrGenealogy': set([189]),  # empty.
@@ -526,7 +536,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)
@@ -569,6 +579,14 @@
                          u'Norme ISAAR(CPF) du Conseil international des archives, '
                          u'2e \xe9dition, 1996.')
 
+    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(len(rset), 1)
diff -r 29a224db521a -r ba06431cf4f7 test/test_schema.py
--- a/test/test_schema.py	Fri Aug 02 10:20:36 2019 +0200
+++ b/test/test_schema.py	Tue Jul 30 17:31:36 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'])},
             'HistoricalEvent': {('has_event', 'object'): set(['History'])},
             'GeneralContext': {('general_context_of', 'subject'): set(['AuthorityRecord'])},


More information about the saem-devel mailing list