main.utils¶
Classes¶
CheckAcronymAbbrAndFullDict ¶
Checker for acronym, abbreviation and full form dictionaries.
Validates and processes dictionary data containing acronyms with their corresponding abbreviations and full forms.
Attributes:
| Name | Type | Description |
|---|---|---|
names_abbr | str | Key name for abbreviations in the dictionary. |
names_full | str | Key name for full forms in the dictionary. |
Initializes the checker with field names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names_abbr | str | Key name for abbreviations, defaults to "names_abbr". | 'names_abbr' |
names_full | str | Key name for full forms, defaults to "names_full". | 'names_full' |
Source code in pybibtexer/main/utils.py
Functions¶
compare_and_return_only_in_new ¶
Compares old and new JSON data to find newly added items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_old | dict | Old JSON data as dictionary. | required |
json_new | dict | New JSON data as dictionary. | required |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | Dictionary containing keys that only exist in new data. |
Source code in pybibtexer/main/utils.py
length_dupicate_match ¶
Performs comprehensive validation on dictionary data.
Executes three validation steps: length validation, duplicate checking, and mutual pattern matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dict_data | dict[str, dict[str, list[str]]] | Dictionary containing acronym data with abbreviations and full forms. | required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple | tuple[dict[str, dict[str, list[str]]], list[str]] | Validated dictionary and list of acronyms with matches. |
Source code in pybibtexer/main/utils.py
StrictOrderedDict ¶
A dictionary that strictly maintains insertion order.
This implementation guarantees that keys, values, and items will always be returned in the exact order they were inserted, regardless of Python version or internal dictionary implementation changes.
Attributes:
| Name | Type | Description |
|---|---|---|
_keys | List maintaining the order of key insertion. | |
_data | Dictionary storing the actual key-value pairs. |
Initializes the StrictOrderedDict with optional initial data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | dict | Optional iterable of (key, value) pairs to initialize the dictionary. If provided, must be an iterable containing exactly two-element tuples or lists representing key-value pairs. | required |
Example
sod = StrictOrderedDict() sod = StrictOrderedDict([('a', 1), ('b', 2)])
Source code in pybibtexer/main/utils.py
Functions¶
__contains__ ¶
Support key in dict syntax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key to check for existence. | required |
Returns:
| Type | Description |
|---|---|
bool | True if key exists in the dictionary, False otherwise. |
__getitem__ ¶
Retrieves the value associated with the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key to look up. | required |
Returns:
| Type | Description |
|---|---|
Any | The value associated with the key. |
Raises:
| Type | Description |
|---|---|
KeyError | If the key is not found in the dictionary. |
Source code in pybibtexer/main/utils.py
__len__ ¶
__repr__ ¶
Returns a string representation of the dictionary.
Returns:
| Type | Description |
|---|---|
str | A string representation showing all key-value pairs in insertion order, |
str | formatted like a standard Python dictionary. |
Example
sod = StrictOrderedDict([('x', 10), ('y', 20)]) print(sod)
Source code in pybibtexer/main/utils.py
__setitem__ ¶
Sets a key-value pair, maintaining insertion order for new keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key to set or update. | required |
value | Any | The value to associate with the key. | required |
Note
If the key is new, it is added to the end of the insertion order. If the key exists, its value is updated but its position remains unchanged.
Source code in pybibtexer/main/utils.py
get ¶
Safely get a value by key, returning default if key doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key to look up. | required |
default | Any | Value to return if key is not found. Defaults to None. | None |
Returns:
| Type | Description |
|---|---|
Any | The value associated with the key, or default if key doesn't exist. |
Source code in pybibtexer/main/utils.py
items ¶
Returns all key-value pairs in insertion order.
Returns:
| Type | Description |
|---|---|
list[tuple[str, Any]] | A list of (key, value) tuples in the order they were inserted. |
keys ¶
Returns all keys in insertion order.
Returns:
| Type | Description |
|---|---|
list[str] | A copy of the list containing all keys in the order they were inserted. |
values ¶
Returns all values in key insertion order.
Returns:
| Type | Description |
|---|---|
list[Any] | A list of values in the same order as their corresponding keys were inserted. |
Functions¶
parse_bibtex_file ¶
Parse BibTeX file and extract conference or journal data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_biblatex | str | Path to the BibLaTeX file. | required |
entry_type | str | Type of entry to parse - 'article' or 'inproceedings'. | 'article' |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, list[str]]] | Dictionary containing parsed conference or journal data. |
Raises:
| Type | Description |
|---|---|
ValueError | If entry_type is not 'article' or 'inproceedings'. |
Source code in pybibtexer/main/utils.py
process_user_conferences_journals_json ¶
Process user-defined conferences and journals JSON files.
Notes
The structure of full_json_c follows the format {"publisher": {"conferences": {"abbr": {"names_abbr": [], "names_full": []}}}}, while full_json_j adheres to the format {"publisher": {"journals": {"abbr": {"names_abbr": [], "names_full": []}}}}.
Source code in pybibtexer/main/utils.py
read_str ¶
Read file content as string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_file | str | Path to the file to read. | required |
Returns:
| Type | Description |
|---|---|
str | Content of the file as string. |