pikuri-pdf 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/pikuri/extractors/pdf.rb +30 -47
- data/lib/pikuri-pdf.rb +7 -15
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e875a8f930f496ea5e0524e9c89d1323c950a84f8eb3112b9dc46c966f18a271
|
|
4
|
+
data.tar.gz: 2a19155e640dde0d04645afd6d74cdcec6da6856b2cba997fd3b79b261a0438e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: deff0dfd33c26fed2becf99b70a978108debb56ef12e6a2d1b1b7a08eef07de6fc21c9deb47103d86f6e6974efffe5e2247510362b966ee8a263ac0d7e02f198
|
|
7
|
+
data.tar.gz: e44291c7b532cd9433963707d3c612b4759206cfa15028aa7326b942014ac9ea5731ee239cc1c155f46cb547c4277b85b59832642517e204b37ee4d444b4de53
|
data/README.md
CHANGED
|
@@ -37,8 +37,9 @@ posture. This gem is the no-infrastructure wiring — in-process
|
|
|
37
37
|
means no docker and no host CLIs, and it's what makes the lazy
|
|
38
38
|
page-windowed reads possible (a subprocess converter must convert
|
|
39
39
|
the whole document before emitting anything, and re-converts it on
|
|
40
|
-
every paged read). The guide wires this gem in
|
|
41
|
-
supersedes it with pikuri-extractors in
|
|
40
|
+
every paged read). The guide wires this gem in the vector-DB
|
|
41
|
+
chapter and supersedes it with pikuri-extractors in the
|
|
42
|
+
universal-assistant chapter.
|
|
42
43
|
|
|
43
44
|
## Install
|
|
44
45
|
|
|
@@ -4,48 +4,34 @@ require 'pdf-reader'
|
|
|
4
4
|
|
|
5
5
|
module Pikuri
|
|
6
6
|
module Extractors
|
|
7
|
-
# PDF → text extractor
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
# nothing (no marker either), so a fully scanned PDF extracts to
|
|
16
|
-
# the empty String — a deliberate silent skip callers detect by
|
|
17
|
-
# length if they care. No OCR in this path.
|
|
7
|
+
# PDF → text extractor over the +pdf-reader+ gem: each page emits a
|
|
8
|
+
# +"--- Page N ---"+ marker line then its text, blocks joined by
|
|
9
|
+
# single newlines. The markers carry page provenance downstream (a
|
|
10
|
+
# cited answer, a +vectordb+ hit's page number). A page with no
|
|
11
|
+
# extractable text contributes nothing — no marker — so a fully
|
|
12
|
+
# scanned PDF extracts to the empty String, a deliberate silent
|
|
13
|
+
# skip callers detect by length. No OCR here: +pdf-reader+ gives
|
|
14
|
+
# clean text from digitally-generated PDFs, nothing from scans.
|
|
18
15
|
#
|
|
19
16
|
# == Why a separate gem
|
|
20
17
|
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# subprocess converter structurally cannot have — see
|
|
30
|
-
# +Pikuri::Extractor+'s windowing yardoc.
|
|
18
|
+
# Split from pikuri-core to keep pdf-reader's five-gem dependency
|
|
19
|
+
# tail (Ascii85, afm, hashery, ruby-rc4, ttfunk) out of the core
|
|
20
|
+
# audit tree — five gems for one format nothing else in core uses.
|
|
21
|
+
# Hosts opt in with one {.register} call. Being in-process, it pages
|
|
22
|
+
# *lazily* ({.extract_lines} parses pages on demand) — a property a
|
|
23
|
+
# subprocess converter structurally cannot have. (The full
|
|
24
|
+
# this-gem-vs-pikuri-extractors PDF trade-off is in
|
|
25
|
+
# +pikuri-extractors/DESIGN.md+.)
|
|
31
26
|
#
|
|
32
27
|
# == Registration is explicit
|
|
33
28
|
#
|
|
34
|
-
# Requiring
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
# served under a lying header is still extracted, and it never
|
|
41
|
-
# misfires on text.
|
|
42
|
-
#
|
|
43
|
-
# Matched by the +%PDF-+ magic prefix *or* an +application/pdf+
|
|
44
|
-
# content-type.
|
|
45
|
-
#
|
|
46
|
-
# Best-effort by design: +pdf-reader+ produces clean text from
|
|
47
|
-
# PDFs generated from a digital source (LaTeX, Word export, ...)
|
|
48
|
-
# but nothing useful from scanned documents.
|
|
29
|
+
# Requiring the gem registers nothing; a host opts in with
|
|
30
|
+
# +Pikuri::Extractors::PDF.register+, which *front*-inserts into the
|
|
31
|
+
# registry (unlike pikuri-extractors' before-terminal insert)
|
|
32
|
+
# because the +%PDF-+ magic sniff is the registry's strongest
|
|
33
|
+
# signal — it must beat +HTML+'s content-type match so a PDF under a
|
|
34
|
+
# lying header still extracts, and it never misfires on text.
|
|
49
35
|
module PDF
|
|
50
36
|
# Insert this extractor at the front of
|
|
51
37
|
# +Pikuri::Extractor.registry+ (see "Registration is explicit"
|
|
@@ -94,17 +80,14 @@ module Pikuri
|
|
|
94
80
|
# +Pikuri::Extractor.extract_paged+ window) never pays for the
|
|
95
81
|
# pages past its window.
|
|
96
82
|
#
|
|
97
|
-
# +pdf-reader+
|
|
98
|
-
#
|
|
99
|
-
# ({::PDF::Reader::
|
|
100
|
-
# ({::PDF::Reader::
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
# at consumption time, which for a broken xref means the first
|
|
106
|
-
# +next+. Genuine bugs in +pdf-reader+ itself surface as their
|
|
107
|
-
# own classes and crash loud.
|
|
83
|
+
# The three typed +pdf-reader+ parse failures — broken xrefs
|
|
84
|
+
# ({::PDF::Reader::MalformedPDFError}), bad page refs
|
|
85
|
+
# ({::PDF::Reader::InvalidPageError}), encrypted/XFA
|
|
86
|
+
# ({::PDF::Reader::UnsupportedFeatureError}) — are document
|
|
87
|
+
# properties the LLM can react to, so they re-raise as
|
|
88
|
+
# {Pikuri::Extractor::Error}, from *inside* the enumerator: at
|
|
89
|
+
# consumption time, which for a broken xref means the first
|
|
90
|
+
# +next+. Other +pdf-reader+ errors are bugs and crash loud.
|
|
108
91
|
#
|
|
109
92
|
# @param io [IO, StringIO] seekable IO positioned at the start
|
|
110
93
|
# of the PDF bytes; must remain open while the enumerator is
|
data/lib/pikuri-pdf.rb
CHANGED
|
@@ -2,21 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
require 'pikuri-core'
|
|
4
4
|
|
|
5
|
-
# Entry file for the pikuri-pdf gem
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
# is
|
|
10
|
-
#
|
|
11
|
-
# +
|
|
12
|
-
# philosophy as +c.add_extension+, same shape as pikuri-extractors'
|
|
13
|
-
# +DOCUMENTS.register+).
|
|
14
|
-
#
|
|
15
|
-
# The +Pikuri::Extractors+ namespace is cooperative: pikuri-extractors
|
|
16
|
-
# contributes +Documents+ / +DOCUMENTS+, this gem contributes +PDF+.
|
|
17
|
-
# Each gem's loader manages only its own files; the loader constant is
|
|
18
|
-
# +PDF_LOADER+ (not +LOADER+) so both gems can be loaded together
|
|
19
|
-
# without colliding in the shared namespace.
|
|
5
|
+
# Entry file for the pikuri-pdf gem: a per-gem Zeitwerk loader
|
|
6
|
+
# contributing +Pikuri::Extractors::PDF+ to the shared +Pikuri::+
|
|
7
|
+
# namespace. Defining the module registers *nothing* — a host opts in
|
|
8
|
+
# with {Pikuri::Extractors::PDF.register} (see there). The
|
|
9
|
+
# +Pikuri::Extractors+ namespace is cooperative (pikuri-extractors adds
|
|
10
|
+
# +Documents+/+DOCUMENTS+), so the loader constant is +PDF_LOADER+, not
|
|
11
|
+
# +LOADER+, to avoid a collision when both gems load together.
|
|
20
12
|
module Pikuri
|
|
21
13
|
module Extractors
|
|
22
14
|
PDF_LOADER = Zeitwerk::Loader.new
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pikuri-pdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martin Vysny
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0
|
|
18
|
+
version: 0.1.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0
|
|
25
|
+
version: 0.1.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: pdf-reader
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|