pyeasyphd 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyeasyphd might be problematic. Click here for more details.
- pyeasyphd/.python-version +1 -0
- pyeasyphd/Main.sublime-menu +43 -0
- pyeasyphd/__init__.py +0 -0
- pyeasyphd/bib/__init__.py +1 -0
- pyeasyphd/bib/bibtexbase/__init__.py +7 -0
- pyeasyphd/bib/bibtexbase/standardize/_base.py +36 -0
- pyeasyphd/bib/bibtexbase/standardize/default_data.py +97 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_bib.py +54 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_comment_block.py +38 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_entry_block.py +310 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_preamble_block.py +35 -0
- pyeasyphd/bib/bibtexbase/standardize/do_on_string_block.py +34 -0
- pyeasyphd/bib/bibtexbase/standardize_bib.py +75 -0
- pyeasyphd/bib/bibtexparser/__init__.py +47 -0
- pyeasyphd/bib/bibtexparser/bibtex_format.py +87 -0
- pyeasyphd/bib/bibtexparser/exceptions.py +64 -0
- pyeasyphd/bib/bibtexparser/library.py +207 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/add.py +94 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/authors.py +22 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/doi_url.py +62 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_normalize.py +47 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_replace.py +31 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_values_normalize.py +222 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_delete.py +34 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_keep.py +33 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_sort.py +70 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/entry_types.py +15 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/journal_booktitle.py +113 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/month_year.py +34 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/number_volume.py +21 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/pages.py +28 -0
- pyeasyphd/bib/bibtexparser/middlewares/block/title.py +20 -0
- pyeasyphd/bib/bibtexparser/middlewares/library/generating_entrykeys.py +98 -0
- pyeasyphd/bib/bibtexparser/middlewares/library/keeping_blocks.py +29 -0
- pyeasyphd/bib/bibtexparser/middlewares/library/sorting_blocks.py +124 -0
- pyeasyphd/bib/bibtexparser/middlewares/middleware.py +222 -0
- pyeasyphd/bib/bibtexparser/middlewares/parsestack.py +13 -0
- pyeasyphd/bib/bibtexparser/middlewares/utils.py +226 -0
- pyeasyphd/bib/bibtexparser/middlewares_library_to_library.py +414 -0
- pyeasyphd/bib/bibtexparser/middlewares_library_to_str.py +42 -0
- pyeasyphd/bib/bibtexparser/middlewares_str_to_library.py +35 -0
- pyeasyphd/bib/bibtexparser/middlewares_str_to_str.py +29 -0
- pyeasyphd/bib/bibtexparser/model.py +481 -0
- pyeasyphd/bib/bibtexparser/splitter.py +151 -0
- pyeasyphd/bib/core/__init__.py +18 -0
- pyeasyphd/bib/core/convert_library_to_library.py +31 -0
- pyeasyphd/bib/core/convert_library_to_str.py +199 -0
- pyeasyphd/bib/core/convert_str_to_library.py +34 -0
- pyeasyphd/bib/core/convert_str_to_str.py +27 -0
- pyeasyphd/main/__init__.py +17 -0
- pyeasyphd/main/basic_input.py +149 -0
- pyeasyphd/main/pandoc_md_to.py +361 -0
- pyeasyphd/main/python_run_bib.py +73 -0
- pyeasyphd/main/python_run_md.py +235 -0
- pyeasyphd/main/python_run_tex.py +149 -0
- pyeasyphd/main/python_writers.py +212 -0
- pyeasyphd/pyeasyphd.py +72 -0
- pyeasyphd/pyeasyphd.sublime-settings +235 -0
- pyeasyphd/pyeasyphd.sublime-syntax +5 -0
- pyeasyphd/tools/__init__.py +30 -0
- pyeasyphd/tools/compare/compare_bibs.py +234 -0
- pyeasyphd/tools/experiments_base.py +203 -0
- pyeasyphd/tools/format_save_bibs.py +178 -0
- pyeasyphd/tools/generate/generate_from_bibs.py +447 -0
- pyeasyphd/tools/generate/generate_links.py +356 -0
- pyeasyphd/tools/py_run_bib_md_tex.py +378 -0
- pyeasyphd/tools/replace/replace.py +81 -0
- pyeasyphd/tools/search/data.py +318 -0
- pyeasyphd/tools/search/search_base.py +118 -0
- pyeasyphd/tools/search/search_core.py +326 -0
- pyeasyphd/tools/search/search_keywords.py +227 -0
- pyeasyphd/tools/search/search_writers.py +288 -0
- pyeasyphd/tools/search/utils.py +152 -0
- pyeasyphd/tools/spider/process_spider_bib.py +247 -0
- pyeasyphd/tools/spider/process_spider_url.py +74 -0
- pyeasyphd/tools/spider/process_spider_url_bib.py +62 -0
- pyeasyphd/utils/utils.py +62 -0
- pyeasyphd-0.0.2.dist-info/METADATA +27 -0
- pyeasyphd-0.0.2.dist-info/RECORD +80 -0
- pyeasyphd-0.0.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Initialization.
|
|
2
|
+
|
|
3
|
+
This submodule incorporates modified source code from the python-bibtexparser project
|
|
4
|
+
(https://github.com/sciunto-org/python-bibtexparser), which is licensed under the MIT License.
|
|
5
|
+
The original copyright notice and license terms have been preserved in accordance with the license requirements.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"ConvertStrToStr",
|
|
10
|
+
"ConvertStrToLibrary",
|
|
11
|
+
"ConvertLibrayToLibrary",
|
|
12
|
+
"ConvertLibrayToStr",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
from .convert_library_to_library import ConvertLibrayToLibrary
|
|
16
|
+
from .convert_library_to_str import ConvertLibrayToStr
|
|
17
|
+
from .convert_str_to_library import ConvertStrToLibrary
|
|
18
|
+
from .convert_str_to_str import ConvertStrToStr
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Any, Dict, Tuple
|
|
2
|
+
|
|
3
|
+
from ..bibtexparser import Library, MiddlewaresLibraryToLibrary
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ConvertLibrayToLibrary(object):
|
|
7
|
+
"""Convert library to library.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
options (Dict[str, Any]): Options. Default is {}.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
choose_abbr_zotero_save (str): Choose "abbr", "zotero", or "save". Default is "save".
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, options: Dict[str, Any] = {}) -> None:
|
|
17
|
+
|
|
18
|
+
self.choose_abbr_zotero_save = options.get("choose_abbr_zotero_save", "save")
|
|
19
|
+
|
|
20
|
+
self._middleware_library_library = MiddlewaresLibraryToLibrary(options)
|
|
21
|
+
|
|
22
|
+
def generate_single_library(self, library: Library) -> Library:
|
|
23
|
+
func = eval(f"_x.function_{self.choose_abbr_zotero_save}", {}, {"_x": self._middleware_library_library})
|
|
24
|
+
library = func(library)
|
|
25
|
+
|
|
26
|
+
return library
|
|
27
|
+
|
|
28
|
+
def generate_multi_libraries(self, library: Library) -> Tuple[Library, Library, Library]:
|
|
29
|
+
abbr_library, zotero_library, save_library = self._middleware_library_library.functions(library)
|
|
30
|
+
|
|
31
|
+
return abbr_library, zotero_library, save_library
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
from typing import Any, Dict, List, Optional, Union
|
|
3
|
+
|
|
4
|
+
from ..bibtexparser import (
|
|
5
|
+
BibtexFormat,
|
|
6
|
+
Block,
|
|
7
|
+
DuplicateBlockKeyBlock,
|
|
8
|
+
Entry,
|
|
9
|
+
ExplicitComment,
|
|
10
|
+
Field,
|
|
11
|
+
ImplicitComment,
|
|
12
|
+
Library,
|
|
13
|
+
MiddlewaresLibraryToStr,
|
|
14
|
+
ParsingFailedBlock,
|
|
15
|
+
Preamble,
|
|
16
|
+
String,
|
|
17
|
+
)
|
|
18
|
+
from .convert_library_to_library import ConvertLibrayToLibrary
|
|
19
|
+
|
|
20
|
+
VAL_SEP = " = "
|
|
21
|
+
PARSING_FAILED_COMMENT = "% WARNING Parsing failed for the following {n} lines."
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ConvertLibrayToStr(object):
|
|
25
|
+
"""Convert library to str.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
options (Dict[str, Any]): Options. Default is {}.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
is_standardize_library (bool): Is standardize library. Default is False.
|
|
32
|
+
empty_entry_cite_keys (bool): Empty entry cite keys. Default is False.
|
|
33
|
+
add_index_to_entries (bool): Add index to entries. Default is False.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, options: Dict[str, Any]):
|
|
37
|
+
|
|
38
|
+
self.is_standardize_library = options.get("is_standardize_library", False)
|
|
39
|
+
self.empty_entry_cite_keys = options.get("empty_entry_cite_keys", False)
|
|
40
|
+
self.add_index_to_entries = options.get("add_index_to_entries", False)
|
|
41
|
+
self.entries_necessary = options.get("entries_necessary", True)
|
|
42
|
+
|
|
43
|
+
self.options = options
|
|
44
|
+
|
|
45
|
+
def generate_str(
|
|
46
|
+
self, library: Union[Library, List[Block]], bibtex_format: Optional[BibtexFormat] = None
|
|
47
|
+
) -> List[str]:
|
|
48
|
+
"""Serialize a BibTeX database.
|
|
49
|
+
|
|
50
|
+
:param library: BibTeX database to serialize.
|
|
51
|
+
:param bibtex_format: Customized BibTeX format to use (optional).
|
|
52
|
+
"""
|
|
53
|
+
# --------- --------- --------- #
|
|
54
|
+
if not isinstance(library, Library):
|
|
55
|
+
library = Library(library)
|
|
56
|
+
|
|
57
|
+
# standardizer
|
|
58
|
+
if self.is_standardize_library:
|
|
59
|
+
library = ConvertLibrayToLibrary(self.options).generate_single_library(library)
|
|
60
|
+
|
|
61
|
+
# --------- --------- --------- #
|
|
62
|
+
library = MiddlewaresLibraryToStr(self.options).functions(library)
|
|
63
|
+
|
|
64
|
+
# --------- --------- --------- #
|
|
65
|
+
if bibtex_format is None:
|
|
66
|
+
bibtex_format = BibtexFormat()
|
|
67
|
+
|
|
68
|
+
if bibtex_format.value_column == "auto":
|
|
69
|
+
auto_val: int = self._calculate_auto_value_align(library)
|
|
70
|
+
# Copy the format instance to avoid modifying the original
|
|
71
|
+
# (which would be bad if the format is used for multiple libraries)
|
|
72
|
+
bibtex_format = deepcopy(bibtex_format)
|
|
73
|
+
bibtex_format.value_column = auto_val
|
|
74
|
+
|
|
75
|
+
# --------- --------- --------- #
|
|
76
|
+
if self.entries_necessary:
|
|
77
|
+
if not library.entries:
|
|
78
|
+
return []
|
|
79
|
+
|
|
80
|
+
data_list = []
|
|
81
|
+
j = 0
|
|
82
|
+
for i, block in enumerate(library.blocks):
|
|
83
|
+
if self.add_index_to_entries and isinstance(block, Entry):
|
|
84
|
+
data_list.append(f"% {j + 1}\n")
|
|
85
|
+
j += 1
|
|
86
|
+
|
|
87
|
+
# Get str representation of block
|
|
88
|
+
pieces = self._treat_block(bibtex_format, block)
|
|
89
|
+
data_list.extend(pieces)
|
|
90
|
+
|
|
91
|
+
# Separate Blocks
|
|
92
|
+
if i < len(library.blocks) - 1:
|
|
93
|
+
data_list.append(bibtex_format.block_separator)
|
|
94
|
+
return data_list
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def _calculate_auto_value_align(library: Library) -> int:
|
|
98
|
+
max_key_len = 0
|
|
99
|
+
for entry in library.entries:
|
|
100
|
+
for key in entry.fields_dict:
|
|
101
|
+
max_key_len = max(max_key_len, len(key))
|
|
102
|
+
return max_key_len
|
|
103
|
+
|
|
104
|
+
def _treat_block(self, bibtex_format, block) -> List[str]:
|
|
105
|
+
if isinstance(block, Entry):
|
|
106
|
+
pieces = self._treat_entry(block, bibtex_format)
|
|
107
|
+
elif isinstance(block, String):
|
|
108
|
+
pieces = self._treat_string(block, bibtex_format)
|
|
109
|
+
elif isinstance(block, Preamble):
|
|
110
|
+
pieces = self._treat_preamble(block, bibtex_format)
|
|
111
|
+
elif isinstance(block, ExplicitComment):
|
|
112
|
+
pieces = self._treat_expl_comment(block, bibtex_format)
|
|
113
|
+
elif isinstance(block, ImplicitComment):
|
|
114
|
+
pieces = self._treat_impl_comment(block, bibtex_format)
|
|
115
|
+
elif isinstance(block, ParsingFailedBlock):
|
|
116
|
+
pieces = self._treat_failed_block(block, bibtex_format)
|
|
117
|
+
else:
|
|
118
|
+
raise ValueError(f"Unknown block type: {type(block)} in {__file__}")
|
|
119
|
+
return pieces
|
|
120
|
+
|
|
121
|
+
# entry
|
|
122
|
+
def _treat_entry(self, block: Entry, bibtex_format: BibtexFormat) -> List[str]:
|
|
123
|
+
if self.empty_entry_cite_keys:
|
|
124
|
+
result = ["@" + block.entry_type + "{" + " " + ",\n"]
|
|
125
|
+
else:
|
|
126
|
+
result = ["@" + block.entry_type + "{" + block.key + ",\n"]
|
|
127
|
+
field: Field
|
|
128
|
+
for i, field in enumerate(block.fields):
|
|
129
|
+
res = []
|
|
130
|
+
res.append(bibtex_format.indent)
|
|
131
|
+
res.append(field.key)
|
|
132
|
+
res.append(self._val_intent_string(bibtex_format, field.key))
|
|
133
|
+
res.append(VAL_SEP)
|
|
134
|
+
res.append("{") # add by me
|
|
135
|
+
res.append(field.value)
|
|
136
|
+
res.append("}") # add by me
|
|
137
|
+
if bibtex_format.trailing_comma or i < len(block.fields) - 1:
|
|
138
|
+
res.append(",")
|
|
139
|
+
res.append("\n")
|
|
140
|
+
result.append("".join(res))
|
|
141
|
+
|
|
142
|
+
result.append("}\n")
|
|
143
|
+
return result
|
|
144
|
+
|
|
145
|
+
@staticmethod
|
|
146
|
+
def _val_intent_string(bibtex_format: BibtexFormat, key: str) -> str:
|
|
147
|
+
"""Calculate the spaces which have to be added after the ` = `."""
|
|
148
|
+
if isinstance(bibtex_format.value_column, int):
|
|
149
|
+
length = bibtex_format.value_column - len(key)
|
|
150
|
+
return "" if length <= 0 else " " * length
|
|
151
|
+
else:
|
|
152
|
+
return ""
|
|
153
|
+
|
|
154
|
+
# string
|
|
155
|
+
@staticmethod
|
|
156
|
+
def _treat_string(block: String, bibtex_format: BibtexFormat) -> List[str]:
|
|
157
|
+
result = [
|
|
158
|
+
"@string{",
|
|
159
|
+
block.key,
|
|
160
|
+
VAL_SEP,
|
|
161
|
+
"{",
|
|
162
|
+
block.value,
|
|
163
|
+
"}",
|
|
164
|
+
"}\n",
|
|
165
|
+
]
|
|
166
|
+
return ["".join(result)]
|
|
167
|
+
|
|
168
|
+
# preamble
|
|
169
|
+
@staticmethod
|
|
170
|
+
def _treat_preamble(block: Preamble, bibtex_format: BibtexFormat) -> List[str]:
|
|
171
|
+
result = ["@preamble{" + f' "{block.value.rstrip()} "' + " }", "\n"]
|
|
172
|
+
return ["".join(result)]
|
|
173
|
+
|
|
174
|
+
# implicit comment
|
|
175
|
+
@staticmethod
|
|
176
|
+
def _treat_impl_comment(block: ImplicitComment, bibtex_format: BibtexFormat) -> List[str]:
|
|
177
|
+
# Note: No explicit escaping is done here - that should be done in middleware
|
|
178
|
+
result = [block.comment.rstrip(), "\n"]
|
|
179
|
+
return ["".join(result)]
|
|
180
|
+
|
|
181
|
+
# explicit comment
|
|
182
|
+
@staticmethod
|
|
183
|
+
def _treat_expl_comment(block: ExplicitComment, bibtex_format: BibtexFormat) -> List[str]:
|
|
184
|
+
result = ["@comment{", block.comment.rstrip(), "}\n"]
|
|
185
|
+
return ["".join(result)]
|
|
186
|
+
|
|
187
|
+
# failed block
|
|
188
|
+
@staticmethod
|
|
189
|
+
def _treat_failed_block(block: ParsingFailedBlock, bibtex_format: BibtexFormat) -> List[str]:
|
|
190
|
+
if isinstance(block.raw, str):
|
|
191
|
+
lines = len(block.raw.splitlines())
|
|
192
|
+
parsing_failed_comment = PARSING_FAILED_COMMENT.format(n=lines)
|
|
193
|
+
return [parsing_failed_comment.rstrip(), "\n", block.raw.rstrip(), "\n"]
|
|
194
|
+
else:
|
|
195
|
+
if isinstance(block, DuplicateBlockKeyBlock):
|
|
196
|
+
print(f"Duplicate key block: previous block key is `{block.key}`.")
|
|
197
|
+
else:
|
|
198
|
+
print(f"The raw of the field block: {block} is None.")
|
|
199
|
+
return []
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
|
|
3
|
+
from ..bibtexparser import Library, MiddlewaresStrToLibrary, Splitter
|
|
4
|
+
from .convert_str_to_str import ConvertStrToStr
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConvertStrToLibrary(object):
|
|
8
|
+
"""Convert str to library.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
options (Dict[str, Any]): Options. Default is {}.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
is_standardize_bib (bool): Is standardize bib. Default is True.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, options: Dict[str, Any] = {}) -> None:
|
|
18
|
+
|
|
19
|
+
self.is_standardize_bib = options.get("is_standardize_bib", True)
|
|
20
|
+
|
|
21
|
+
self.options = options
|
|
22
|
+
|
|
23
|
+
def generate_library(self, data_list: List[str]) -> Library:
|
|
24
|
+
implicit_coments = []
|
|
25
|
+
# standardizer
|
|
26
|
+
if self.is_standardize_bib:
|
|
27
|
+
data_list, implicit_coments = ConvertStrToStr(self.options).generate_str(data_list)
|
|
28
|
+
|
|
29
|
+
# splitter
|
|
30
|
+
library = Splitter().splitter(data_list, implicit_coments)
|
|
31
|
+
|
|
32
|
+
# middlewares
|
|
33
|
+
library = MiddlewaresStrToLibrary(self.options).functions(library)
|
|
34
|
+
return library
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Tuple
|
|
2
|
+
|
|
3
|
+
from ..bibtexbase import StandardizeBib
|
|
4
|
+
from ..bibtexparser import MiddlewaresStrToStr
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConvertStrToStr(object):
|
|
8
|
+
"""Convert str to str.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
options (Dict[str, Any]): Options. Default is {}.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
default_additional_field_list (List[str]): Default additional field list. Default is [].
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, options: Dict[str, Any] = {}) -> None:
|
|
18
|
+
|
|
19
|
+
self.default_additional_field_list = options.get("default_additional_field_list", [])
|
|
20
|
+
|
|
21
|
+
self.options = options
|
|
22
|
+
|
|
23
|
+
def generate_str(self, data_list: List[str]) -> Tuple[List[str], List[List[str]]]:
|
|
24
|
+
data_list, implicit_comment_list = StandardizeBib(self.default_additional_field_list).standardize(data_list)
|
|
25
|
+
|
|
26
|
+
data_list = MiddlewaresStrToStr(self.options).functions(data_list)
|
|
27
|
+
return data_list, implicit_comment_list
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Initialization."""
|
|
2
|
+
|
|
3
|
+
__all__ = [
|
|
4
|
+
"BasicInput",
|
|
5
|
+
"PandocMdTo",
|
|
6
|
+
"PythonRunBib",
|
|
7
|
+
"PythonRunMd",
|
|
8
|
+
"PythonRunTex",
|
|
9
|
+
"PythonWriters",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
from .basic_input import BasicInput
|
|
13
|
+
from .pandoc_md_to import PandocMdTo
|
|
14
|
+
from .python_run_bib import PythonRunBib
|
|
15
|
+
from .python_run_md import PythonRunMd
|
|
16
|
+
from .python_run_tex import PythonRunTex
|
|
17
|
+
from .python_writers import PythonWriters
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
5
|
+
from pyadvtools import read_list, standard_path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BasicInput(object):
|
|
9
|
+
"""Basic input.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
options (Dict[str, Any]): Options.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
path_bibs (str): Path bibs.
|
|
16
|
+
path_figures (str): Path figures.
|
|
17
|
+
path_templates (str): Path templates.
|
|
18
|
+
|
|
19
|
+
full_abbr_article_dict (Dict[str, str]): Full abbr article dict.
|
|
20
|
+
full_abbr_inproceedings_dict (Dict[str, str]): Full abbr inproceedings dict.
|
|
21
|
+
full_names_in_json (str): Full names in json.
|
|
22
|
+
abbr_names_in_json (str): Abbr names in json.
|
|
23
|
+
|
|
24
|
+
full_csl_style_pandoc (str): Full path to csl style for pandoc.
|
|
25
|
+
full_tex_article_template_pandoc (str): Full path to tex article template for pandoc.
|
|
26
|
+
article_template_tex (List[str]): Article template for LaTex.
|
|
27
|
+
|
|
28
|
+
article_template_header_tex (List[str]): Article template header for LaTex.
|
|
29
|
+
article_template_tail_tex (List[str]): Article template tail for LaTex.
|
|
30
|
+
beamer_template_header_tex (List[str]): Beamer template header for LaTex.
|
|
31
|
+
beamer_template_tail_tex (List[str]): Beamer template tail for LaTex.
|
|
32
|
+
tex_math_commands_tex (List[str]): Tex math commands for LaTex.
|
|
33
|
+
tex_usepackages_tex (List[str]): Tex usepackages for LaTex.
|
|
34
|
+
handly_preamble (bool): Handly preamble.
|
|
35
|
+
|
|
36
|
+
options (Dict[str, Any]): Options.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, options: Dict[str, Any]) -> None:
|
|
40
|
+
# The paths of Figures, Bibs, and Templates
|
|
41
|
+
self.path_bibs: str = standard_path(options.get("path_bibs", ""))
|
|
42
|
+
self.path_figures: str = standard_path(options.get("path_figures", ""))
|
|
43
|
+
self.path_templates: str = standard_path(options.get("path_templates", ""))
|
|
44
|
+
|
|
45
|
+
# Update
|
|
46
|
+
path_config = standard_path(options.get("path_config", ""))
|
|
47
|
+
if len(self.path_bibs) == 0:
|
|
48
|
+
for folder in ["bib", "bibs", "Bib", "Bibs", "BIB", "BIBS"]:
|
|
49
|
+
if os.path.exists(p := os.path.join(path_config, folder)):
|
|
50
|
+
self.path_bibs = p
|
|
51
|
+
break
|
|
52
|
+
|
|
53
|
+
if len(self.path_figures) == 0:
|
|
54
|
+
for folder in ["figure", "figures", "Figure", "Figures", "FIGURE", "FIGURES"]:
|
|
55
|
+
if os.path.exists(p := os.path.join(path_config, folder)):
|
|
56
|
+
self.path_figures = p
|
|
57
|
+
break
|
|
58
|
+
|
|
59
|
+
if len(self.path_templates) == 0:
|
|
60
|
+
for folder in ["template", "templates", "Template", "Templates", "TEMPLATE", "TEMPLATES"]:
|
|
61
|
+
if os.path.exists(p := os.path.join(path_config, folder)):
|
|
62
|
+
self.path_templates = p
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
# bib/core
|
|
66
|
+
self._initialize_middlewares(options)
|
|
67
|
+
|
|
68
|
+
# main
|
|
69
|
+
self._initialize_pandoc_md_to(options)
|
|
70
|
+
self._initialize_python_run_tex(options)
|
|
71
|
+
|
|
72
|
+
self.options = options
|
|
73
|
+
|
|
74
|
+
# bib/core
|
|
75
|
+
def _initialize_middlewares(self, options: Dict[str, Any]) -> None:
|
|
76
|
+
full_json_c = os.path.join(self.path_templates, "AbbrFull", "conferences.json")
|
|
77
|
+
full_json_j = os.path.join(self.path_templates, "AbbrFull", "journals.json")
|
|
78
|
+
if os.path.isfile(full_json_c):
|
|
79
|
+
with open(full_json_c, "r") as f:
|
|
80
|
+
try:
|
|
81
|
+
json_dict = json.loads(f.read())
|
|
82
|
+
except Exception as e:
|
|
83
|
+
print(e)
|
|
84
|
+
json_dict = {}
|
|
85
|
+
full_abbr_inproceedings_dict = {p: json_dict[p].get("conferences", {}) for p in json_dict}
|
|
86
|
+
else:
|
|
87
|
+
full_abbr_inproceedings_dict = {}
|
|
88
|
+
|
|
89
|
+
if os.path.isfile(full_json_j):
|
|
90
|
+
with open(full_json_j, "r") as f:
|
|
91
|
+
try:
|
|
92
|
+
json_dict = json.loads(f.read())
|
|
93
|
+
except Exception as e:
|
|
94
|
+
print(e)
|
|
95
|
+
json_dict = {}
|
|
96
|
+
full_abbr_article_dict = {p: json_dict[p].get("journals", {}) for p in json_dict}
|
|
97
|
+
else:
|
|
98
|
+
full_abbr_article_dict = {}
|
|
99
|
+
|
|
100
|
+
inproceedings_dict = options.get("full_abbr_inproceedings_dict", {})
|
|
101
|
+
if len(inproceedings_dict) == 0:
|
|
102
|
+
inproceedings_dict = full_abbr_inproceedings_dict
|
|
103
|
+
self.full_abbr_inproceedings_dict = full_abbr_inproceedings_dict
|
|
104
|
+
|
|
105
|
+
article_dict = options.get("full_abbr_article_dict", {})
|
|
106
|
+
if len(article_dict) == 0:
|
|
107
|
+
article_dict = full_abbr_article_dict
|
|
108
|
+
self.full_abbr_article_dict = full_abbr_article_dict
|
|
109
|
+
|
|
110
|
+
full_names_in_json = options.get("full_names_in_json", "names_full")
|
|
111
|
+
if len(full_names_in_json) == 0:
|
|
112
|
+
full_names_in_json = "names_full"
|
|
113
|
+
self.full_names_in_json = full_names_in_json
|
|
114
|
+
|
|
115
|
+
abbr_names_in_json = options.get("abbr_names_in_json", "names_abbr")
|
|
116
|
+
if len(abbr_names_in_json) == 0:
|
|
117
|
+
abbr_names_in_json = "names_abbr"
|
|
118
|
+
self.abbr_names_in_json = abbr_names_in_json
|
|
119
|
+
|
|
120
|
+
options["full_abbr_article_dict"] = self.full_abbr_article_dict
|
|
121
|
+
options["full_abbr_inproceedings_dict"] = self.full_abbr_inproceedings_dict
|
|
122
|
+
|
|
123
|
+
options["full_names_in_json"] = self.full_names_in_json
|
|
124
|
+
options["abbr_names_in_json"] = self.abbr_names_in_json
|
|
125
|
+
|
|
126
|
+
# main
|
|
127
|
+
def _initialize_pandoc_md_to(self, options: Dict[str, Any]) -> None:
|
|
128
|
+
csl_name = options.get("csl_name", "apa-no-ampersand")
|
|
129
|
+
if len(csl_name) == 0:
|
|
130
|
+
csl_name = "apa-no-ampersand"
|
|
131
|
+
self.full_csl_style_pandoc = os.path.join(self.path_templates, f"CSL/{csl_name}.csl")
|
|
132
|
+
self.full_tex_article_template_pandoc = os.path.join(self.path_templates, "TEX/eisvogel.tex")
|
|
133
|
+
|
|
134
|
+
self.article_template_tex = read_list(os.path.join(self.path_templates, "TEX/Article.tex"))
|
|
135
|
+
|
|
136
|
+
def _initialize_python_run_tex(self, options: Dict[str, Any]) -> None:
|
|
137
|
+
self.article_template_header_tex = read_list(os.path.join(self.path_templates, "TEX/Article_Header.tex"))
|
|
138
|
+
self.article_template_tail_tex = read_list(os.path.join(self.path_templates, "TEX/Article_Tail.tex"))
|
|
139
|
+
self.beamer_template_header_tex = read_list(os.path.join(self.path_templates, "TEX/Beamer_Header.tex"))
|
|
140
|
+
self.beamer_template_tail_tex = read_list(os.path.join(self.path_templates, "TEX/Beamer_Tail.tex"))
|
|
141
|
+
self.math_commands_tex = read_list(os.path.join(self.path_templates, "TEX/math_commands.tex"))
|
|
142
|
+
self.usepackages_tex = read_list(os.path.join(self.path_templates, "TEX/Style.tex"))
|
|
143
|
+
|
|
144
|
+
# handly preamble
|
|
145
|
+
self.handly_preamble = options.get("handly_preamble", False)
|
|
146
|
+
if self.handly_preamble:
|
|
147
|
+
self.article_template_header_tex, self.article_template_tail_tex = [], []
|
|
148
|
+
self.beamer_template_header_tex, self.beamer_template_tail_tex = [], []
|
|
149
|
+
self.math_commands_tex, self.usepackages_tex = [], []
|