Steve White 8c8af7dcaa | ||
---|---|---|
README.md | ||
errors.go | ||
example_test.go | ||
go.mod | ||
paperformatter.go | ||
paperformatter_test.go |
README.md
Paper Formatter
A Go library that converts JSON files containing paper reviews into formatted Markdown documents. The library organizes papers into accepted and rejected categories, formatting each entry with title, arXiv link, abstract, decision, and explanation.
Installation
go get gitea.r8z.us/stwhite/paperformatter
Usage
import "gitea.r8z.us/stwhite/paperformatter"
err := paperformatter.FormatPapers("input.json", "output.md")
if err != nil {
log.Fatal(err)
}
Input Format
The input JSON file should contain an array of entries, where each entry has the following structure:
[
{
"paper": {
"title": "Paper Title",
"abstract": "Paper Abstract",
"arxiv_id": "2301.00000"
},
"decision": "accept",
"explanation": "Explanation for the decision"
}
]
Output Format
The library generates a Markdown file that:
- Separates papers into "Accepted Papers" and "Rejected Papers" sections
- For each paper, includes:
- Title as a heading
- ArXiv link
- Abstract (formatted as a blockquote)
- Decision
- Explanation for the decision
Example output:
# Accepted Papers
## Example Paper Title
[arXiv:2301.00000](https://arxiv.org/abs/2301.00000)
> This is the paper's abstract...
**Decision:** accept
**Explanation:** This is the explanation for accepting the paper...
# Rejected Papers
[Additional papers would be listed here...]
Error Handling
The library provides detailed error handling with custom error types:
Validation Errors
- Empty or missing required fields (title, abstract, arxiv_id)
- Invalid decision values (must be "accept" or "reject")
- Empty explanation
File Operation Errors
- Input file cannot be read
- Output file cannot be written
- Includes detailed information about the failed operation and file path
JSON Parsing Errors
- Invalid JSON format
- Missing required fields in JSON structure
Each error type provides specific information about what went wrong:
// Example error handling
err := paperformatter.FormatPapers("input.json", "output.md")
if err != nil {
switch e := err.(type) {
case *paperformatter.ValidationError:
fmt.Printf("Validation failed for %s: %s\n", e.Field, e.Message)
case *paperformatter.FileError:
fmt.Printf("File operation '%s' failed for '%s': %v\n", e.Op, e.Path, e.Wrapped)
case *paperformatter.JSONError:
fmt.Printf("JSON parsing failed: %v\n", e.Wrapped)
default:
fmt.Printf("Error: %v\n", err)
}
}
Requirements
- Go 1.23.1 or later
Testing
The library includes comprehensive unit tests covering:
- Successful format conversion
- Error handling cases
- Edge cases (empty input, case sensitivity)
- File I/O operations
- Multiline text formatting
Run the tests using:
go test -v