123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- offset = 4
- relation_first_grade = {
- 'f': ['Ur-Ur-Großmutter', 'Ur-Großmutter', 'Großmutter', 'Mutter', 'ich', 'Tochter', 'Enkelin', 'Ur-Enkelin', 'Ur-Ur-Enkelin'],
- 'm': ['Ur-Ur-Großvater', 'Ur-Großvater', 'Großvater', 'Vater', 'ich', 'Sohn', 'Enkel', 'Ur-Enkel', 'Ur-Ur-Enkel']
- }
- relation_higher_grade = {
- 'f': ['Ur-Ur-Großtante', 'Ur-Großtante', 'Großtante', 'Tante', 'Cousine', 'Nichte', 'Großnichte', 'Ur-Großnichte', 'Ur-Ur-Großnichte'],
- 'm': ['Ur-Ur-Großonkel', 'Ur-Großonkel', 'Großonkel', 'Onkel', 'Cousin', 'Neffe', 'Großneffe', 'Ur-Großneffe', 'Ur-Ur-Großneffe']
- }
- def relationship_name(subject, relative, gender):
- if gender != 'm':
- gender = 'f'
- s = subject.split('.')
- r = relative.split('.')
- delta = len(r) - len(s)
- if subject.startswith(relative) or relative.startswith(subject):
- return relation_first_grade[gender][delta + offset]
- common = relationship_grade(s, r)
- min_grade = min(len(s), len(r))
- grade = min_grade - common
- if delta == 0:
- grade = grade - 1
- if grade == 0:
- return 'Bruder' if (gender == 'm') else 'Schwester'
- if grade == 1:
- return relation_higher_grade[gender][delta + offset]
- return relation_higher_grade[gender][delta + offset] + f' {grade}. Grades'
- def relationship_grade(s, r):
- min_grade = min(len(s), len(r))
- for i in range(min_grade):
- if s[i] != r[i]:
- return i
- return min_grade
- def relationship_distance(subject, relative):
- s = subject.split('.')
- r = relative.split('.')
- common = relationship_grade(s, r)
- grade = len(s) + len(r) - (2 * common)
- return grade
- def relationship_list(family_list, rel_index):
- subject = family_list[rel_index]
- result = []
- for person in family_list:
- rel_name = relationship_name(subject[1], person[1], person[2])
- rel_name2 = relationship_name(person[1], subject[1], subject[2])
- dist = relationship_distance(subject[1], person[1])
- result.append((*subject, rel_name2, *person, rel_name, dist))
- return result
- def relationship_list_all(family_list):
- result = []
- for i in range(len(family_list)):
- result.extend(relationship_list(family_list, i))
- return result
|