summaryrefslogtreecommitdiff
path: root/entities/person.py
diff options
context:
space:
mode:
Diffstat (limited to 'entities/person.py')
-rw-r--r--entities/person.py152
1 files changed, 76 insertions, 76 deletions
diff --git a/entities/person.py b/entities/person.py
index b315aac..a5aa396 100644
--- a/entities/person.py
+++ b/entities/person.py
@@ -1,76 +1,76 @@
-import json
-
-from entities.basic_entity import BasicEntity
-
-
-class Person(BasicEntity):
- def __init__(self, name, date_of_birth, name_in_langs, bio_data, comments_list, profession):
- """
-
- :param name:
- :param date_of_birth:
- :param name_in_langs: Mapping of the persons's name in various languages, as a dictionary. For example:
- {
- "latin": "George"
- "heb": "[george in hebrew]"
- }
- """
- self.name = name
- years_parts = date_of_birth.split('-')
- if (len(years_parts) == 2):
- self.birth_year = years_parts[0]
- self.death_year = years_parts[1]
- else:
- self.birth_year = date_of_birth.strip()
- self.death_year = ''
- self.name_in_langs = name_in_langs
- '''
- place_of_birth = list()
- place_of_death = list()
- profession = list()
- for comment in bio_data:
- encoded_comment = ''.join(comment).strip()
- if encoded_comment.startswith(u"מקום לידה: "):
- place_of_birth.append(encoded_comment.partition(u"מקום לידה: ")[2])
- if encoded_comment.startswith(u"מקום פטירה: "):
- place_of_death.append(encoded_comment.partition(u"מקום פטירה: ")[2])
- if encoded_comment.startswith(u"מקצוע: "):
- profession.append(encoded_comment.partition(u"מקום פטירה: ")[2])
-
- self.place_of_birth = place_of_birth
- self.place_of_death = place_of_death
- self.profession = profession
- '''
- bio_data_dict = dict()
- for elem in bio_data:
- elem_splitted = elem.split(":")
- if len(elem_splitted) == 2:
- bio_data_key = elem_splitted[0]
- bio_data_value = elem_splitted[1]
- if bio_data_key in bio_data_dict:
- bio_data_dict.get(bio_data_key).append(bio_data_value)
- else:
- bio_data_dict.update(
- {bio_data_key: [bio_data_value]}
- )
- else:
- bio_data_dict.update({elem: ''})
- self.bio_data = bio_data_dict
- self.comments_list = comments_list
- self.profession = profession
-
- CSV_FIELDS = ["name", "biodata", "comments"]
- TYPE = 'PERSON'
-
- def print_entity(self):
- print("Name = " + self.name)
- print("Birth year = " + self.birth_year)
- print("Death year = " + self.death_year)
- print("Names in langs = " + str(self.name_in_langs))
- print("Bio Data = " + str(self.bio_data))
- print("Comments = " + str(self.comments_list))
- print("Profession = " + str(self.profession))
-
- def to_csv_dict(self):
- return {'name': self.name, 'biodata': self.bio_data,
- 'comments': json.dumps(self.comments_list, ensure_ascii=False)}
+import json
+
+from entities.basic_entity import BasicEntity
+
+
+class Person(BasicEntity):
+ def __init__(self, name, date_of_birth, name_in_langs, bio_data, comments_list, profession):
+ """
+
+ :param name:
+ :param date_of_birth:
+ :param name_in_langs: Mapping of the persons's name in various languages, as a dictionary. For example:
+ {
+ "latin": "George"
+ "heb": "[george in hebrew]"
+ }
+ """
+ self.name = name
+ years_parts = date_of_birth.split('-')
+ if (len(years_parts) == 2):
+ self.birth_year = years_parts[0]
+ self.death_year = years_parts[1]
+ else:
+ self.birth_year = date_of_birth.strip()
+ self.death_year = ''
+ self.name_in_langs = name_in_langs
+ '''
+ place_of_birth = list()
+ place_of_death = list()
+ profession = list()
+ for comment in bio_data:
+ encoded_comment = ''.join(comment).strip()
+ if encoded_comment.startswith(u"מקום לידה: "):
+ place_of_birth.append(encoded_comment.partition(u"מקום לידה: ")[2])
+ if encoded_comment.startswith(u"מקום פטירה: "):
+ place_of_death.append(encoded_comment.partition(u"מקום פטירה: ")[2])
+ if encoded_comment.startswith(u"מקצוע: "):
+ profession.append(encoded_comment.partition(u"מקום פטירה: ")[2])
+
+ self.place_of_birth = place_of_birth
+ self.place_of_death = place_of_death
+ self.profession = profession
+ '''
+ bio_data_dict = dict()
+ for elem in bio_data:
+ elem_splitted = elem.split(":")
+ if len(elem_splitted) == 2:
+ bio_data_key = elem_splitted[0]
+ bio_data_value = elem_splitted[1]
+ if bio_data_key in bio_data_dict:
+ bio_data_dict.get(bio_data_key).append(bio_data_value)
+ else:
+ bio_data_dict.update(
+ {bio_data_key: [bio_data_value]}
+ )
+ else:
+ bio_data_dict.update({elem: ''})
+ self.bio_data = bio_data_dict
+ self.comments_list = comments_list
+ self.profession = profession
+
+ CSV_FIELDS = ["name", "biodata", "comments"]
+ TYPE = 'PERSON'
+
+ def print_entity(self):
+ print("Name = " + self.name)
+ print("Birth year = " + self.birth_year)
+ print("Death year = " + self.death_year)
+ print("Names in langs = " + str(self.name_in_langs))
+ print("Bio Data = " + str(self.bio_data))
+ print("Comments = " + str(self.comments_list))
+ print("Profession = " + str(self.profession))
+
+ def to_csv_dict(self):
+ return {'name': self.name, 'biodata': self.bio_data,
+ 'comments': json.dumps(self.comments_list, ensure_ascii=False)}