From adb5d960f03b0477f204307eb6ff0c1ce43b1057 Mon Sep 17 00:00:00 2001 From: Romuald Rousseau Date: Thu, 17 Oct 2024 22:52:34 +0800 Subject: [PATCH] Bug fix/fix tutorials (#25) * fix: Fix tutorials * fix: Fix tutorials --------- Co-authored-by: Romuald Rousseau --- .../archery/examples/Tutorial2.java | 14 ++------------ .../archery/examples/Tutorial3.java | 9 ++++----- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial2.java b/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial2.java index a33f1424..116add0f 100644 --- a/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial2.java +++ b/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial2.java @@ -8,7 +8,6 @@ import com.github.romualdrousseau.archery.Document; import com.github.romualdrousseau.archery.DocumentFactory; -import com.github.romualdrousseau.archery.parser.LayexTableParser; public class Tutorial2 implements Runnable { @@ -21,7 +20,6 @@ public void run() { final var builder = Common.loadModelBuilderFromGitHub("sales-english"); final var model = builder - .setTableParser(this.customTableParser()) .setEntityList(this.customEntities(builder.getEntityList())) .setPatternMap(this.customPatternMap(builder.getPatternMap())) .build(); @@ -29,8 +27,7 @@ public void run() { final var file = Common.loadData("document with multiple tables.xlsx", this.getClass()); try (final var doc = DocumentFactory.createInstance(file, "UTF-8") .setModel(model) - .setHints(EnumSet.of(Document.Hint.INTELLI_LAYOUT)) - .setRecipe("sheet.setCapillarityThreshold(0)")) { + .setHints(EnumSet.of(Document.Hint.INTELLI_LAYOUT))) { doc.sheets().forEach(s -> Common.addSheetDebugger(s).getTable().ifPresent(t -> { Common.printHeaders(t.headers()); Common.printRows(t.rows()); @@ -38,16 +35,9 @@ public void run() { } } - private LayexTableParser customTableParser() { - return new LayexTableParser( - List.of("(v.$)+"), - List.of("(()(S+$))(()([/^TOTAL/|v].+$)())+(/TOTAL/.+$)")); - } - private List customEntities(final List entities) { final var result = new ArrayList(entities); - result.add("PRODUCTNAME"); - result.remove("PACKAGE"); + result.add(0, "PRODUCTNAME"); return result; } diff --git a/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial3.java b/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial3.java index 70a443b6..77c4afce 100644 --- a/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial3.java +++ b/archery-examples/src/main/java/com/github/romualdrousseau/archery/examples/Tutorial3.java @@ -30,7 +30,7 @@ public void run() { try (final var doc = DocumentFactory.createInstance(file, "UTF-8") .setModel(model) .setHints(EnumSet.of(Document.Hint.INTELLI_LAYOUT)) - .setRecipe("sheet.setCapillarityThreshold(0)")) { + .setRecipe("sheet.setCapillarityThreshold(1)")) { doc.sheets().forEach(s -> Common.addSheetDebugger(s).getTable().ifPresent(t -> { Common.printHeaders(t.headers()); @@ -41,14 +41,13 @@ public void run() { private LayexTableParser customTableParser() { return new LayexTableParser( - List.of("(v.$)+"), - List.of("(()(S+$))(()([/^TOTAL/|v].+$)())+(/TOTAL/.+$)")); + List.of("((v)(S)$)+"), + List.of("((e.+$)?(v+$))(()([/^TOTAL/|v].+$)())+(/TOTAL/.+$)")); } private List customEntities(final List entities) { final var result = new ArrayList(entities); - result.add("PRODUCTNAME"); - result.remove("PACKAGE"); + result.add(0, "PRODUCTNAME"); return result; }