[PATCH eac] Add `family` relations support in cpfrelations

Katia Saurfelt katia.saurfelt at logilab.fr
Mon Sep 2 15:47:01 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1565282779 -7200
#      Thu Aug 08 18:46:19 2019 +0200
# Node ID 529f93fa0fee289de55b2c6fea3639a049725107
# Parent  c02eb8b8c97d049e3482ceb704a7fc527006425f
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 529f93fa0fee
Add `family` relations support in cpfrelations

diff --git a/cubicweb_eac/dataimport.py b/cubicweb_eac/dataimport.py
--- a/cubicweb_eac/dataimport.py
+++ b/cubicweb_eac/dataimport.py
@@ -47,7 +47,8 @@ ETYPES_ORDER_HINT = ('AgentKind', 'Phone
                      'AgentFunction', 'Occupation', 'GeneralContext', 'AssociationRelation',
                      'ChronologicalRelation', 'HierarchicalRelation', 'EACResourceRelation',
                      'EACFunctionRelation', 'ParallelNames', 'ExternalUri', 'EACSource',
-                     'Activity', 'EACOtherRecordId', 'NameEntry', 'IdentityRelation')
+                     'Activity', 'EACOtherRecordId', 'NameEntry', 'IdentityRelation',
+                     'FamilyRelation')
 
 
 class InvalidEAC(RuntimeError):
@@ -915,15 +916,18 @@ class EACCPFImporter(object):
                     yield extentity
 
     @add_xml_wrap_for('AssociationRelation', 'ChronologicalRelation',
-                      'HierarchicalRelation', 'IdentityRelation')
+                      'HierarchicalRelation', 'IdentityRelation',
+                      'FamilyRelation')
     @add_dates_for('AssociationRelation')
     @add_dates_for('ChronologicalRelation')
     @add_dates_for('HierarchicalRelation')
     @add_dates_for('IdentityRelation')
+    @add_dates_for('FamilyRelation')
     @add_place_entries_for('AssociationRelation')
     @add_place_entries_for('ChronologicalRelation')
     @add_place_entries_for('HierarchicalRelation')
     @add_place_entries_for('IdentityRelation')
+    @add_place_entries_for('FamilyRelation')
     def build_relation(self, elem):
         """Build a relation between records external entity (with proper type)."""
         relationship = elem.attrib.get('cpfRelationType')
@@ -956,6 +960,8 @@ class EACCPFImporter(object):
                                 'association_to', 'association_from'),
                 'identity': ('IdentityRelation',
                              'identity_to', 'identity_from'),
+                'family': ('FamilyRelation',
+                           'family_to', 'family_from')
             }[relationship]
         except KeyError:
             self.import_log.record_warning(self._(
diff --git a/cubicweb_eac/entities.py b/cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py
+++ b/cubicweb_eac/entities.py
@@ -125,6 +125,18 @@ class HierarchicalRelation(_Relation):
         return self.hierarchical_child[0]
 
 
+class FamilyRelation(_Relation):
+    __regid__ = 'FamilyRelation'
+
+    @property
+    def subject(self):
+        return self.family_from[0]
+
+    @property
+    def object(self):
+        return self.family_to[0]
+
+
 class IdentityRelation(_Relation):
     __regid__ = 'IdentityRelation'
 
diff --git a/cubicweb_eac/hooks.py b/cubicweb_eac/hooks.py
--- a/cubicweb_eac/hooks.py
+++ b/cubicweb_eac/hooks.py
@@ -42,6 +42,8 @@ class DeleteTernaryRelationsHook(hook.Ho
             'chronological_successor',
             'hierarchical_parent',
             'hierarchical_child',
+            'family_from',
+            'family_to',
             'identity_from',
             'identity_to'
         ):
diff --git a/cubicweb_eac/migration/0.9.0_Any.py b/cubicweb_eac/migration/0.9.0_Any.py
--- a/cubicweb_eac/migration/0.9.0_Any.py
+++ b/cubicweb_eac/migration/0.9.0_Any.py
@@ -5,6 +5,7 @@ add_entity_type('EACFunctionRelation')
 add_entity_type('DateEntity')
 add_entity_type('PlaceEntry')
 add_entity_type('IdentityRelation')
+add_entity_type('FamilyRelation')
 
 # Attributes to update
 add_attribute('EACResourceRelation', 'xml_attributes')
diff --git a/cubicweb_eac/schema.py b/cubicweb_eac/schema.py
--- a/cubicweb_eac/schema.py
+++ b/cubicweb_eac/schema.py
@@ -119,7 +119,7 @@ class date_relation(RelationDefinition):
                'ChronologicalRelation', 'AssociationRelation',
                'AgentFunction', 'EACFunctionRelation', 'LegalStatus',
                'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation',
-               'NameEntry', 'IdentityRelation')
+               'NameEntry', 'IdentityRelation', 'FamilyRelation')
     object = 'DateEntity'
     cardinality = '*1'
     composite = 'subject'
@@ -138,7 +138,7 @@ class place_entry_relation(RelationDefin
                'ChronologicalRelation', 'AssociationRelation',
                'AgentFunction', 'EACFunctionRelation', 'LegalStatus',
                'Mandate', 'Occupation', 'AgentPlace', 'EACResourceRelation',
-               'IdentityRelation')
+               'IdentityRelation', 'FamilyRelation')
     object = 'PlaceEntry'
     cardinality = '*1'
     composite = 'subject'
@@ -262,6 +262,21 @@ class _agent_relation(RelationDefinition
 
 
 @xml_wrap
+class FamilyRelation(EntityType):
+    """Family relation between authority records"""
+    entry = String()
+    description = RichString()
+
+
+class family_from(_agent_relation):
+    subject = 'FamilyRelation'
+
+
+class family_to(_agent_relation):
+    subject = 'FamilyRelation'
+
+
+ at xml_wrap
 class IdentityRelation(EntityType):
     """Identity relation between authority records"""
     entry = String()
diff --git a/test/data/FRAD033_EAC_00001_simplified.xml b/test/data/FRAD033_EAC_00001_simplified.xml
--- a/test/data/FRAD033_EAC_00001_simplified.xml
+++ b/test/data/FRAD033_EAC_00001_simplified.xml
@@ -346,6 +346,14 @@
           <objectXMLWrap><gloups>hips</gloups></objectXMLWrap>
 	</cpfRelation>
 
+      <cpfRelation cpfRelationType="family" xlink:href="whatever" xlink:type="simple">
+          <relationEntry>CG32</relationEntry>
+          <dateRange>
+              <fromDate standardDate="1917">1917</fromDate>
+              <toDate standardDate="2009">2009</toDate>
+          </dateRange>
+      </cpfRelation>
+
       <cpfRelation cpfRelationType="associative" xlink:href="agent-x" xlink:type="simple"></cpfRelation>
       <resourceRelation resourceRelationType="creatorOf"
         xmlns:xlink="http://www.w3.org/1999/xlink" 
diff --git a/test/test_dataimport.py b/test/test_dataimport.py
--- a/test/test_dataimport.py
+++ b/test/test_dataimport.py
@@ -478,6 +478,16 @@ class EACXMLParserTC(unittest.TestCase):
             ('DateEntity', _gen_extid(),
              {'start_date': [datetime.date(2042, 1, 1)]}
             ),
+            ('FamilyRelation', _gen_extid(),
+             {'date_relation': ['57'],
+              'entry': [u'CG32'],
+              'family_from': ['authorityrecord-FRAD033_EAC_00001'],
+              'family_to': ['whatever']}
+            ),
+            ('DateEntity', _gen_extid(),
+             {'end_date': [datetime.date(2009, 1, 1)],
+              'start_date': [datetime.date(1917, 1, 1)]}
+            ),
             ('AssociationRelation', _gen_extid(),
              {'association_from': set(['authorityrecord-FRAD033_EAC_00001']),
               'association_to': set(['agent-x']),
@@ -485,7 +495,7 @@ class EACXMLParserTC(unittest.TestCase):
              ),
             ('EACResourceRelation', _gen_extid(),
              {'agent_role': set([u'creatorOf']),
-              'date_relation': set(['58']),
+              'date_relation': set(['60']),
               '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"}']),
@@ -547,7 +557,7 @@ class EACXMLParserTC(unittest.TestCase):
                                   'and abolishment of schools.\n\t  </p>']),
               'r_type': set([u'controls']),
               'description_format': set([u'text/html']),
-              'date_relation': set(['61']),
+              'date_relation': set(['63']),
               'relation_entry': set([u'Establishment and abolishment\n\tof schools\n\t']),
               'xml_attributes': set([u'{}'])
               },



More information about the saem-devel mailing list