pyeasyphd 0.1.0__py3-none-any.whl → 0.1.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.

Files changed (75) hide show
  1. pyeasyphd/.python-version +1 -1
  2. pyeasyphd/main/__init__.py +0 -4
  3. pyeasyphd/main/basic_input.py +7 -63
  4. pyeasyphd/main/python_run_md.py +3 -3
  5. pyeasyphd/main/python_run_tex.py +1 -1
  6. pyeasyphd/pyeasyphd.sublime-settings +2 -160
  7. pyeasyphd/tools/__init__.py +1 -16
  8. pyeasyphd/tools/generate/generate_from_bibs.py +54 -330
  9. pyeasyphd/tools/generate/generate_html.py +122 -0
  10. pyeasyphd/tools/generate/generate_library.py +188 -0
  11. pyeasyphd/tools/generate/generate_links.py +13 -4
  12. pyeasyphd/tools/py_run_bib_md_tex.py +12 -13
  13. pyeasyphd/tools/search/search_base.py +8 -5
  14. pyeasyphd/tools/search/search_core.py +4 -3
  15. pyeasyphd/tools/search/search_keywords.py +1 -1
  16. pyeasyphd/tools/search/search_writers.py +8 -5
  17. {pyeasyphd-0.1.0.dist-info → pyeasyphd-0.1.2.dist-info}/METADATA +3 -6
  18. pyeasyphd-0.1.2.dist-info/RECORD +27 -0
  19. pyeasyphd/bib/__init__.py +0 -1
  20. pyeasyphd/bib/bibtexbase/__init__.py +0 -7
  21. pyeasyphd/bib/bibtexbase/standardize/_base.py +0 -36
  22. pyeasyphd/bib/bibtexbase/standardize/default_data.py +0 -97
  23. pyeasyphd/bib/bibtexbase/standardize/do_on_bib.py +0 -54
  24. pyeasyphd/bib/bibtexbase/standardize/do_on_comment_block.py +0 -38
  25. pyeasyphd/bib/bibtexbase/standardize/do_on_entry_block.py +0 -310
  26. pyeasyphd/bib/bibtexbase/standardize/do_on_preamble_block.py +0 -35
  27. pyeasyphd/bib/bibtexbase/standardize/do_on_string_block.py +0 -34
  28. pyeasyphd/bib/bibtexbase/standardize_bib.py +0 -75
  29. pyeasyphd/bib/bibtexparser/__init__.py +0 -47
  30. pyeasyphd/bib/bibtexparser/bibtex_format.py +0 -87
  31. pyeasyphd/bib/bibtexparser/exceptions.py +0 -64
  32. pyeasyphd/bib/bibtexparser/library.py +0 -207
  33. pyeasyphd/bib/bibtexparser/middlewares/block/add.py +0 -94
  34. pyeasyphd/bib/bibtexparser/middlewares/block/authors.py +0 -22
  35. pyeasyphd/bib/bibtexparser/middlewares/block/doi_url.py +0 -62
  36. pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_normalize.py +0 -47
  37. pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_replace.py +0 -31
  38. pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_values_normalize.py +0 -222
  39. pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_delete.py +0 -34
  40. pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_keep.py +0 -33
  41. pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_sort.py +0 -70
  42. pyeasyphd/bib/bibtexparser/middlewares/block/entry_types.py +0 -15
  43. pyeasyphd/bib/bibtexparser/middlewares/block/journal_booktitle.py +0 -113
  44. pyeasyphd/bib/bibtexparser/middlewares/block/month_year.py +0 -34
  45. pyeasyphd/bib/bibtexparser/middlewares/block/number_volume.py +0 -21
  46. pyeasyphd/bib/bibtexparser/middlewares/block/pages.py +0 -28
  47. pyeasyphd/bib/bibtexparser/middlewares/block/title.py +0 -20
  48. pyeasyphd/bib/bibtexparser/middlewares/library/generating_entrykeys.py +0 -98
  49. pyeasyphd/bib/bibtexparser/middlewares/library/keeping_blocks.py +0 -29
  50. pyeasyphd/bib/bibtexparser/middlewares/library/sorting_blocks.py +0 -124
  51. pyeasyphd/bib/bibtexparser/middlewares/middleware.py +0 -222
  52. pyeasyphd/bib/bibtexparser/middlewares/parsestack.py +0 -13
  53. pyeasyphd/bib/bibtexparser/middlewares/utils.py +0 -226
  54. pyeasyphd/bib/bibtexparser/middlewares_library_to_library.py +0 -414
  55. pyeasyphd/bib/bibtexparser/middlewares_library_to_str.py +0 -42
  56. pyeasyphd/bib/bibtexparser/middlewares_str_to_library.py +0 -35
  57. pyeasyphd/bib/bibtexparser/middlewares_str_to_str.py +0 -29
  58. pyeasyphd/bib/bibtexparser/model.py +0 -481
  59. pyeasyphd/bib/bibtexparser/splitter.py +0 -151
  60. pyeasyphd/bib/core/__init__.py +0 -18
  61. pyeasyphd/bib/core/convert_library_to_library.py +0 -31
  62. pyeasyphd/bib/core/convert_library_to_str.py +0 -199
  63. pyeasyphd/bib/core/convert_str_to_library.py +0 -34
  64. pyeasyphd/bib/core/convert_str_to_str.py +0 -27
  65. pyeasyphd/main/python_run_bib.py +0 -73
  66. pyeasyphd/main/python_writers.py +0 -212
  67. pyeasyphd/tools/compare/compare_bibs.py +0 -234
  68. pyeasyphd/tools/experiments_base.py +0 -203
  69. pyeasyphd/tools/format_save_bibs.py +0 -178
  70. pyeasyphd/tools/replace/replace.py +0 -81
  71. pyeasyphd/tools/spider/process_spider_bib.py +0 -247
  72. pyeasyphd/tools/spider/process_spider_url.py +0 -75
  73. pyeasyphd/tools/spider/process_spider_url_bib.py +0 -62
  74. pyeasyphd-0.1.0.dist-info/RECORD +0 -80
  75. {pyeasyphd-0.1.0.dist-info → pyeasyphd-0.1.2.dist-info}/WHEEL +0 -0
@@ -1,18 +0,0 @@
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
@@ -1,31 +0,0 @@
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
@@ -1,199 +0,0 @@
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 []
@@ -1,34 +0,0 @@
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
@@ -1,27 +0,0 @@
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
@@ -1,73 +0,0 @@
1
- from typing import Any, Dict, List, Tuple, Union
2
-
3
- from pyadvtools import (
4
- transform_to_data_list,
5
- )
6
-
7
- from ..bib.bibtexparser import Entry, Library
8
- from ..bib.core import ConvertLibrayToLibrary, ConvertStrToLibrary
9
- from .basic_input import BasicInput
10
-
11
-
12
- class PythonRunBib(BasicInput):
13
- """Python bib.
14
-
15
- Args:
16
- options (Dict[str, Any]): Options.
17
- """
18
-
19
- def __init__(self, options: Dict[str, Any]) -> None:
20
- super().__init__(options)
21
-
22
- def parse_to_single_standard_library(
23
- self,
24
- original_data: Union[List[str], str, Library],
25
- given_cite_keys: List[str] = [],
26
- **kwargs,
27
- ) -> Library:
28
- # update
29
- self.options["keep_entries_by_cite_keys"] = given_cite_keys
30
-
31
- if not isinstance(original_data, Library):
32
- original_data = transform_to_data_list(original_data, extension=".bib", **kwargs)
33
- original_data = ConvertStrToLibrary(self.options).generate_library(original_data)
34
-
35
- library = ConvertLibrayToLibrary(self.options).generate_single_library(original_data)
36
- return library
37
-
38
- def parse_to_multi_standard_library(
39
- self,
40
- original_data: Union[List[str], str, Library],
41
- given_cite_keys: List[str] = [],
42
- **kwargs,
43
- ) -> Tuple[Library, Library, Library]:
44
- # update
45
- self.options["keep_entries_by_cite_keys"] = given_cite_keys
46
-
47
- if not isinstance(original_data, Library):
48
- original_data = transform_to_data_list(original_data, extension=".bib", **kwargs)
49
- original_data = ConvertStrToLibrary(self.options).generate_library(original_data)
50
-
51
- libraries = ConvertLibrayToLibrary(self.options).generate_multi_libraries(original_data)
52
- abbr_library, zotero_library, save_library = libraries
53
- return abbr_library, zotero_library, save_library
54
-
55
- def parse_to_nested_entries_dict(
56
- self,
57
- original_data: Union[List[str], str, Library],
58
- given_cite_keys: List[str] = [],
59
- **kwargs,
60
- ) -> Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, List[Entry]]]]]]:
61
- library = self.parse_to_single_standard_library(original_data, given_cite_keys, **kwargs)
62
-
63
- entry_type_year_volume_number_month_entry_dict = {}
64
- for entry in library.entries:
65
- entry_type = entry.entry_type
66
- year = entry["year"] if "year" in entry else "year"
67
- volume = entry["volume"] if "volume" in entry else "volume"
68
- number = entry["number"] if "number" in entry else "number"
69
- month = entry["month"] if "month" in entry else "month"
70
- entry_type_year_volume_number_month_entry_dict.setdefault(entry_type, {}).setdefault(year, {}).setdefault(
71
- volume, {}
72
- ).setdefault(number, {}).setdefault(month, []).append(entry)
73
- return entry_type_year_volume_number_month_entry_dict
@@ -1,212 +0,0 @@
1
- import os
2
- import re
3
- from typing import Any, Dict, List, Optional, Tuple, Union
4
-
5
- from pyadvtools import (
6
- write_list,
7
- )
8
-
9
- from ..bib.bibtexparser import BibtexFormat, Block, Library
10
- from ..bib.core import ConvertLibrayToStr
11
- from .basic_input import BasicInput
12
- from .python_run_bib import PythonRunBib
13
-
14
-
15
- class PythonWriters(BasicInput):
16
- """Python writers.
17
-
18
- Args:
19
- options (Dict[str, Any]): Options.
20
-
21
- Attributes:
22
- bib_for_abbr_name (str = "abbr.bib"): Bib for abbr name.
23
- bib_for_zotero_name (str = "zotero.bib"): Bib for zotero name.
24
- bib_for_save_name (str = "save.bib"): Bib for save name.
25
- choose_abbr_zotero_save (str = "save"): Choose "abbr", "zotero", or "save".
26
- display_google_connected_scite (List[str] = ["google", "connected", "scite"]): Choose multiple items.
27
- """
28
-
29
- def __init__(self, options: Dict[str, Any]) -> None:
30
- options["is_sort_entry_fields"] = options.get("is_sort_entry_fields", True)
31
- options["is_sort_blocks"] = options.get("is_sort_blocks", True)
32
- options["sort_entries_by_field_keys_reverse"] = options.get("sort_entries_by_field_keys_reverse", True)
33
- super().__init__(options)
34
-
35
- self.bib_for_abbr_name = options.get("bib_for_abbr_name", "abbr.bib")
36
- self.bib_for_zotero_name = options.get("bib_for_zotero_name", "zotero.bib")
37
- self.bib_for_save_name = options.get("bib_for_save_name", "save.bib")
38
- self.choose_abbr_zotero_save = options.get("choose_abbr_zotero_save", "save")
39
-
40
- self.display_google_connected_scite = options.get(
41
- "display_google_connected_scite", ["google", "connected", "scite"]
42
- )
43
-
44
- self.bibtex_format_indent = options.get("bibtex_format_indent", " ")
45
- self.bibtex_format_trailing_comma = options.get("bibtex_format_trailing_comma", True)
46
- self.bibtex_format_block_separator = options.get("bibtex_format_block_separator", "")
47
-
48
- bibtex_format = BibtexFormat()
49
- bibtex_format.indent = self.bibtex_format_indent
50
- bibtex_format.block_separator = self.bibtex_format_block_separator
51
- bibtex_format.trailing_comma = self.bibtex_format_trailing_comma
52
- self.bibtex_format: Optional[BibtexFormat] = bibtex_format
53
-
54
- self._python_bib = PythonRunBib(self.options)
55
-
56
- def write_to_str(self, library: Union[Library, List[Block]]) -> List[str]:
57
- """Serialize a BibTeX database to a string.
58
-
59
- Args:
60
- library (Library | List[Block]): BibTeX database to serialize.
61
- bibtex_format (Optional[BibtexFormat] = None):
62
-
63
- """
64
- return ConvertLibrayToStr(self.options).generate_str(library, self.bibtex_format)
65
-
66
- def write_to_file(
67
- self,
68
- original_data: Union[Library, List[Block], List[str]],
69
- file_name: str,
70
- write_flag: str = "w",
71
- path_storage: Optional[str] = None,
72
- check: bool = True,
73
- delete_first_empty: bool = True,
74
- delete_last_empty: bool = True,
75
- compulsory: bool = False,
76
- delete_original_file: bool = False,
77
- ) -> None:
78
- """Write.
79
-
80
- Args:
81
- original_data (Union[Library, List[Block], List[str]]): data
82
- file_name (str): file name
83
- write_flag (str = "w"): write flag
84
- path_storage (Optional[str] = None): path storage
85
- check (bool = True): check
86
- delete_first_empty (bool = True): delete first empty
87
- delete_last_empty (bool = True): delete last empty
88
- compulsory (bool = False): compulsory
89
- delete_original_file (bool = False): delete original file
90
- bibtex_format (Optional[BibtexFormat] = None):
91
-
92
- """
93
- _options = {}
94
- _options.update(self.options)
95
- _library_str = ConvertLibrayToStr(_options)
96
-
97
- if isinstance(original_data, Library):
98
- data_list = _library_str.generate_str(original_data, self.bibtex_format)
99
- elif isinstance(original_data, list):
100
- if all([isinstance(line, str) for line in original_data]):
101
- data_list = [line for line in original_data if isinstance(line, str)]
102
- else:
103
- data_list = [line for line in original_data if isinstance(line, Block)]
104
- data_list = _library_str.generate_str(data_list, self.bibtex_format)
105
-
106
- write_list(
107
- data_list,
108
- file_name,
109
- write_flag,
110
- path_storage,
111
- check,
112
- delete_first_empty,
113
- delete_last_empty,
114
- compulsory,
115
- delete_original_file,
116
- )
117
- return None
118
-
119
- def write_multi_library_to_file(
120
- self,
121
- path_output: str,
122
- bib_for_abbr: Union[Library, List[Block]],
123
- bib_for_zotero: Union[Library, List[Block]],
124
- bib_for_save: Union[Library, List[Block]],
125
- given_cite_keys: List[str] = [],
126
- **kwargs,
127
- ) -> Tuple[str, str, str]:
128
- _options = {}
129
- _options.update(self.options)
130
- _options["keep_entries_by_cite_keys"] = given_cite_keys
131
- _options["sort_entries_by_cite_keys"] = given_cite_keys
132
-
133
- bib_abbr = ConvertLibrayToStr(_options).generate_str(bib_for_abbr, **kwargs)
134
- write_list(bib_abbr, self.bib_for_abbr_name, "w", path_output, False, **kwargs)
135
-
136
- bib_zotero = ConvertLibrayToStr(_options).generate_str(bib_for_zotero, **kwargs)
137
- write_list(bib_zotero, self.bib_for_zotero_name, "w", path_output, False, **kwargs)
138
-
139
- bib_save = ConvertLibrayToStr(_options).generate_str(bib_for_save, **kwargs)
140
- write_list(bib_save, self.bib_for_save_name, "w", path_output, False, **kwargs)
141
-
142
- full_bib_for_abbr = os.path.join(path_output, self.bib_for_abbr_name)
143
- full_bib_for_zotero = os.path.join(path_output, self.bib_for_zotero_name)
144
- full_bib_for_save = os.path.join(path_output, self.bib_for_save_name)
145
- return full_bib_for_abbr, full_bib_for_zotero, full_bib_for_save
146
-
147
- def output_key_url_http_bib_dict(self, library: Library) -> Dict[str, List[List[str]]]:
148
- _options = {}
149
- _options.update(self.options)
150
- _options["empty_entry_cite_keys"] = True
151
-
152
- key_url_http_bib_dict: Dict[str, List[List[str]]] = {}
153
-
154
- for key, entry in library.entries_dict.items():
155
-
156
- url = entry["url"] if "url" in entry else ""
157
- if len(url) == 0:
158
- url = entry["doi"] if "doi" in entry else ""
159
- if (len(url) != 0) and (not re.match(r"https*://", url)):
160
- url = f"https://doi.org/{url}"
161
-
162
- link_list = self._generate_link_list(entry)
163
- patch_bib = ConvertLibrayToStr(_options).generate_str([entry])
164
-
165
- v: List[List[str]] = [[], [], patch_bib]
166
-
167
- if len(url) != 0:
168
- v[0] = [url + "\n"]
169
- link_list.insert(0, rf"[www]({url})")
170
-
171
- join_link = []
172
- if link_list:
173
- for i in range(len(link_list) - 1):
174
- join_link.append(link_list[i].strip() + " |\n")
175
- join_link.append(link_list[-1].strip() + "\n")
176
-
177
- join_link[0] = "(" + join_link[0]
178
- join_link[-1] = join_link[-1].strip() + ")\n"
179
-
180
- v[1] = join_link
181
-
182
- key_url_http_bib_dict.update({key: v})
183
- return key_url_http_bib_dict
184
-
185
- def _generate_link_list(self, entry) -> List[str]:
186
- title = entry["title"] if "title" in entry else ""
187
- if not title:
188
- return []
189
-
190
- title = re.sub(r"\s+", "+", title)
191
- url_google = f"https://scholar.google.com/scholar?q={title}"
192
- url_connected = f"https://www.connectedpapers.com/search?q={title}"
193
- url_scite = f"https://scite.ai/search?q={title}"
194
-
195
- # Search cited number
196
- cited_number = entry["annotation"] if "annotation" in entry else ""
197
- if cited_number:
198
- cited_number = re.sub(r"[^0-9]+", "", cited_number)
199
- cited_number = int(cited_number) if cited_number.isdigit() else ""
200
- google = f"[Google Scholar: {cited_number}]({url_google})"
201
- else:
202
- google = f"[Google Scholar]({url_google})"
203
-
204
- connected = f"[Connected Papers]({url_connected})"
205
- scite = f"[Scite]({url_scite})"
206
-
207
- link_list = []
208
- for i, j in zip(["google", "connected", "scite"], [google, connected, scite]):
209
- if i in self.display_google_connected_scite:
210
- link_list.append(j)
211
-
212
- return link_list