Skip to content

Commit 793d416

Browse files
committed
fix(parser): lower word-space threshold 0.30 -> 0.20 of font size
PDFs emit one positioned glyph per text item with no explicit spaces; the parser infers word boundaries from the X-gap between glyphs. Measured against arXiv papers, real word-boundary gaps land around 0.20-0.30 of fontSize while intra-word kerning stays near zero. The old 0.30 threshold sat above most word gaps, so multi-word headings and body text ran together (implementingtensor2tensor, ModelArchitecture). 0.20 cleanly separates words without splitting tokens like tensor2tensor.
1 parent 764701c commit 793d416

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

pkg/parser/pdf.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,15 @@ func extractPDFRows(reader *pdflib.Reader) ([]pdfRow, error) {
261261
var sb strings.Builder
262262
var lastX float64
263263
for i, ch := range b.chars {
264-
// Insert a space if there's a visible gap between glyphs.
265-
if i > 0 && ch.X-lastX > ch.FontSize*0.3 {
264+
// Insert a space when the gap between the previous
265+
// glyph's end and this glyph's start exceeds a fraction
266+
// of the font size. 0.20 was tuned against real PDFs
267+
// (arXiv papers): word-boundary gaps land around
268+
// 0.20-0.30·fontSize while intra-word kerning stays
269+
// well below. The old 0.30 threshold missed most word
270+
// boundaries, producing run-together text like
271+
// "implementingtensor2tensor".
272+
if i > 0 && ch.X-lastX > ch.FontSize*0.20 {
266273
sb.WriteString(" ")
267274
}
268275
sb.WriteString(ch.S)

0 commit comments

Comments
 (0)