summaryrefslogtreecommitdiff
path: root/entities/person.py
blob: b315aac99cab905cfc94bd203cd2545a17c7cbc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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)}