Skip to content

Commit 6a52b0f

Browse files
committed
doc: improve readme
1 parent 821ce09 commit 6a52b0f

3 files changed

Lines changed: 136 additions & 376 deletions

File tree

README.md

Lines changed: 23 additions & 290 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# bibextract
22

3+
[![codecov](https://codecov.io/gh/gautierdag/bibextract/branch/main/graph/badge.svg?token=NWHDJ22L8I)](https://codecov.io/gh/gautierdag/bibextract) [![tests](https://github.com/gautierdag/bibextract/actions/workflows/test.yml/badge.svg)](https://github.com/gautierdag/bibextract/actions/workflows/bibextract.yml) [![image](https://img.shields.io/pypi/l/bibextract.svg)](https://pypi.python.org/pypi/bibextract) [![image](https://img.shields.io/pypi/pyversions/bibextract.svg)](https://pypi.python.org/pypi/bibextract) [![PyPI version](https://badge.fury.io/py/bibextract.svg)](https://badge.fury.io/py/bibextract)
4+
35
A Python package (with Rust backend) for extracting survey content and bibliography from arXiv papers.
46

57
## Features
@@ -13,34 +15,40 @@ A Python package (with Rust backend) for extracting survey content and bibliogra
1315

1416
## Installation
1517

16-
### From PyPI (when published)
18+
### MCP server implementation
19+
20+
```bash
21+
uv run bibextract_mcp.py
22+
```
23+
24+
### From PyPI
1725

1826
```bash
19-
pip install bibextract
27+
uv add bibextract
2028
```
2129

2230
### From Source
2331

2432
1. Install Rust (if not already installed):
2533

26-
```bash
27-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
28-
source ~/.cargo/env
29-
```
34+
```bash
35+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
36+
source ~/.cargo/env
37+
```
3038

3139
2. Install maturin:
3240

33-
```bash
34-
pip install maturin
35-
```
41+
```bash
42+
pip install maturin
43+
```
3644

3745
3. Clone and build:
3846

39-
```bash
40-
git clone https://github.com/your-username/bibextract.git
41-
cd bibextract
42-
maturin develop
43-
```
47+
```bash
48+
git clone https://github.com/gautier/bibextract.git
49+
cd bibextract
50+
maturin develop
51+
```
4452

4553
## Usage
4654

@@ -74,290 +82,15 @@ cargo build --release
7482
./target/release/bibextract --paper-ids 2104.08653 1912.02292 --output survey.tex
7583
```
7684

77-
## Example Output
78-
79-
The package will generate:
80-
81-
1. **Survey Text** (`survey_text`): LaTeX content with normalized sections:
82-
83-
```latex
84-
\section{Related Work}
85-
86-
Recent advances in machine learning have shown...
87-
\cite{author2021paper, smith2020method}
88-
89-
\section{Background}
90-
91-
The foundations of this work build upon...
92-
\cite{jones2019foundation}
93-
```
94-
95-
2. **BibTeX Bibliography** (`bibtex`): Properly formatted citations:
96-
97-
```bibtex
98-
@article{author2021paper,
99-
title = {A Novel Approach to Machine Learning},
100-
author = {Author, First and Author, Second},
101-
journal = {Journal of ML},
102-
year = {2021},
103-
}
104-
105-
@inproceedings{smith2020method,
106-
title = {Efficient Methods for Deep Learning},
107-
author = {Smith, John},
108-
booktitle = {Conference on AI},
109-
year = {2020},
110-
}
111-
```
112-
113-
## API Reference
114-
115-
### `extract_survey(arxiv_ids)`
116-
117-
Extract survey content from arXiv papers.
118-
119-
**Parameters:**
120-
121-
- `arxiv_ids` (list): List of arXiv paper IDs (e.g., `['2104.08653', '1912.02292']`)
122-
123-
**Returns:**
124-
125-
- `dict` with keys:
126-
- `'survey_text'`: Raw LaTeX text with extracted sections and normalized citations
127-
- `'bibtex'`: BibTeX bibliography entries for all cited works
128-
129-
**Raises:**
130-
131-
- `TypeError`: If `arxiv_ids` is not a list
132-
- `ValueError`: If `arxiv_ids` is empty or contains no valid IDs
133-
- `RuntimeError`: If there's an error processing the papers
134-
13585
## Development
13686

13787
### Running Tests
13888

13989
```bash
14090
cargo test
91+
pytest tests
14192
```
14293

143-
### Building Documentation
144-
145-
```bash
146-
cargo doc --open
147-
```
148-
149-
### Contributing
150-
151-
1. Fork the repository
152-
2. Create a feature branch
153-
3. Make your changes
154-
4. Add tests if applicable
155-
5. Submit a pull request
156-
15794
## License
15895

15996
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
160-
161-
## Acknowledgments
162-
163-
- Built with [PyO3](https://pyo3.rs/) for Python-Rust integration
164-
- Uses [reqwest](https://github.com/seanmonstar/reqwest) for HTTP requests
165-
- Bibliography verification via DBLP and arXiv APIs
166-
- **Parallel Processing**: Uses parallel verification for improved performance
167-
- **Multiple Paper Support**: Processes multiple papers and consolidates their bibliographies
168-
169-
## Installation
170-
171-
### Prerequisites
172-
173-
- Rust (latest stable version)
174-
- Internet connection for downloading papers and verifying citations
175-
176-
### Building from Source
177-
178-
```bash
179-
git clone https://github.com/yourusername/bibextract.git
180-
cd bibextract
181-
cargo build --release
182-
```
183-
184-
The binary will be available at `target/release/bibextract`.
185-
186-
## Usage
187-
188-
### Basic Usage
189-
190-
Extract related work sections from a single arXiv paper:
191-
192-
```bash
193-
bibextract --paper-ids 2104.08653
194-
```
195-
196-
### Multiple Papers
197-
198-
Process multiple papers at once:
199-
200-
```bash
201-
bibextract --paper-ids 2104.08653 2203.15556 2307.09288
202-
```
203-
204-
### Save to File
205-
206-
Save the output to a LaTeX file:
207-
208-
```bash
209-
bibextract --paper-ids 2104.08653 2203.15556 --output survey.tex
210-
```
211-
212-
### Verbose Logging
213-
214-
Enable detailed logging to see the processing steps:
215-
216-
```bash
217-
bibextract --paper-ids 2104.08653 --verbose
218-
```
219-
220-
### Command Line Options
221-
222-
- `--paper-ids` or `-p`: List of arXiv paper IDs (e.g., 2104.08653)
223-
- `--output` or `-o`: Output file path (prints to stdout if not specified)
224-
- `--verbose` or `-v`: Enable verbose logging
225-
226-
## How It Works
227-
228-
### 1. Paper Download and Extraction
229-
230-
The tool downloads LaTeX source files from arXiv and extracts them:
231-
232-
- Supports both ZIP and TAR.GZ archives
233-
- Finds the main LaTeX file automatically
234-
- Processes `\input` and `\include` commands recursively
235-
236-
### 2. Section Detection
237-
238-
Identifies relevant sections based on common patterns:
239-
240-
- "Related Work"
241-
- "Background"
242-
- "Literature Review"
243-
- "Prior Work"
244-
- "State of the Art"
245-
- And many more variants
246-
247-
### 3. Bibliography Processing
248-
249-
Parses `.bbl` files to extract bibliography entries:
250-
251-
- Handles standard BibTeX formats
252-
- Extracts author, title, year, and other metadata
253-
- Supports both `\bibitem` and `\citeauthoryear` formats
254-
255-
### 4. Citation Verification
256-
257-
Verifies bibliography entries using external APIs:
258-
259-
- **DBLP API**: For academic paper verification
260-
- **arXiv API**: For arXiv preprint verification
261-
- **Parallel Processing**: Verifies multiple entries simultaneously
262-
- **Smart Matching**: Uses title, author, and year for accurate matching
263-
264-
### 5. Output Generation
265-
266-
Produces clean LaTeX output:
267-
268-
- Normalized citation keys
269-
- Consolidated bibliography
270-
- Ready-to-use LaTeX sections
271-
272-
## Output Format
273-
274-
The tool generates LaTeX output with:
275-
276-
```latex
277-
\section{Related Work}
278-
...section content with normalized citations...
279-
280-
\section{Background}
281-
...section content with normalized citations...
282-
283-
% Consolidated bibliography
284-
Bibliography {
285-
smith_machine_learning_2020: article {
286-
author: "John Smith",
287-
title: "Machine Learning Approaches",
288-
year: "2020",
289-
verified_source: "DBLP",
290-
}
291-
...
292-
}
293-
```
294-
295-
## Example
296-
297-
```bash
298-
# Extract related work from a few machine learning papers
299-
bibextract --paper-ids 2104.08653 2203.15556 2307.09288 --output ml_survey.tex --verbose
300-
```
301-
302-
This will:
303-
304-
1. Download and extract LaTeX sources for each paper
305-
2. Parse bibliography files
306-
3. Verify citations using DBLP and arXiv APIs
307-
4. Extract related work sections
308-
5. Normalize citation keys
309-
6. Consolidate bibliographies
310-
7. Save the result to `ml_survey.tex`
311-
312-
## Architecture
313-
314-
The project is organized into several modules:
315-
316-
- `latex::bibliography`: Bibliography parsing and management
317-
- `latex::citation`: Citation extraction and normalization
318-
- `latex::parser`: LaTeX file parsing and archive extraction
319-
- `latex::verification`: Bibliography verification using external APIs
320-
321-
## Dependencies
322-
323-
- `anyhow`: Error handling
324-
- `clap`: Command line argument parsing
325-
- `reqwest`: HTTP client for API requests
326-
- `regex`: Regular expression support
327-
- `rayon`: Parallel processing
328-
- `serde_json`: JSON parsing for API responses
329-
- `tempfile`: Temporary file management
330-
- `zip`: ZIP archive extraction
331-
- `tar` + `flate2`: TAR.GZ archive extraction
332-
333-
## Logging
334-
335-
The tool uses structured logging to show progress:
336-
337-
```
338-
INFO Processing arXiv paper with ID: 2104.08653
339-
INFO Downloading source files from arXiv for paper: 2104.08653
340-
INFO Extracting ZIP archive
341-
INFO Verifying bibliography entries for paper 2104.08653
342-
INFO Verified entry: smith2020 (progress: 1/25)
343-
INFO Found 3 sections with bibliography entries
344-
INFO Output written to "survey.tex"
345-
```
346-
347-
## Error Handling
348-
349-
The tool handles various error conditions gracefully:
350-
351-
- Invalid arXiv IDs
352-
- Missing or corrupted source files
353-
- Network failures during verification
354-
- Malformed LaTeX files
355-
- Missing bibliography files
356-
357-
## Contributing
358-
359-
Contributions are welcome! Please feel free to submit issues and pull requests.
360-
361-
## License
362-
363-
This project is licensed under the MIT License - see the LICENSE file for details.

bibextract_mcp.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# /// script
2+
# dependencies = ["fastmcp", "bibextract"]
3+
# ///
4+
5+
from fastmcp import FastMCP
6+
7+
mcp = FastMCP("Get arvix paper related work and bibliography")
8+
9+
10+
@mcp.tool(
11+
name="arvix_survey", description="Get arvix paper related work and bibliography"
12+
)
13+
def arvix_survey(arvix_id: str) -> str:
14+
"""
15+
Get arvix paper related work and bibliography.
16+
Args:
17+
arvix_id (str): The ID of the arXiv paper to process.
18+
Returns:
19+
str: related work and cited work bibliography
20+
"""
21+
try:
22+
from bibextract import extract_survey
23+
24+
result = extract_survey([arvix_id])
25+
return f"Related work:\n{result['survey_text']}\n\nBibliography:\n{result['bibtex']}"
26+
except Exception as e:
27+
return f"Error processing arXiv paper {arvix_id}: {e}"
28+
29+
30+
if __name__ == "__main__":
31+
mcp.run()

0 commit comments

Comments
 (0)