def test_iter_subjects(self): with open(self.subject_data_file, 'r') as inputfile, open(self.subject_file, 'r') as dumpf: subjects = list(ggsipu_result.iter_subjects(inputfile.read())) json_dump = ggsipu_result.toJSON(subjects) self.assertEqual(json_dump, dumpf.read())
import ggsipu_result FILE = "document1.pdf" with open('subj_dump.json', 'a') as fs, open('res_dump.json', 'a') as fr: for page in ggsipu_result.iter_pages(FILE): if ggsipu_result.has_page_results(page): results = list(ggsipu_result.iter_results(page)) fr.write(ggsipu_result.toJSON(results)) elif ggsipu_result.has_page_subejcts(page): subjects = list(ggsipu_result.iter_subjects(page)) fs.write(ggsipu_result.toJSON(subjects))
def test_iter_subjects(self): with open(self.subject_data_file, "r") as inputfile, open(self.subject_file, "r") as dump_f: subjects = list(ggsipu_result.iter_subjects(inputfile.read())) json_dump = ggsipu_result.toJSON(subjects) assert json_dump == dump_f.read()
import ggsipu_result import os CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) PROJECT_ROOT = os.path.dirname(CURRENT_DIR) RESOURCE_ROOT = os.path.join(PROJECT_ROOT, "Resources") SUBJ_TXT = os.path.join(RESOURCE_ROOT, "CSE_Result", "1.txt") RES_TXT = os.path.join(RESOURCE_ROOT, "CSE_Result", "58.txt") with open(os.path.join(RESOURCE_ROOT, "subjects.json"), "w") as subj_f, open( SUBJ_TXT, "r" ) as inputfile: inputdata = inputfile.read() if ggsipu_result.has_page_subjects(inputdata): subjects = list(ggsipu_result.iter_subjects(inputdata)) subj_f.write(ggsipu_result.toJSON(subjects)) with open(os.path.join(RESOURCE_ROOT, "results.json"), "w") as res_f, open( RES_TXT, "r" ) as inputfile: inputdata = inputfile.read() if ggsipu_result.has_page_results(inputdata): results = list(ggsipu_result.iter_results(inputdata)) res_f.write(ggsipu_result.toJSON(results))