def from_json(json_filename, from_annotated=False): paper = Paper('', '', None, []) datas = [] with io.open(json_filename, mode='rt', encoding='utf8') as json_file: for line in json_file: try: data = json.loads(line.strip()) datas.append(data) except Exception as e: print(line) continue if len(datas) == 0: return None data = datas[-1] #print data # Read required fields. assert 'title' in data assert 'abstract' in data paper.TITLE = data['title'] paper.ABSTRACT = data['abstract'] if 'id' in data: if data['id'] == "": paper.ID = json_filename.split("/")[-1].split(".")[0] else: paper.ID = data['id'] else: paper.ID = json_filename.split("/")[-1].split(".")[0] # Read optional fields. paper.AUTHORS = data['authors'] if 'authors' in data else None paper.CONFERENCE = data['conference'] if 'conference' in data else None paper.ACCEPTED = data['accepted'] if 'accepted' in data else None paper.SCORE = data['score'] if 'score' in data else None paper.PUBLICATION_TYPE = data[ 'publication_type'] if 'publication_type' in data else None paper.SCIENCEPARSE = data[ 'scienceparse'] if 'scienceparse' in data else None paper.KEYWORDS = data['keywords'] if 'keywords' in data else None paper.AUTHOR_EMAILS = data[ 'author_emails'] if 'author_emails' in data else None paper.DATE_OF_SUBMISSION = data[ 'DATE_OF_SUBMISSION'] if 'DATE_OF_SUBMISSION' in data else None paper.SUBJECTS = data['SUBJECTS'] if 'SUBJECTS' in data else None paper.COMMENTS = data['COMMENTS'] if 'COMMENTS' in data else None paper.VERSION = data['VERSION'] if 'VERSION' in data else None paper.HISTORIES = data['histories'] if 'histories' in data else None # Read reviews (mandatory). assert 'reviews' in data for review_data in data['reviews']: review = Review.from_json_object(review_data) paper.REVIEWS.append(review) return paper
def from_softconf_dump(json_file, conference=None): with io.open(json_file, "r", encoding="utf8") as ifh: json_str = ifh.read() # print (json_str) json_data = json.loads(json_str)["submissions"] papers = [] for i in range(len(json_data)): reviews = [] for k in range(len(json_data[i]["reviews"])): # print(json_data[i]["reviews"][k]) review_data = [] review = Review.from_json_object( json_data[i]["reviews"][k], k == i == 0) #review = None reviews.append(review) authors = json_data[i]["authors"] if "authors" in json_data[i] else None score = json_data[i]["score"] if "score" in json_data[i] else None accepted = json_data[i]["accepted"] if "accepted" in json_data[i] else None publication_type = json_data[i]["publication_type"] if "publication_type" in json_data[i] else None keywords = json_data[i]["KEYWORDS"] if "KEYWORDS" in json_data[i] else None author_emails = json_data[i]["AUTHOR_EMAILS"] if "AUTHOR_EMAILS" in json_data[i] else None date_of_submission = json_data[i]["DATE_OF_SUBMISSION"] if "DATE_OF_SUBMISSION" in json_data[i] else None paper = Paper( json_data[i]["title"], json_data[i]["abstract"], json_data[i]["id"], reviews, authors, conference, accepted, score, publication_type, None, keywords, author_emails, date_of_submission) papers.append(paper) # break return papers