From 985a0fcac8b89bfe3c5bdcea0889b921cc27c033 Mon Sep 17 00:00:00 2001 From: roy lewin Date: Wed, 21 Sep 2016 21:59:22 +0300 Subject: Added basic entities --- .idea/lib2wiki.iml | 11 +++++++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ entities/__init__.py | 3 +++ entities/basic_entity.py | 5 +++++ entities/institution.py | 6 ++++++ entities/location.py | 8 ++++++++ entities/person.py | 18 ++++++++++++++++++ factories/INL_factory.py | 23 +++++++++++++++++++++++ factories/__init__.py | 2 ++ factories/basic_factory.py | 3 +++ libs/__init__.py | 1 + libs/json_tools.py | 6 ++++++ parsers/basic_parser.py | 8 ++++---- 14 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 .idea/lib2wiki.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 entities/basic_entity.py create mode 100644 entities/institution.py create mode 100644 entities/location.py create mode 100644 entities/person.py create mode 100644 factories/INL_factory.py create mode 100644 factories/__init__.py create mode 100644 factories/basic_factory.py create mode 100644 libs/__init__.py create mode 100644 libs/json_tools.py diff --git a/.idea/lib2wiki.iml b/.idea/lib2wiki.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/lib2wiki.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..de9bbc8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9a7bd2d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/entities/__init__.py b/entities/__init__.py index e69de29..48f64d6 100644 --- a/entities/__init__.py +++ b/entities/__init__.py @@ -0,0 +1,3 @@ +from person import Person +from institution import Institution +from location import Location \ No newline at end of file diff --git a/entities/basic_entity.py b/entities/basic_entity.py new file mode 100644 index 0000000..9181422 --- /dev/null +++ b/entities/basic_entity.py @@ -0,0 +1,5 @@ +from libs import JsonSerializable + + +class BasicEntity(JsonSerializable): + pass diff --git a/entities/institution.py b/entities/institution.py new file mode 100644 index 0000000..4538207 --- /dev/null +++ b/entities/institution.py @@ -0,0 +1,6 @@ +from entities.basic_entity import BasicEntity + + +class Institution(BasicEntity): + def __init__(self): + raise NotImplementedError() diff --git a/entities/location.py b/entities/location.py new file mode 100644 index 0000000..8130632 --- /dev/null +++ b/entities/location.py @@ -0,0 +1,8 @@ +from entities.basic_entity import BasicEntity + + +class Location(BasicEntity): + def __init__(self, name, types, coordinates): + self.name = name + self.types = types + self.coordinates = coordinates diff --git a/entities/person.py b/entities/person.py new file mode 100644 index 0000000..b9e9d78 --- /dev/null +++ b/entities/person.py @@ -0,0 +1,18 @@ +from entities.basic_entity import BasicEntity + + +class Person(BasicEntity): + def __init__(self, name, date_of_birth, name_in_langs): + """ + + :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 + self.date_of_birth = date_of_birth + self.name_in_langs = name_in_langs diff --git a/factories/INL_factory.py b/factories/INL_factory.py new file mode 100644 index 0000000..6607368 --- /dev/null +++ b/factories/INL_factory.py @@ -0,0 +1,23 @@ +import entities +from factories import BasicFactory + +TAG_TO_ENTITY_MAPPING = { + '100': entities.Person, + '110': entities.Institution, + '151': entities.Location +} + + +class INLFactory(BasicFactory): + def __init__(self, tag_to_entity_mapping=None): + self.mapping = tag_to_entity_mapping or TAG_TO_ENTITY_MAPPING + + def get_entity(self, entity_key, raw_object): + if entity_key == '100': + return entities.Person('', '', '') + elif entity_key == '110': + return entities.Institution() + elif entity_key == '151': + return entities.Location('', '', '') + else: + raise KeyError('Key {} was not recognized for factory {}'.format(entity_key, type(self))) diff --git a/factories/__init__.py b/factories/__init__.py new file mode 100644 index 0000000..add236d --- /dev/null +++ b/factories/__init__.py @@ -0,0 +1,2 @@ +from basic_factory import BasicFactory +from INL_factory import INLFactory \ No newline at end of file diff --git a/factories/basic_factory.py b/factories/basic_factory.py new file mode 100644 index 0000000..1715846 --- /dev/null +++ b/factories/basic_factory.py @@ -0,0 +1,3 @@ +class BasicFactory(object): + def get_entity(self, entity_key, raw_object): + raise NotImplementedError("get_entity() method must be implemented class {}".format(type(self))) diff --git a/libs/__init__.py b/libs/__init__.py new file mode 100644 index 0000000..5e2ded0 --- /dev/null +++ b/libs/__init__.py @@ -0,0 +1 @@ +from json_tools import JsonSerializable \ No newline at end of file diff --git a/libs/json_tools.py b/libs/json_tools.py new file mode 100644 index 0000000..6354531 --- /dev/null +++ b/libs/json_tools.py @@ -0,0 +1,6 @@ +import json + + +class JsonSerializable(object): + def __repr__(self): + return json.dumps(self.__dict__) diff --git a/parsers/basic_parser.py b/parsers/basic_parser.py index e050113..dae19cb 100644 --- a/parsers/basic_parser.py +++ b/parsers/basic_parser.py @@ -1,6 +1,6 @@ class BasicParser(object): - def __init__(self): - pass + def __init__(self): + pass - def parse(self, data): - raise NotImplementedError("parse() method must be implemented class {}".format(type(self))) \ No newline at end of file + def parse(self, data): + raise NotImplementedError("parse() method must be implemented class {}".format(type(self))) -- cgit v1.2.3