From 60dac4370357e0fa352629fa1738965bc5feac05 Mon Sep 17 00:00:00 2001 From: sebastien curt <sebastien.curt@tetras-libre.fr> Date: Wed, 8 Jul 2020 12:25:47 +0200 Subject: [PATCH] Add test for issue --- .../fr/tetras_libre/unltools/unl/CatsUnl.java | 109 ++++++++- .../tetras_libre/unltools/unl/Issue13Unl.java | 208 ++++++++++++++++++ .../unltools/unl/UnlSentences.java | 15 ++ ...Issue13WithExpectedUnlDocumentChecker.java | 10 + .../unltools/unl/parser/UnlParserTest.java | 9 +- 5 files changed, 346 insertions(+), 5 deletions(-) create mode 100644 unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue13Unl.java create mode 100644 unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue13WithExpectedUnlDocumentChecker.java diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/CatsUnl.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/CatsUnl.java index 951f79d..9311784 100644 --- a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/CatsUnl.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/CatsUnl.java @@ -1,9 +1,12 @@ package fr.tetras_libre.unltools.unl; +import fr.tetras_libre.unltools.unl.builders.RestrictionOrientation; +import fr.tetras_libre.unltools.unl.builders.UnlDocumentNodeBuilder; + import java.util.*; public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements GraphImporter { - public static UnlDocumentNode buildSentenceNode() { + private static UnlDocumentNode CreateWithOldBuilder() { var graph = new Graph(); // mod @@ -62,6 +65,110 @@ public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements Gra return new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:00]", graph); } + private static UnlDocumentNode newBuilder(){ + return UnlDocumentNodeBuilder + .createBuilder() + .withNodeType(UnlDocumentNodeType.Sentence) + .withLabel("[S:00]") + .withGraph( + gb -> + gb.addGraphRelation( + grb -> grb + .label("mod") + .reference(":01") + .leftNode( + lnb -> + lnb + .universalWord( + uwb -> + uwb + .headWord("cat1") + .addTernaryTransitiveRestriction("icl", "feline", "thing", RestrictionOrientation.Right) + ) + .instanceNumber(":01") + .addAttribute(".@entry") + .addAttribute(".@def") + ) + .rightNode( + rnb -> rnb + .universalWord( + uwb -> + uwb + .headWord("black") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "adj") + ) + ) + ) + .addGraphRelation(grb -> + grb.label("and") + .reference(":01") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("cat1") + .addTernaryTransitiveRestriction("icl", "feline", "thing", RestrictionOrientation.Right) + ) + .instanceNumber(":01") + .addAttribute(".@entry") + .addAttribute(".@def") + ) + .rightNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("cat2") + .addTernaryTransitiveRestriction("icl", "feline", "thing", RestrictionOrientation.Right) + ) + .instanceNumber(":02") + .addAttribute(".@entry") + .addAttribute(".@def") + ) + ) + .addGraphRelation( + grb -> grb.label("mod") + .reference(":01") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("cat2") + .addTernaryTransitiveRestriction("icl", "feline", "thing", RestrictionOrientation.Right) + ) + .instanceNumber(":02") + .addAttribute(".@entry") + .addAttribute(".@def") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("white") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "adj") + ) + ) + ) + .addGraphRelation( + grb -> grb.label("agt") + .noReference() + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("eat") + .addTernaryTransitiveRestriction("icl", "consume", "do", RestrictionOrientation.Right) + .addSimpleRestriction("agt", RestrictionOrientation.Right, "living_thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "concrete_thing") + .addSimpleRestriction("ins", RestrictionOrientation.Right, "thing") + ) + .addAttribute(".@entry") + .addAttribute(".@pl") + .addAttribute(".@present") + .addAttribute(".@progress") + ) + .rightSubGraphNode( + rnb -> rnb.referenceNumber(":01") + .addAttribute(".@_hn-scope") + ) + ) + ) + .buildUnlDocumentNode(); + } + + public static UnlDocumentNode buildSentenceNode() { + return newBuilder(); + } + protected List<UnlDocument> buildUnlDocuments() { var unlDocument = new UnlDocument("[D]"); diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue13Unl.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue13Unl.java new file mode 100644 index 0000000..05c871b --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue13Unl.java @@ -0,0 +1,208 @@ +package fr.tetras_libre.unltools.unl; + +import fr.tetras_libre.unltools.unl.builders.RestrictionOrientation; +import fr.tetras_libre.unltools.unl.builders.UnlDocumentNodeBuilder; + +import java.util.Collections; +import java.util.List; + +public class Issue13Unl extends AbstractFlyweightUnlArgumentProvider { + private static UnlDocument unlDocument; + + public static UnlDocumentNode buildSentenceNode1() { + return UnlDocumentNodeBuilder + .createBuilder() + .withNodeType(UnlDocumentNodeType.Sentence) + .withLabel("[S:00]") + .withGraph(gb -> gb + // mod relation + .addGraphRelation(s -> + s.label("mod") + .noReference() + .leftNode( + ln -> ln + .universalWord(uwb -> uwb.headWord("m") + .addTernaryTransitiveRestriction("icl", "metric_linear_unit", "thing", RestrictionOrientation.Right) + .addSimpleRestriction("equ", RestrictionOrientation.Right, "meter") + ) + .addAttribute(".@entry") + .addAttribute(".@parenthesis")) + .rightNode( + rn -> rn + .simpleUniversalWord(() -> "=") + ) + ) + // second mod relation + .addGraphRelation(s -> + s + .label("mod") + .noReference() + .leftNode( + ln -> ln + .simpleUniversalWord( + () -> "=" + ) + ) + .rightNode( + rn -> rn + .universalWord( + uwb -> uwb + .headWord("mandatory") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "adj") + .addSimpleRestriction("equ", RestrictionOrientation.Right, "compulsory") + ) + .addAttribute(".@maiuscul") + ) + ) + // obj relation + .addGraphRelation( + s -> + s.label("obj") + .noReference() + .leftNode( + ln -> ln + .universalWord( + uw -> uw + .headWord("respect") + .addTernaryTransitiveRestriction("icl", "consider", "be", RestrictionOrientation.Right) + .addSimpleRestriction("rsn", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("aoj", RestrictionOrientation.Right, "person") + ) + .addAttribute(".@present") + .addAttribute(".@promise") + ) + .rightNode( + rn -> rn + .universalWord( + uw -> uw + .headWord("requirement") + .addTernaryTransitiveRestriction("icl", "duty", "thing", RestrictionOrientation.Right) + ) + .addAttribute(".@def") + .addAttribute(".@topic") + ) + ) + // cnt relation + .addGraphRelation( + s -> + s.label("cnt") + .noReference() + .leftNode( + lnb -> lnb + .universalWord( + uw -> uw + .headWord("mandatory") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "adj") + .addSimpleRestriction("equ", RestrictionOrientation.Right, "compulsory") + ) + .addAttribute(".@maiuscul") + ) + .rightNode( + rn -> rn + .universalWord( + uwb -> uwb + .headWord("respect") + .addTernaryTransitiveRestriction("icl", "consider", "be", RestrictionOrientation.Right) + .addSimpleRestriction("rsn", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("aoj", RestrictionOrientation.Right, "person") + ) + .addAttribute(".@present") + .addAttribute(".@promise") + ) + ) + // mod + .addGraphRelation( + s -> + s.label("mod") + .noReference() + .leftNode( + ln -> ln + .universalWord( + uwb -> uwb + .headWord("application") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "information") + .addSimpleRestriction("equ", RestrictionOrientation.Right, "request") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "uw") + ) + ) + .rightNode( + rn -> rn + .universalWord( + uwb -> uwb + .headWord("every") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "quantity") + .addSimpleRestriction("per", RestrictionOrientation.Right, "thing") + ) + ) + ) + // mod + .addGraphRelation( + s -> s + .label("mod") + .noReference() + .leftNode( + ln -> ln + .universalWord( + uwb -> uwb + .headWord("application") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "information") + .addSimpleRestriction("equ", RestrictionOrientation.Right, "request") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "uw") + ) + ) + .rightNode( + rn -> rn + .simpleUniversalWord( + () -> "etcs" + ) + ) + ) + .addGraphRelation( + s -> + s + .label("scn") + .noReference() + .leftNode( + ln -> ln + .universalWord( + uwb -> uwb + .headWord("respect") + .addTernaryTransitiveRestriction("icl", "consider", "be", RestrictionOrientation.Right) + .addSimpleRestriction("rsn", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("aoj", RestrictionOrientation.Right, "person") + ) + .addAttribute(".@present") + .addAttribute(".@promise") + ) + .rightNode( + rn -> rn + .universalWord( + uwb -> uwb + .headWord("application") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "information") + .addSimpleRestriction("equ", RestrictionOrientation.Right, "request") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "uw") + ) + ) + ) + ) + .buildUnlDocumentNode(); + + } + + + @Override + protected List<UnlDocument> buildUnlDocuments() { + if (null == Issue13Unl.unlDocument) { + Issue13Unl.unlDocument = new UnlDocument(); + Issue13Unl.unlDocument.add(buildSentenceNode1()); + } + return Collections.singletonList(Issue13Unl.unlDocument); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/UnlSentences.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/UnlSentences.java index 6c4c525..50d9ee9 100644 --- a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/UnlSentences.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/UnlSentences.java @@ -93,4 +93,19 @@ public class UnlSentences { "{/unl}\n" + "[/S]\n" + "[/D]"; + + public static final String Issue13 = "[S:00]\n" + + "{org:en}\n" + + "(M) = Mandatory:The requirement shall be respected in every ETCS application. \n" + + "{/org}\n" + + "{unl}\n" + + "mod(m(icl>metric_linear_unit>thing,equ>meter).@entry.@parenthesis,=)\n" + + "mod(=,mandatory(icl>adj,equ>compulsory).@maiuscul)\n" + + "obj(respect(icl>consider>be,rsn>thing,obj>thing,aoj>person).@present.@promise,requirement(icl>duty>thing).@def.@topic)\n" + + "cnt(mandatory(icl>adj,equ>compulsory).@maiuscul,respect(icl>consider>be,rsn>thing,obj>thing,aoj>person).@present.@promise)\n" + + "mod(application(icl>information,equ>request,agt>thing,obj>uw),every(icl>quantity,per>thing))\n" + + "mod(application(icl>information,equ>request,agt>thing,obj>uw),etcs)\n" + + "scn(respect(icl>consider>be,rsn>thing,obj>thing,aoj>person).@present.@promise,application(icl>information,equ>request,agt>thing,obj>uw))\n" + + "{/unl}\n" + + "[/S]\n"; } diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue13WithExpectedUnlDocumentChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue13WithExpectedUnlDocumentChecker.java new file mode 100644 index 0000000..85a99cd --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue13WithExpectedUnlDocumentChecker.java @@ -0,0 +1,10 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.Issue13Unl; +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class Issue13WithExpectedUnlDocumentChecker extends SentenceWithExpectedUnlDocumentsChecker { + public Issue13WithExpectedUnlDocumentChecker() { + super(UnlSentences.Issue13, new Issue13Unl().getUnlDocuments()); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserTest.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserTest.java index 7bc9410..4c77e1f 100644 --- a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserTest.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserTest.java @@ -14,13 +14,14 @@ class UnlParserTest { private static Stream<SentenceWithExpectedUnlDocumentsChecker> unlParserShouldParseSentenceAndGetExpectedUnlDocuments() { return Stream.of(new R1SentenceWithExpectedUnlDocumentsChecker(), - new R2SentenceWithExpectedUnlDocumentsChecker(), - new CatsSentenceWithExpectedUnlDocumentsChecker(), - new AllSentenceWithExpectedUnlDocumentsChecker()); + new R2SentenceWithExpectedUnlDocumentsChecker(), + new CatsSentenceWithExpectedUnlDocumentsChecker(), + new AllSentenceWithExpectedUnlDocumentsChecker(), + new Issue13WithExpectedUnlDocumentChecker()); } @ParameterizedTest - @ValueSource(strings = {UnlSentences.R1, UnlSentences.R2, UnlSentences.Cats, UnlSentences.All}) + @ValueSource(strings = {UnlSentences.R1, UnlSentences.R2, UnlSentences.Cats, UnlSentences.All, UnlSentences.Issue13}) void unlParserShouldParseSimpleSentenceWithoutException(String input) { UnlParserFactory unlFactory = new UnlParserFactoryFromString(input); var wrapper = createAndCheckUnlParserValidity(unlFactory); -- GitLab