Comments (4)
Hey :-)
Your case is a bit tricky, as it does not only contain a duplicate block key, but also a duplicate field key.
In principle, middleware (which is responsible for the transformations of the parsed bibtex, e.g. to remove the enclosings is not applied to error blocks (as in most cases, their behavior would be undefined). The deliberate default is thus to just pass on these blocks when applying the middleware.
Note however that you can change the used middleware, and may just start by adding a middleware layer which attempts to ignore all errors:
from bibtexparser import parse_string
from bibtexparser.middlewares import BlockMiddleware, ResolveStringReferencesMiddleware, RemoveEnclosingMiddleware
from bibtexparser.model import Entry, Block, DuplicateBlockKeyBlock, DuplicateFieldKeyBlock
from bibtexparser import Library
from typing import Union, Collection
class IgnoreAllErrors(BlockMiddleware):
def transform_block(self, block: Block, library: Library) -> Union[Block, Collection[Block], None]:
print("bla")
try:
print("try")
return self.transform_entry(block.ignore_error_block, library)
except AttributeError:
print("nf")
return block
parse_stack = [IgnoreAllErrors(True), ResolveStringReferencesMiddleware(True), RemoveEnclosingMiddleware(True)]
library = parse_string(r"""
@article{foobar,
doi = {abc},
note = {Note 1},
note = {Note 2},
}""", parse_stack=parse_stack)
print(library.blocks[0])
from python-bibtexparser.
Your case is a bit tricky, as it does not only contain a duplicate block key, but also a duplicate field key.
There's only one duplication here, right? Just the note
field.
Anyway, I'll try this out. I'd like to have as little code as possible in my repo, so I'm voting for a duplicate_fields: Literal["ignore", "error", "parse"]
argument to parse()
here.
from python-bibtexparser.
Importing BlockMiddleware
fails. Please reopen.
from bibtexparser.middlewares import BlockMiddleware
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from bibtexparser.middlewares import BlockMiddleware
ImportError: cannot import name 'BlockMiddleware' from 'bibtexparser.middlewares' (/home/nschloe/venv/lib/python3.11/site-packages/bibtexparser/middlewares/__init__.py)
from python-bibtexparser.
Suggestion: Remove DuplicateBlockKeyBlock
and just parse an entry with duplicated field keys as Entry
. Perhaps add a duplicate_keys
attribute to Entry
. Better still a function has_duplicate_fields()
that runs over the fields list.
from python-bibtexparser.
Related Issues (20)
- Use case sensitive entry type HOT 4
- Make behaviour entry closer to `dict`: check if field is present
- Default `allow_parallel_execution=True` HOT 3
- Discussion: closer `dict` mimicking `Entry` HOT 1
- Apply style using pre-commit HOT 1
- Normalize field keys (to lowercase) HOT 8
- docs: links to code not working
- docs: switch themes? HOT 4
- Error in latex_to_unicode
- split_multiple_persons_names() bug HOT 1
- More flexible handling of case sensitivity in all keys HOT 3
- Question: sorting blocks by specific field values HOT 5
- Bug in SeparateCoAuthors
- ✨ Allow simple way to create custom block sorting HOT 2
- Where is the doc for v1? HOT 1
- does this package provide CURD function? HOT 2
- del
- Packaging: Include all files necessary for testing HOT 2
- parsing of escaped double quotes in double quote delimited fields fails
- Splitter interprets any @ sign as new block start
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-bibtexparser.