Skip to content

Commit

Permalink
Merge pull request #66 from krishnasism/chore/use-yield-instead-of-di…
Browse files Browse the repository at this point in the history
…rect-return-sparsematrix-krish-20012024

Use yield in SparseMatrix items function + remove lru_cache
  • Loading branch information
krishnasism authored Jan 20, 2024
2 parents 0b15117 + 34c0e62 commit ca32fef
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 5 deletions.
1 change: 0 additions & 1 deletion hotpdf/hotpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,5 @@ def extract_spans_text(
extracted_text: list[str] = []

for span in spans:
# TODO: This will be span.to_text() in the next release
extracted_text.append(span.to_text())
return "".join(extracted_text)
3 changes: 0 additions & 3 deletions hotpdf/memory_map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math
import xml.etree.ElementTree as ET
from collections.abc import Generator
from functools import lru_cache
from hashlib import md5

from .data.classes import HotCharacter, PageResult
Expand Down Expand Up @@ -103,7 +102,6 @@ def load_memory_map(self, page: ET.Element, drop_duplicate_spans: bool = True) -
self.width = self.memory_map.columns
self.height = self.memory_map.rows

@lru_cache # noqa: B019
def extract_text_from_bbox(self, x0: int, x1: int, y0: int, y1: int) -> str:
"""Extract text within a specified bounding box.
Expand All @@ -128,7 +126,6 @@ def extract_text_from_bbox(self, x0: int, x1: int, y0: int, y1: int) -> str:

return extracted_text

@lru_cache # noqa: B019
def find_text(self, query: str) -> tuple[list[str], PageResult]:
"""Find text within the memory map.
Expand Down
2 changes: 1 addition & 1 deletion hotpdf/span_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __setitem__(self, span_id: Union[str, None], hot_character: HotCharacter) ->
self.insert(span_id, hot_character)

def items(self) -> Iterable[tuple[str, Span]]:
return self.span_map.items()
yield from self.span_map.items()

def insert(self, span_id: Union[str, None], hot_character: HotCharacter) -> None:
if not span_id:
Expand Down

0 comments on commit ca32fef

Please sign in to comment.