Skip to content
Snippets Groups Projects
Commit 60dac437 authored by Sebastien's avatar Sebastien
Browse files

Add test for issue

parent 897b98b4
No related branches found
No related tags found
1 merge request!10Resolve "Lexical Error"
package fr.tetras_libre.unltools.unl; 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.*; import java.util.*;
public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements GraphImporter { public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements GraphImporter {
public static UnlDocumentNode buildSentenceNode() { private static UnlDocumentNode CreateWithOldBuilder() {
var graph = new Graph(); var graph = new Graph();
// mod // mod
...@@ -62,6 +65,110 @@ public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements Gra ...@@ -62,6 +65,110 @@ public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements Gra
return new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:00]", graph); 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() { protected List<UnlDocument> buildUnlDocuments() {
var unlDocument = new UnlDocument("[D]"); var unlDocument = new UnlDocument("[D]");
......
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);
}
}
...@@ -93,4 +93,19 @@ public class UnlSentences { ...@@ -93,4 +93,19 @@ public class UnlSentences {
"{/unl}\n" + "{/unl}\n" +
"[/S]\n" + "[/S]\n" +
"[/D]"; "[/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";
} }
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());
}
}
...@@ -16,11 +16,12 @@ class UnlParserTest { ...@@ -16,11 +16,12 @@ class UnlParserTest {
return Stream.of(new R1SentenceWithExpectedUnlDocumentsChecker(), return Stream.of(new R1SentenceWithExpectedUnlDocumentsChecker(),
new R2SentenceWithExpectedUnlDocumentsChecker(), new R2SentenceWithExpectedUnlDocumentsChecker(),
new CatsSentenceWithExpectedUnlDocumentsChecker(), new CatsSentenceWithExpectedUnlDocumentsChecker(),
new AllSentenceWithExpectedUnlDocumentsChecker()); new AllSentenceWithExpectedUnlDocumentsChecker(),
new Issue13WithExpectedUnlDocumentChecker());
} }
@ParameterizedTest @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) { void unlParserShouldParseSimpleSentenceWithoutException(String input) {
UnlParserFactory unlFactory = new UnlParserFactoryFromString(input); UnlParserFactory unlFactory = new UnlParserFactoryFromString(input);
var wrapper = createAndCheckUnlParserValidity(unlFactory); var wrapper = createAndCheckUnlParserValidity(unlFactory);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment