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