summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroy lewin <roy.lewin@gmail.com>2016-09-21 21:59:22 +0300
committerroy lewin <roy.lewin@gmail.com>2016-09-21 21:59:22 +0300
commit985a0fcac8b89bfe3c5bdcea0889b921cc27c033 (patch)
tree8cc9bc1fbcae35a0aab8b49e3f04c3c0843e0fdd
parent9876529cd25312ce1b92329618a81d962fb86c44 (diff)
Added basic entities
-rw-r--r--.idea/lib2wiki.iml11
-rw-r--r--.idea/misc.xml4
-rw-r--r--.idea/modules.xml8
-rw-r--r--entities/__init__.py3
-rw-r--r--entities/basic_entity.py5
-rw-r--r--entities/institution.py6
-rw-r--r--entities/location.py8
-rw-r--r--entities/person.py18
-rw-r--r--factories/INL_factory.py23
-rw-r--r--factories/__init__.py2
-rw-r--r--factories/basic_factory.py3
-rw-r--r--libs/__init__.py1
-rw-r--r--libs/json_tools.py6
-rw-r--r--parsers/basic_parser.py8
14 files changed, 102 insertions, 4 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$" />
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+ <component name="TestRunnerService">
+ <option name="PROJECT_TEST_RUNNER" value="Unittests" />
+ </component>
+</module> \ 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.10 (C:\Python27\python.exe)" project-jdk-type="Python SDK" />
+</project> \ 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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/lib2wiki.iml" filepath="$PROJECT_DIR$/.idea/lib2wiki.iml" />
+ </modules>
+ </component>
+</project> \ 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)))