跳转至

Paper

labridge.func_modules.reference.paper

labridge.func_modules.reference.paper.PaperInfo

Bases: RefInfoBase

This class contains the information of a paper, including:

PARAMETER DESCRIPTION
title

The title of the paper.

TYPE: str

file_path

The file path of the paper.

TYPE: str

possessor

The user that possesses the paper.

TYPE: str

Source code in labridge\func_modules\reference\paper.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class PaperInfo(RefInfoBase):
	r"""
	This class contains the information of a paper, including:

	Args:
		title (str): The title of the paper.
		file_path (str): The file path of the paper.
		possessor (str): The user that possesses the paper.
	"""
	def __init__(
		self,
		title: str,
		file_path: str,
		possessor: str,
		doi: str = None,
	):
		self.title = title
		self.possessor = possessor
		self.doi = doi
		super().__init__(ref_file_path=file_path)

	def dumps(self) -> str:
		r""" Dump to a string in JSON format. """
		info_dict = {
			REF_TYPE: PaperInfo.__name__,
			"title": self.title,
			REF_INFO_FILE_PATH_KEY: self.ref_file_path,
			"possessor": self.possessor,
			"doi": self.doi,
		}
		return json.dumps(info_dict)

	@classmethod
	def loads(cls, info_str: str):
		r""" Load from a string in JSON format. """
		try:
			info_dict = json.loads(info_str)
			title = info_dict["title"]
			ref_file_path = info_dict[REF_INFO_FILE_PATH_KEY]
			possessor = info_dict["possessor"]
			doi = info_dict["doi"]
			return cls(
				title=title,
				file_path=ref_file_path,
				possessor=possessor,
				doi=doi,
			)
		except Exception:
			raise ValueError("Invalid paper info string.")

labridge.func_modules.reference.paper.PaperInfo.dumps()

Dump to a string in JSON format.

Source code in labridge\func_modules\reference\paper.py
27
28
29
30
31
32
33
34
35
36
def dumps(self) -> str:
	r""" Dump to a string in JSON format. """
	info_dict = {
		REF_TYPE: PaperInfo.__name__,
		"title": self.title,
		REF_INFO_FILE_PATH_KEY: self.ref_file_path,
		"possessor": self.possessor,
		"doi": self.doi,
	}
	return json.dumps(info_dict)

labridge.func_modules.reference.paper.PaperInfo.loads(info_str) classmethod

Load from a string in JSON format.

Source code in labridge\func_modules\reference\paper.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@classmethod
def loads(cls, info_str: str):
	r""" Load from a string in JSON format. """
	try:
		info_dict = json.loads(info_str)
		title = info_dict["title"]
		ref_file_path = info_dict[REF_INFO_FILE_PATH_KEY]
		possessor = info_dict["possessor"]
		doi = info_dict["doi"]
		return cls(
			title=title,
			file_path=ref_file_path,
			possessor=possessor,
			doi=doi,
		)
	except Exception:
		raise ValueError("Invalid paper info string.")