diff options
Diffstat (limited to 'entities')
-rw-r--r-- | entities/__init__.py | 4 | ||||
-rw-r--r-- | entities/basic_entity.py | 10 | ||||
-rw-r--r-- | entities/institution.py | 12 | ||||
-rw-r--r-- | entities/location.py | 50 | ||||
-rw-r--r-- | entities/person.py | 152 |
5 files changed, 114 insertions, 114 deletions
diff --git a/entities/__init__.py b/entities/__init__.py index 907ef4d..701846e 100644 --- a/entities/__init__.py +++ b/entities/__init__.py @@ -1,3 +1,3 @@ -from entities.person import Person -from entities.institution import Institution +from entities.person import Person
+from entities.institution import Institution
from entities.location import Location
\ No newline at end of file diff --git a/entities/basic_entity.py b/entities/basic_entity.py index 9181422..9e8f11b 100644 --- a/entities/basic_entity.py +++ b/entities/basic_entity.py @@ -1,5 +1,5 @@ -from libs import JsonSerializable - - -class BasicEntity(JsonSerializable): - pass +from libs import JsonSerializable
+
+
+class BasicEntity(JsonSerializable):
+ pass
diff --git a/entities/institution.py b/entities/institution.py index 4538207..6be86fc 100644 --- a/entities/institution.py +++ b/entities/institution.py @@ -1,6 +1,6 @@ -from entities.basic_entity import BasicEntity - - -class Institution(BasicEntity): - def __init__(self): - raise NotImplementedError() +from entities.basic_entity import BasicEntity
+
+
+class Institution(BasicEntity):
+ def __init__(self):
+ raise NotImplementedError()
diff --git a/entities/location.py b/entities/location.py index a43eb8d..f782e1f 100644 --- a/entities/location.py +++ b/entities/location.py @@ -1,25 +1,25 @@ -import json - -from entities.basic_entity import BasicEntity - - -class Location(BasicEntity): - def __init__(self, name, types_of_place, name_in_langs, comments_list): - self.name = name - self.types_of_place = types_of_place - self.name_in_langs = name_in_langs - self.comments_list = comments_list - - CSV_FIELDS = ["name", "comments"] - TYPE = "LOCATION" - - - def print_entity(self): - print("Name = " + self.name) - print("Name in langs = " + str(self.name_in_langs)) - print("Types = " + str(self.types_of_place)) - print("Comments = " + str(self.comments_list)) - - def to_csv_dict(self): - return {'name': self.name, - 'comments': json.dumps(self.comments_list, ensure_ascii=False)} +import json
+
+from entities.basic_entity import BasicEntity
+
+
+class Location(BasicEntity):
+ def __init__(self, name, types_of_place, name_in_langs, comments_list):
+ self.name = name
+ self.types_of_place = types_of_place
+ self.name_in_langs = name_in_langs
+ self.comments_list = comments_list
+
+ CSV_FIELDS = ["name", "comments"]
+ TYPE = "LOCATION"
+
+
+ def print_entity(self):
+ print("Name = " + self.name)
+ print("Name in langs = " + str(self.name_in_langs))
+ print("Types = " + str(self.types_of_place))
+ print("Comments = " + str(self.comments_list))
+
+ def to_csv_dict(self):
+ return {'name': self.name,
+ 'comments': json.dumps(self.comments_list, ensure_ascii=False)}
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)}
|