diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index c87e8c500e9c1df3b5948f5b8df266ba8206ed75..c5d1b8d88f65de64cf421b74b6b0d5d9e6ed7773 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -1,15 +1,25 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="RemoteRepositoriesConfiguration"> + <remote-repository> + <option name="id" value="central" /> + <option name="name" value="Central Repository" /> + <option name="url" value="https://repo.maven.apache.org/maven2" /> + </remote-repository> + <remote-repository> + <option name="id" value="tetra_central" /> + <option name="name" value="Tetras Central" /> + <option name="url" value="file:////Users/scurt/.m2/tetrasArtifacts/repository" /> + </remote-repository> <remote-repository> <option name="id" value="tetra_central" /> <option name="name" value="Tetras Central" /> <option name="url" value="file:////Users/scurt/.m2/tetrasArtifacts-unl" /> </remote-repository> <remote-repository> - <option name="id" value="central" /> - <option name="name" value="Central Repository" /> - <option name="url" value="https://repo.maven.apache.org/maven2" /> + <option name="id" value="tetra_central" /> + <option name="name" value="Tetras Central" /> + <option name="url" value="file:///C:\Users\curts/.m2/tetrasArtifacts-unl" /> </remote-repository> <remote-repository> <option name="id" value="central" /> @@ -19,7 +29,7 @@ <remote-repository> <option name="id" value="tetra_central" /> <option name="name" value="Tetras Central" /> - <option name="url" value="file:////Users/scurt/.m2/tetrasArtifacts/repository" /> + <option name="url" value="file:///C:\Users\curts\.m2\tetrasArtifacts-unl" /> </remote-repository> <remote-repository> <option name="id" value="jboss.community" /> diff --git a/Examples/issue12.txt b/Examples/issue12.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb0b341d1d45e92bf69711d82db4fdfbd9a8ca8d --- /dev/null +++ b/Examples/issue12.txt @@ -0,0 +1,59 @@ +[D] +[S:00] +{org:en} +This document defines the functional requirements for ERTMS/ETCS (EUROPEAN RAIL TRAFFIC MANAGEMENT SYSTEM / EUROPEAN TRAIN CONTROL SYSTEM). +{/org} +{unl} +mod(document(icl>writing>thing),this(icl>determiner>adj,mod<concrete_thing)) +aoj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,document(icl>writing>thing)) +mod(requirement(icl>duty>thing).@def.@pl,functional(icl>adj,ant>nonfunctional)) +obj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,requirement(icl>duty>thing).@def.@pl) +or(etcs,ertms) +pur(requirement(icl>duty>thing).@def.@pl,etcs) +mod:01(management(icl>action,agt>volitional_thing,obj>thing),traffic(icl>collection>thing)) +mod(:03.@_hn-scope,management(icl>action,agt>volitional_thing,obj>thing)) +or:03(european(icl>inhabitant>person).@entry,system(icl>group>thing):01.@entry) +mod:01(control(icl>power>thing),train(icl>public_transport>thing)) +mod:01(system(icl>group>thing):02,control(icl>power>thing)) +agt:02(rail(icl>complain>do,rsn>thing,agt>volitional_thing).@entry.@present,:01.@entry.@parenthesis) +rsn:02(rail(icl>complain>do,rsn>thing,agt>volitional_thing).@entry.@present,:01.@entry.@parenthesis) +shd(etcs,:02) +mod(train(icl>public_transport>thing),:03.@_hn-scope) +{/unl} +[/S] +[S:00] +{org:en} +The document primarily defines the operational requirements and therefore contains only a few technical terms. +{/org} +{unl} +aoj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,document(icl>writing>thing).@def) +man(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,primarily(icl>how,equ>mainly)) +and(:01,define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present) +mod(requirement(icl>duty>thing).@def.@pl,operational(icl>adj,com>operation)) +obj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,requirement(icl>duty>thing).@def.@pl) +man:01(contain(icl>be,equ>comprise,obj>abstract_thing,aoj>information,pur>abstract_thing).@entry.@present,therefore(icl>how)) +man:01(term(icl>word>thing,mod>thing).@pl,only(icl>how,equ>recently)) +qua:01(term(icl>word>thing,mod>thing).@pl,a_few(icl>adj,equ>some,qua<thing)) +mod:01(term(icl>word>thing,mod>thing).@pl,technical(icl>adj,ant>nontechnical)) +obj:01(contain(icl>be,equ>comprise,obj>abstract_thing,aoj>information,pur>abstract_thing).@entry.@present,term(icl>word>thing,mod>thing).@pl) +{/unl} +[/S] +[S:00] +{org:en} +For consistency reasons, all functional requirements not implemented in the SRS 2.3.0 have been removed from this version.. +{/org} +{unl} +agt:01(reason(icl>persuade>do,agt>thing,gol>uw,rec>person).@entry.@present,consistency(icl>uniformity>thing,ant>inconsistency)) +qua:02(requirement(icl>duty>thing).@pl,all(icl>quantity,ant>some,per>thing)) +mod:02(requirement(icl>duty>thing).@pl,functional(icl>adj,ant>nonfunctional)) +agt:02(implement(icl>employ>do,agt>thing,obj>thing).@past.@not,requirement(icl>duty>thing).@pl) +plc(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,srs.@def) +obj(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,"2.3".@topic) +mod("2.3".@topic,".0") +mod(version(icl>interpretation>abstract_thing,agt>thing,obj>uw),this(icl>determiner>adj,mod<concrete_thing)) +plf(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,version(icl>interpretation>abstract_thing,agt>thing,obj>uw)) +and(implement(icl>employ>do,agt>thing,obj>thing).@past.@not,:01) +rsn(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,:02) +{/unl} +[/S] +[/D] \ No newline at end of file diff --git a/pom.xml b/pom.xml index ab85d7818315d972b01eb3b16fcfd8f21c48495c..bc1964ec37cc5926b26869789dd1d82ff80015b3 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ </snapshots> <id>tetra_central</id> <name>Tetras Central</name> - <url>file:///${user.home}/.m2/tetrasArtifacts-unl</url> + <url>file:///${user.home}\.m2\tetrasArtifacts-unl</url> </repository> </repositories> diff --git a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java index 62ed3433b85252679ebb70ff5cd605ee980ff57e..60af88c6947e76809202269368710e7fa21b1264 100644 --- a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java +++ b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java @@ -2,6 +2,7 @@ package fr.tetras_libre.unltools.Convert; import fr.tetras_libre.unltools.cqrs.CommandHandler; import fr.tetras_libre.unltools.cqrs.Result; +import fr.tetras_libre.unltools.unl.GraphExportException; import fr.tetras_libre.unltools.unl.GraphExporterFactory; import java.io.IOException; @@ -18,7 +19,9 @@ public class ExportUnlDocumentsHandler implements CommandHandler<ExportUnlDocume try { var graphExporter = factory.createGraphExporter(command.getWriter(), command.getExporterName()); graphExporter.write(command.getGraphImporter().Import()); - } catch (IOException e) { + command.getWriter().flush(); + command.getWriter().close(); + } catch (IOException | GraphExportException e) { return Result.Failure(String.format("Cannot export unl documents to format '%s'", command.getExporterName()), e); } diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java index 33197d0d85d44bd13ac62076a486991bb149b41d..66dfed1bbf5967afaa5aaaa63f45e4699bb889b2 100644 --- a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java @@ -81,6 +81,15 @@ public class Graph { int i = 0; GraphNode graphNode = null; + while ((i < this.nodes.size()) && (null == graphNode)) { + var node = this.nodes.get(i); + if(graphNumber.equals(node.getNodeId()) && node.isEntryNode()){ + return node; + } + i++; + } + + i=0; while ((i < relations.size()) && (null == graphNode)) { graphNode = getEntryNode(this.relations.get(i), graphNumber); i++; diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExportException.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExportException.java new file mode 100644 index 0000000000000000000000000000000000000000..a1545794baf3b2867135fc60dc1334e7e10578e8 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExportException.java @@ -0,0 +1,19 @@ +package fr.tetras_libre.unltools.unl; + +public class GraphExportException extends Exception { + public GraphExportException() { + super(); + } + + public GraphExportException(String message) { + super(message); + } + + public GraphExportException(String message, Throwable cause) { + super(message, cause); + } + + public GraphExportException(Throwable cause) { + super(cause); + } +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java index a61a61ba3548037645d64010e632c4d9f390e55a..4507799f3a2ced4e94598457063712caf072baed 100644 --- a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java @@ -4,5 +4,5 @@ import java.io.IOException; import java.util.List; public interface GraphExporter { - void write(List<UnlDocument> g) throws IOException; + void write(List<UnlDocument> g) throws IOException, GraphExportException; } diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/builders/GraphRelationBuilder.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/builders/GraphRelationBuilder.java index 85ce4803b3750c363791fa5ae779c9c3346fa151..a9e747c1bf271466f1e152a380aa3a24ec218bef 100644 --- a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/builders/GraphRelationBuilder.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/builders/GraphRelationBuilder.java @@ -30,7 +30,7 @@ public class GraphRelationBuilder { public interface RequiredLeftNode { RequiredRightNode leftNode(Function<UniversalWordNodeBuilder.IRequiredUniversalWord, UniversalWordNodeBuilder.IBuild> f); - IBuild rightSubGraphNode(Function<SubGraphReferenceNodeBuilder.IRequiredReferenceNumber, SubGraphReferenceNodeBuilder.IBuild> f); + RequiredRightNode leftSubGraphNode(Function<SubGraphReferenceNodeBuilder.IRequiredReferenceNumber, SubGraphReferenceNodeBuilder.IBuild> f); } public interface RequiredRightNode { @@ -69,8 +69,8 @@ public class GraphRelationBuilder { } @Override - public IBuild rightSubGraphNode(Function<SubGraphReferenceNodeBuilder.IRequiredReferenceNumber, SubGraphReferenceNodeBuilder.IBuild> f) { - instance.node2 = f.apply(SubGraphReferenceNodeBuilder.createBuilder()).buildSubGraphReferenceNode(); + public RequiredRightNode leftSubGraphNode(Function<SubGraphReferenceNodeBuilder.IRequiredReferenceNumber, SubGraphReferenceNodeBuilder.IBuild> f) { + instance.node1 = f.apply(SubGraphReferenceNodeBuilder.createBuilder()).buildSubGraphReferenceNode(); return this; } @@ -90,5 +90,11 @@ public class GraphRelationBuilder { instance.node2 = f.apply(UniversalWordNodeBuilder.createBuilder()).buildUniversalWordNode(); return this; } + + @Override + public IBuild rightSubGraphNode(Function<SubGraphReferenceNodeBuilder.IRequiredReferenceNumber, SubGraphReferenceNodeBuilder.IBuild> f) { + instance.node2 = f.apply(SubGraphReferenceNodeBuilder.createBuilder()).buildSubGraphReferenceNode(); + return this; + } } } diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java index 77105988e8891fe7eb1494c935e0d029715b39fa..55027061d1a28e090bd22526d3080af08eb77b45 100644 --- a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java @@ -23,11 +23,12 @@ public class DotFileGraphExporter implements GraphExporter { } - private void write(Graph g) throws IOException { + private void write(Graph g) throws IOException, GraphExportException { try { this.InternalWrite(g); } catch (NoEntryNodeException e) { // TODO : to define what to do here + throw new GraphExportException("Unable to export graph due to unknown node relation", e); } } @@ -190,7 +191,7 @@ public class DotFileGraphExporter implements GraphExporter { } @Override - public void write(List<UnlDocument> documents) throws IOException { + public void write(List<UnlDocument> documents) throws IOException, GraphExportException { for (var document : documents) { for (var documentNode : document.getDocElements()) { this.write(documentNode.getGraph()); diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java index f293807504a8bc545bdd7fa27ee2f18c7c2d8518..386380fb5fa7f10dd9c5d1dadaaf234f4df2d50a 100644 --- a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java @@ -22,8 +22,9 @@ public class UnlGraphImporterFromUnlParser implements GraphImporter { @Override public List<UnlDocument> Import() { if (documents == null) { + var documentParser = new UnlParser(this.bufferedReader); try { - documents = new UnlParser(this.bufferedReader).createUnlDocumentList(); + documents = documentParser.createUnlDocumentList(); } catch (ParseException e) { e.printStackTrace(); } diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue12Unl.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue12Unl.java new file mode 100644 index 0000000000000000000000000000000000000000..4be29b0b88ecd43538c54f32b3d27cd847eea05f --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/Issue12Unl.java @@ -0,0 +1,300 @@ +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 Issue12Unl extends AbstractFlyweightUnlArgumentProvider { + + private UnlDocumentNode createUnlDocumentNode() { + return null; + } + + private UnlDocumentNode createSentence1() { + return UnlDocumentNodeBuilder + .createBuilder() + .withNodeType(UnlDocumentNodeType.Sentence) + .withLabel("[S:00]") + .withGraph( + gb -> + gb.addGraphRelation( + grb -> grb.label("mod") + .noReference() + .leftNode( + lnb -> + lnb.universalWord( + uwb -> uwb.headWord("document") + .addTernaryTransitiveRestriction("icl", "writing", "thing", RestrictionOrientation.Right) + ) + ) + .rightNode( + lnb -> + lnb.universalWord( + uwb -> uwb.headWord("this") + .addTernaryTransitiveRestriction("icl", "determiner", "adj", RestrictionOrientation.Right) + .addSimpleRestriction("mod", RestrictionOrientation.Left, "concrete_thing") + ) + ) + ) + .addGraphRelation( + grb -> grb.label("aoj") + .noReference() + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("define") + .addTernaryTransitiveRestriction("icl", "characterize", "be", RestrictionOrientation.Right) + .addSimpleRestriction("obj", RestrictionOrientation.Right, "uw") + .addSimpleRestriction("aoj", RestrictionOrientation.Right, "thing") + ) + .addAttribute(".@entry") + .addAttribute(".@present") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("document") + .addTernaryTransitiveRestriction("icl", "writing", "thing", RestrictionOrientation.Right) + ) + ) + ) + .addGraphRelation( + grb -> grb.label("mod") + .noReference() + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("requirement") + .addTernaryTransitiveRestriction("icl", "duty", "thing", RestrictionOrientation.Right) + ) + .addAttribute(".@def") + .addAttribute(".@pl") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("functional") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "adj") + .addSimpleRestriction("ant", RestrictionOrientation.Right, "nonfunctional") + ) + ) + ) + .addGraphRelation( + grb -> + grb.label("obj") + .noReference() + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("define") + .addTernaryTransitiveRestriction("icl", "characterize", "be", RestrictionOrientation.Right) + .addSimpleRestriction("obj", RestrictionOrientation.Right, "uw") + .addSimpleRestriction("aoj", RestrictionOrientation.Right, "thing") + ) + .addAttribute(".@entry") + .addAttribute(".@present") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("requirement") + .addTernaryTransitiveRestriction("icl", "duty", "thing", RestrictionOrientation.Right) + ) + .addAttribute(".@def") + .addAttribute(".@pl") + ) + ) + .addGraphRelation( + grb -> grb.label("or") + .noReference() + .leftNode( + lnb -> lnb.simpleUniversalWord(() -> "etcs") + ) + .rightNode( + rnb -> rnb.simpleUniversalWord(() -> "ertms") + ) + ) + .addGraphRelation( + grb -> grb.label("pur") + .noReference() + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("requirement") + .addTernaryTransitiveRestriction("icl", "duty", "thing", RestrictionOrientation.Right) + ) + .addAttribute(".@def") + .addAttribute(".@pl") + ) + .rightNode( + rnb -> rnb.simpleUniversalWord(() -> "etcs") + ) + ) + .addGraphRelation( + grb -> + grb.label("mod") + .reference(":01") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("management") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "action") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "volitional_thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "thing") + ) + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("traffic") + .addTernaryTransitiveRestriction("icl", "collection", "thing", RestrictionOrientation.Right) + ) + ) + ) + .addGraphRelation( + grb -> grb.label("mod") + .noReference() + .leftSubGraphNode( + lsgrb -> lsgrb.referenceNumber(":03") + .addAttribute(".@_hn-scope") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("management") + .addSimpleRestriction("icl", RestrictionOrientation.Right, "action") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "volitional_thing") + .addSimpleRestriction("obj", RestrictionOrientation.Right, "thing") + ) + ) + ) + .addGraphRelation( + grb -> grb.label("or") + .reference(":03") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("european") + .addTernaryTransitiveRestriction("icl", "inhabitant", "person", RestrictionOrientation.Right) + ) + .addAttribute(".@entry") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("system") + .addTernaryTransitiveRestriction("icl", "group", "thing", RestrictionOrientation.Right) + ) + .instanceNumber(":01") + .addAttribute(".@entry") + ) + ) + .addGraphRelation( + grb -> grb.label("mod") + .reference(":01") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("control") + .addTernaryTransitiveRestriction("icl", "power", "thing", RestrictionOrientation.Right) + ) + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("train") + .addTernaryTransitiveRestriction("icl", "public_transport", "thing", RestrictionOrientation.Right) + + ) + ) + ) + .addGraphRelation( + grb -> grb.label("mod") + .reference(":01") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("system") + .addTernaryTransitiveRestriction("icl", "group", "thing", RestrictionOrientation.Right) + ) + .instanceNumber(":02") + ) + .rightNode( + rnb -> rnb.universalWord( + uwb -> uwb.headWord("control") + .addTernaryTransitiveRestriction("icl", "power", "thing", RestrictionOrientation.Right) + ) + ) + ) + .addGraphRelation( + grb -> grb.label("agt") + .reference(":02") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("rail") + .addTernaryTransitiveRestriction("icl", "complain", "do", RestrictionOrientation.Right) + .addSimpleRestriction("rsn", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "volitional_thing") + ) + .addAttribute(".@entry") + .addAttribute(".@present") + ) + .rightSubGraphNode( + sgnb -> sgnb.referenceNumber(":01") + .addAttribute(".@entry") + .addAttribute(".@parenthesis") + ) + ) + .addGraphRelation( + grb -> grb.label("rsn") + .reference(":02") + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("rail") + .addTernaryTransitiveRestriction("icl", "complain", "do", RestrictionOrientation.Right) + .addSimpleRestriction("rsn", RestrictionOrientation.Right, "thing") + .addSimpleRestriction("agt", RestrictionOrientation.Right, "volitional_thing") + ) + .addAttribute(".@entry") + .addAttribute(".@present") + ) + .rightSubGraphNode( + rsngb -> rsngb.referenceNumber(":01") + .addAttribute(".@entry") + .addAttribute(".@parenthesis") + ) + ) + .addGraphRelation( + grb -> grb.label("shd") + .noReference() + .leftNode( + lnb -> lnb.simpleUniversalWord(() -> "etcs") + ) + .rightSubGraphNode( + rsgnb -> rsgnb.referenceNumber(":02") + ) + ) + .addGraphRelation( + grb -> grb.label("mod") + .noReference() + .leftNode( + lnb -> lnb.universalWord( + uwb -> uwb.headWord("train") + .addTernaryTransitiveRestriction("icl", "public_transport", "thing", RestrictionOrientation.Right) + ) + ) + .rightSubGraphNode( + rsgnb -> rsgnb.referenceNumber(":03") + .addAttribute(".@_hn-scope") + ) + ) + ) + .buildUnlDocumentNode(); + } + + private UnlDocumentNode createSentence2() { + return null; + } + + private UnlDocumentNode createSentence3() { + return null; + } + + @Override + protected List<UnlDocument> buildUnlDocuments() { + var unlDocument = new UnlDocument("[D]"); + + UnlDocumentNode unlDocumentNode = createSentence1(); + + unlDocument.add(unlDocumentNode); + + return Collections.singletonList(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 6c4c52527cd1caedf7d7090a10d26d500f7080bb..555be8e6cc63ea8952d4bf1b149170ee4cb9715d 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,64 @@ public class UnlSentences { "{/unl}\n" + "[/S]\n" + "[/D]"; + + public static final String Issue12 = "[D]\n" + + "[S:00]\n" + + "{org:en}\n" + + "This document defines the functional requirements for ERTMS/ETCS (EUROPEAN RAIL TRAFFIC MANAGEMENT SYSTEM / EUROPEAN TRAIN CONTROL SYSTEM).\n" + + "{/org}\n" + + "{unl}\n" + + "mod(document(icl>writing>thing),this(icl>determiner>adj,mod<concrete_thing))\n" + + "aoj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,document(icl>writing>thing))\n" + + "mod(requirement(icl>duty>thing).@def.@pl,functional(icl>adj,ant>nonfunctional))\n" + + "obj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,requirement(icl>duty>thing).@def.@pl)\n" + + "or(etcs,ertms)\n" + + "pur(requirement(icl>duty>thing).@def.@pl,etcs)\n" + + "mod:01(management(icl>action,agt>volitional_thing,obj>thing),traffic(icl>collection>thing))\n" + + "mod(:03.@_hn-scope,management(icl>action,agt>volitional_thing,obj>thing))\n" + + "or:03(european(icl>inhabitant>person).@entry,system(icl>group>thing):01.@entry)\n" + + "mod:01(control(icl>power>thing),train(icl>public_transport>thing))\n" + + "mod:01(system(icl>group>thing):02,control(icl>power>thing))\n" + + "agt:02(rail(icl>complain>do,rsn>thing,agt>volitional_thing).@entry.@present,:01.@entry.@parenthesis)\n" + + "rsn:02(rail(icl>complain>do,rsn>thing,agt>volitional_thing).@entry.@present,:01.@entry.@parenthesis)\n" + + "shd(etcs,:02)\n" + + "mod(train(icl>public_transport>thing),:03.@_hn-scope)\n" + + "{/unl}\n" + + "[/S]\n" + +// "[S:00]\n" + +// "{org:en}\n" + +// "The document primarily defines the operational requirements and therefore contains only a few technical terms.\n" + +// "{/org}\n" + +// "{unl}\n" + +// "aoj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,document(icl>writing>thing).@def)\n" + +// "man(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,primarily(icl>how,equ>mainly))\n" + +// "and(:01,define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present)\n" + +// "mod(requirement(icl>duty>thing).@def.@pl,operational(icl>adj,com>operation))\n" + +// "obj(define(icl>characterize>be,obj>uw,aoj>thing).@entry.@present,requirement(icl>duty>thing).@def.@pl)\n" + +// "man:01(contain(icl>be,equ>comprise,obj>abstract_thing,aoj>information,pur>abstract_thing).@entry.@present,therefore(icl>how))\n" + +// "man:01(term(icl>word>thing,mod>thing).@pl,only(icl>how,equ>recently))\n" + +// "qua:01(term(icl>word>thing,mod>thing).@pl,a_few(icl>adj,equ>some,qua<thing))\n" + +// "mod:01(term(icl>word>thing,mod>thing).@pl,technical(icl>adj,ant>nontechnical))\n" + +// "obj:01(contain(icl>be,equ>comprise,obj>abstract_thing,aoj>information,pur>abstract_thing).@entry.@present,term(icl>word>thing,mod>thing).@pl)\n" + +// "{/unl}\n" + +// "[/S]\n" + +// "[S:00]\n" + +// "{org:en}\n" + +// "For consistency reasons, all functional requirements not implemented in the SRS 2.3.0 have been removed from this version..\n" + +// "{/org}\n" + +// "{unl}\n" + +// "agt:01(reason(icl>persuade>do,agt>thing,gol>uw,rec>person).@entry.@present,consistency(icl>uniformity>thing,ant>inconsistency))\n" + +// "qua:02(requirement(icl>duty>thing).@pl,all(icl>quantity,ant>some,per>thing))\n" + +// "mod:02(requirement(icl>duty>thing).@pl,functional(icl>adj,ant>nonfunctional))\n" + +// "agt:02(implement(icl>employ>do,agt>thing,obj>thing).@past.@not,requirement(icl>duty>thing).@pl)\n" + +// "plc(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,srs.@def)\n" + +// "obj(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,\"2.3\".@topic)\n" + +// "mod(\"2.3\".@topic,\".0\")\n" + +// "mod(version(icl>interpretation>abstract_thing,agt>thing,obj>uw),this(icl>determiner>adj,mod<concrete_thing))\n" + +// "plf(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,version(icl>interpretation>abstract_thing,agt>thing,obj>uw))\n" + +// "and(implement(icl>employ>do,agt>thing,obj>thing).@past.@not,:01)\n" + +// "rsn(remove(icl>dismiss>do,plf>thing,agt>volitional_thing,obj>person).@entry.@present.@complete,:02)\n" + +// "{/unl}\n" + +// "[/S]\n" + + "[/D]"; } diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileBuilderTest.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileBuilderTest.java index daba156b658c145b6815099d0f69851f5130489f..b0d5130e9d4d4df7384482a854c80d75d22e0df5 100644 --- a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileBuilderTest.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileBuilderTest.java @@ -30,6 +30,21 @@ class DotFileBuilderTest { this.writeInFile(new AllUnl().getUnlDocuments(), new AllSetenceWithExpectedDotChecker()); } + @Test + public void Issue12shouldBeExportedInDotFormatWithoutException(){ + // Startup + Writer strResult = new StringWriter(); + DotFileGraphExporter dotFileBuilder = new DotFileGraphExporter(strResult); + + // Test + Assertions.assertDoesNotThrow(() -> dotFileBuilder.write(new Issue12Unl().getUnlDocuments())); + + // Teardown + Assertions.assertDoesNotThrow(strResult::flush); + Assertions.assertTrue(() -> strResult.toString().length() != 0); + Assertions.assertDoesNotThrow(strResult::close); + } + private void writeInFile(List<UnlDocument> unlDocuments, SentenceWithExpectedDotChecker sentenceChecker) { // Startup Writer strResult = new StringWriter(); @@ -39,11 +54,11 @@ class DotFileBuilderTest { Assertions.assertDoesNotThrow(() -> dotFileBuilder.write(unlDocuments)); // Teardown - Assertions.assertDoesNotThrow(() -> strResult.flush()); + Assertions.assertDoesNotThrow(strResult::flush); Assertions.assertTrue(() -> strResult.toString().length() != 0); Assertions.assertDoesNotThrow(() -> sentenceChecker.setCurrentDotContent(strResult.toString())); sentenceChecker.assetSameAsExpected(); - Assertions.assertDoesNotThrow(() -> strResult.close()); + Assertions.assertDoesNotThrow(strResult::close); } } \ No newline at end of file diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue12WithExpectedUnlDocumentsChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue12WithExpectedUnlDocumentsChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..8a45889ae079e585e9c79dd2005ccc409de231eb --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/Issue12WithExpectedUnlDocumentsChecker.java @@ -0,0 +1,13 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.Issue12Unl; +import fr.tetras_libre.unltools.unl.UnlDocument; +import fr.tetras_libre.unltools.unl.UnlSentences; + +import java.util.List; + +public class Issue12WithExpectedUnlDocumentsChecker extends SentenceWithExpectedUnlDocumentsChecker { + public Issue12WithExpectedUnlDocumentsChecker() { + super(UnlSentences.Issue12, new Issue12Unl().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 7bc9410c46b7cfd8b6c8a661f7b236345b116839..aa24a463e113aff5ff0b7ac1280a7faaa97250de 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 @@ -16,11 +16,12 @@ class UnlParserTest { return Stream.of(new R1SentenceWithExpectedUnlDocumentsChecker(), new R2SentenceWithExpectedUnlDocumentsChecker(), new CatsSentenceWithExpectedUnlDocumentsChecker(), - new AllSentenceWithExpectedUnlDocumentsChecker()); + new AllSentenceWithExpectedUnlDocumentsChecker(), + new Issue12WithExpectedUnlDocumentsChecker()); } @ParameterizedTest - @ValueSource(strings = {UnlSentences.R1, UnlSentences.R2, UnlSentences.Cats, UnlSentences.All}) + @ValueSource(strings = {UnlSentences.R1, UnlSentences.R2, UnlSentences.Cats, UnlSentences.All, UnlSentences.Issue12}) void unlParserShouldParseSimpleSentenceWithoutException(String input) { UnlParserFactory unlFactory = new UnlParserFactoryFromString(input); var wrapper = createAndCheckUnlParserValidity(unlFactory); diff --git a/unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java b/unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java index 555b7e7be9d9ec4eeb8e61124ca2f5574b562dfa..f9a15fb027f7151344cd13516e25d1f663e6569d 100644 --- a/unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java +++ b/unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java @@ -8,6 +8,7 @@ import fr.tetras_libre.unltools.unl.exporters.GraphExporterNames; import fr.tetras_libre.unltools.unl.parser.UnlGraphImporterFromUnlParser; import picocli.CommandLine; +import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; @@ -43,9 +44,9 @@ public class Unl2Rdf { String extension = ToExtension(outType); String outfileName = options.getOutputFile() + extension; FileWriter fileWriter = new FileWriter(outfileName, false); - var convertCommand = new ExportUnlDocuments(importer, GetExporterName(outType), fileWriter); + var bufferedWriter = new BufferedWriter(fileWriter); + var convertCommand = new ExportUnlDocuments(importer, GetExporterName(outType), bufferedWriter); handler.handle(convertCommand); - fileWriter.close(); System.out.println(String.format("Graph writen into file '%s'", outfileName)); } } diff --git a/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java b/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java index 4a9dfb91cf582313bae6e2e722270098042db815..004b6928e0d9fb1230db13eb8303f83126b331ba 100644 --- a/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java +++ b/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java @@ -44,6 +44,12 @@ class Unl2RdfTest { Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "exemples_unl", "--output-type", "rdf"})); } + @Tag("integration") + @Test + public void issue12ShouldBeConvertedToDotFile() { + Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "issue12", "--output-type", "dot"})); + } + static class TestMainShouldNotThrowOnPartialParameterArgumentProvider implements ArgumentsProvider { @Override