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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15262ec68d575017876fbd0d6fc1812187fd004b72bd35d9d14180da89d68158
4
- data.tar.gz: ac8496b5f58cb08b0dc10d86bd9c9911097117746cc4e39298c3a04347bf6fa9
3
+ metadata.gz: e875a8f930f496ea5e0524e9c89d1323c950a84f8eb3112b9dc46c966f18a271
4
+ data.tar.gz: 2a19155e640dde0d04645afd6d74cdcec6da6856b2cba997fd3b79b261a0438e
5
5
  SHA512:
6
- metadata.gz: e3177ca8f534ebaa3033b730d68f305670eef81ddd66180930f44be1e6e62811fc33abe8ebfd94b2fc654f8e29b015e39fccf1eb4b40defbc22f569c84501794
7
- data.tar.gz: b7fcb7ded03135da14351889b47cdb67bd11049cd5dba42651ac8fd678631aa67377367187019ecc6d9260cde5ba38f77aa59b9ee684f23eac193dd1a2adf6be
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 chapter 3 and
41
- supersedes it with pikuri-extractors in chapter 7's assistant.
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. Wraps the +pdf-reader+ gem: walk every
8
- # page, emit a +"--- Page N ---"+ marker line followed by that
9
- # page's extracted text, join the blocks with single newlines.
10
- # The markers give every consumer page provenance the Read
11
- # tools tell the model to cite pages back to the user from them,
12
- # +vectordb_search+ chunks carry them so a hit can say which page
13
- # it came from, and what +vectordb_read+ shows matches what was
14
- # indexed exactly. Pages with no extractable text contribute
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
- # This extractor lived in pikuri-core until pdf-reader's
22
- # dependency tail (Ascii85, afm, hashery, ruby-rc4, ttfunk) became
23
- # the largest single bite in the core's audit tree five gems for
24
- # one file format, serving nothing else in core. Splitting it out
25
- # keeps the core minimal; hosts that want PDFs opt in with one
26
- # {.register} call. Distinct from pikuri-extractors' sandboxed
27
- # subprocess converters: this one is in-process and *lazy*
28
- # ({.extract_lines} parses pages on demand), a property a
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 pikuri-pdf defines this module but registers nothing.
35
- # A host script opts in with +Pikuri::Extractors::PDF.register+,
36
- # which inserts it at the *front* of the registry — unlike
37
- # pikuri-extractors' before-the-terminal insert because the
38
- # +%PDF-+ magic-byte sniff is the strongest signal in the
39
- # registry: it must win over +HTML+'s content-type match so a PDF
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+ raises a handful of typed exceptions for
98
- # documents it cannot parse — broken xrefs
99
- # ({::PDF::Reader::MalformedPDFError}), invalid page references
100
- # ({::PDF::Reader::InvalidPageError}), encrypted/XFA files
101
- # ({::PDF::Reader::UnsupportedFeatureError}). All three describe
102
- # a property of the document the LLM can react to ("try a
103
- # different URL / file"), so they re-raise as
104
- # {Pikuri::Extractor::Error} from inside the enumerator, i.e.
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. Sets up a dedicated Zeitwerk
6
- # loader rooted at this gem's +lib/+, contributing to the shared
7
- # +Pikuri::+ namespace alongside pikuri-core. After +require
8
- # 'pikuri-pdf'+, +Pikuri::Extractors::PDF+ is defined — but *nothing
9
- # is registered*: extractors plug into +Pikuri::Extractor.registry+
10
- # only when the host script calls their +register+ explicitly, so a
11
- # +bin/pikuri-*+ picks which extractors it wires in (same opt-in
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.7
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.7
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.7
25
+ version: 0.1.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: pdf-reader
28
28
  requirement: !ruby/object:Gem::Requirement