Skip to content

Commit

Permalink
Merge pull request #112 from swisstopo/fix-sorting-of-text-lines-with…
Browse files Browse the repository at this point in the history
…-identical-vertical-position

Sort lines with identical vertical position by horizontal position in DataExtractor
  • Loading branch information
stijnvermeeren-swisstopo authored Jan 27, 2025
2 parents b5ef183 + d385aaf commit a31eafa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/stratigraphy/data_extractor/data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ def get_lines_near_key(self, lines, key_line: TextLine) -> list[TextLine]:
feature_lines.insert(0, key_line)
feature_lines = list(dict.fromkeys(feature_lines))

# Sort by vertical distance between the top of the feature line and the top of key_line
feature_lines_sorted = sorted(feature_lines, key=lambda line: abs(line.rect.y0 - key_line.rect.y0))
# Sort by
# - vertical distance between the top of the feature line and the top of key_line
# - horizontal position (left-first) for lines with identical vertical position
feature_lines_sorted = sorted(
feature_lines, key=lambda line: (abs(line.rect.y0 - key_line.rect.y0), line.rect.x0)
)

return feature_lines_sorted

Expand Down

1 comment on commit a31eafa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/stratigraphy
   __init__.py8188%11
   extract.py1671670%3–446
   get_files.py19190%3–47
   main.py1261260%3–333
src/stratigraphy/benchmark
   metrics.py594229%22–25, 29–32, 36–39, 46–49, 53–54, 58, 65–74, 78–91, 96–133
src/stratigraphy/data_extractor
   data_extractor.py76495%32, 45, 120, 164
   utility.py6350%28–36
src/stratigraphy/depth
   a_to_b_interval_extractor.py371559%41–60, 79, 92
   depthcolumnentry_extractor.py23291%45–46
   interval.py1015249%25–28, 33–36, 42, 48, 52, 91–137, 158, 164–180
src/stratigraphy/depths_materials_column_pairs
   bounding_boxes.py301067%23, 32, 50, 60, 72–78
   material_description_rect_with_sidebar.py18856%27–40
src/stratigraphy/evaluation
   evaluation_dataclasses.py491178%52, 71–74, 90, 104, 125–131, 147
   groundwater_evaluator.py48198%77
   layer_evaluator.py664630%29–30, 35–39, 47, 69–95, 105–113, 128–149
   metadata_evaluator.py371462%46–65, 86–93
   utility.py16756%43–52
src/stratigraphy/groundwater
   groundwater_extraction.py1469038%52, 94, 137–148, 180–184, 199–215, 226–314, 335–363
   utility.py423614%10–17, 30–50, 62–76, 91–105
src/stratigraphy/layer
   layer.py371365%26, 29, 37, 52–72
src/stratigraphy/lines
   geometric_line_utilities.py86298%81, 131
   line.py51492%25, 50, 60, 110
   linesquadtree.py46198%75
src/stratigraphy/metadata
   coordinate_extraction.py106496%29, 93–94, 106
   elevation_extraction.py906033%34–39, 47, 55, 63, 79–87, 124–138, 150–153, 165–197, 212–220, 234–238
   language_detection.py181328%17–23, 37–45
   metadata.py662464%27, 83, 101–127, 146–155, 195–198, 206
src/stratigraphy/sidebar
   a_above_b_sidebar.py963959%40, 43, 58–66, 71, 78, 99, 104–111, 141–142, 184–225
   a_above_b_sidebar_validator.py411954%48, 58, 61, 63, 83–86, 111–129, 141–145
   a_to_b_sidebar.py431467%36, 49–50, 67, 95–108
   layer_identifier_sidebar.py462937%46–65, 81–97, 109, 122
   layer_identifier_sidebar_extractor.py292031%31–41, 55–75
   sidebar.py38392%41, 46, 87
   sidebarentry.py20385%27, 31, 43
src/stratigraphy/text
   description_block_splitter.py70297%24, 139
   extract_text.py29390%19, 53–54
   find_description.py41880%26–34, 111–114
   textblock.py901188%22, 27, 39, 44, 71, 79, 104, 116, 139, 160, 189
src/stratigraphy/util
   dataclasses.py32391%37–39
   predictions.py723453%72, 95–115, 143–187
   util.py341265%69–76, 90–92, 116–117
TOTAL238697559% 

Tests Skipped Failures Errors Time
101 0 💤 0 ❌ 0 🔥 7.623s ⏱️

Please sign in to comment.