Skip to content

Commit

Permalink
Bug fix/fix tutorials (#25)
Browse files Browse the repository at this point in the history
* fix: Fix tutorials

* fix: Fix tutorials

---------

Co-authored-by: Romuald Rousseau <[email protected]>
  • Loading branch information
RomualdRousseau and Romuald Rousseau authored Oct 17, 2024
1 parent 069b877 commit adb5d96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -21,33 +20,24 @@ 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();

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());
}));
}
}

private LayexTableParser customTableParser() {
return new LayexTableParser(
List.of("(v.$)+"),
List.of("(()(S+$))(()([/^TOTAL/|v].+$)())+(/TOTAL/.+$)"));
}

private List<String> customEntities(final List<String> entities) {
final var result = new ArrayList<String>(entities);
result.add("PRODUCTNAME");
result.remove("PACKAGE");
result.add(0, "PRODUCTNAME");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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<String> customEntities(final List<String> entities) {
final var result = new ArrayList<String>(entities);
result.add("PRODUCTNAME");
result.remove("PACKAGE");
result.add(0, "PRODUCTNAME");
return result;
}

Expand Down

0 comments on commit adb5d96

Please sign in to comment.