|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
import unittest |
|
4
|
|
|
from processors import * |
|
5
|
|
|
import os |
|
6
|
|
|
|
|
7
|
|
|
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) |
|
8
|
|
|
|
|
9
|
|
|
class SerializationTests(unittest.TestCase): |
|
10
|
|
|
|
|
11
|
|
|
def test_doc_load_from_json(self): |
|
12
|
|
|
"Document.load_from_JSON should produce a Document from serialized_doc.json" |
|
13
|
|
|
json_file = os.path.join(__location__, "serialized_doc.json") |
|
14
|
|
|
print(json_file) |
|
15
|
|
|
with open(json_file, "r") as jf: |
|
16
|
|
|
doc = Document.load_from_JSON(json.load(jf)) |
|
|
|
|
|
|
17
|
|
|
self.assertTrue(isinstance(doc, Document), "Document.load_from_JSON did not produce a Document from {}".format(json_file)) |
|
18
|
|
|
|
|
19
|
|
|
def test_sentence_load_from_json(self): |
|
20
|
|
|
"Sentence.load_from_JSON should produce a Sentence from serialized_sentence.json" |
|
21
|
|
|
json_file = os.path.join(__location__, "serialized_sentence.json") |
|
22
|
|
|
print(json_file) |
|
23
|
|
|
with open(json_file, "r") as jf: |
|
24
|
|
|
s = Sentence.load_from_JSON(json.load(jf)) |
|
|
|
|
|
|
25
|
|
|
self.assertTrue(isinstance(s, Sentence), "Sentence.load_from_JSON did not produce a Sentence from {}".format(json_file)) |
|
26
|
|
|
|
|
27
|
|
|
def test_mention_load_from_json(self): |
|
28
|
|
|
"JSONSerializer.load_from_JSON should produce a Mention from serialized_mention.json" |
|
29
|
|
|
json_file = os.path.join(__location__, "serialized_mention.json") |
|
30
|
|
|
print(json_file) |
|
31
|
|
|
with open(json_file, "r") as jf: |
|
32
|
|
|
mentions = JSONSerializer.mentions_from_JSON(json.load(jf)) |
|
|
|
|
|
|
33
|
|
|
self.assertTrue(len(mentions) == 1, "More than one mention found for text.") |
|
34
|
|
|
m = mentions[0] |
|
35
|
|
|
self.assertTrue(isinstance(m, Mention), "JSONSerializer.load_from_JSON did not produce a Mention from {}".format(json_file)) |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
if __name__ == "__main__": |
|
38
|
|
|
unittest.main() |
|
39
|
|
|
|