diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7ec491698a6e134ade2ff19ca1a76429a0390335..92661275c51542eb15ed4e155b228cc91d4d32ed 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,31 +6,39 @@ <sourceOutputDir name="target/generated-sources/annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <outputRelativeToContentRoot value="true" /> - <module name="rdf" /> - <module name="unl-parser" /> + <module name="unl-tools-application" /> + <module name="unl-tools-core" /> + <module name="unl-tools-infrastructure" /> </profile> - <profile name="Annotation profile for unlTools" enabled="true"> + <profile name="Annotation profile for unl-tools" enabled="true"> <sourceOutputDir name="target/generated-sources/annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <outputRelativeToContentRoot value="true" /> - <option name="project" value="fr.tetras_libre.unl/unl2rdf-app" /> + <option name="project" value="fr.tetras_libre.unl/unl-tools-main" /> <processorPath useClasspath="false"> <entry name="$MAVEN_REPOSITORY$/info/picocli/picocli-codegen/4.2.0/picocli-codegen-4.2.0.jar" /> <entry name="$MAVEN_REPOSITORY$/info/picocli/picocli/4.2.0/picocli-4.2.0.jar" /> </processorPath> - <module name="unl2rdf-app" /> + <module name="unl-tools-main" /> </profile> </annotationProcessing> <bytecodeTargetLevel target="11"> - <module name="rdf" target="11" /> <module name="unl-parser" target="11" /> + <module name="unl-tools-app" target="11" /> + <module name="unl-tools-application" target="11" /> + <module name="unl-tools-core" target="11" /> + <module name="unl-tools-infrastructure" target="11" /> + <module name="unl-tools-main" target="11" /> <module name="unl2rdf" target="11" /> <module name="unl2rdf-app" target="11" /> + <module name="unlTools" target="11" /> </bytecodeTargetLevel> </component> <component name="JavacSettings"> <option name="ADDITIONAL_OPTIONS_OVERRIDE"> <module name="unl-parser" options="" /> + <module name="unl-tools-app" options="-Aproject=fr.tetras_libre.unl/unl-tools-app" /> + <module name="unl-tools-main" options="-Aproject=fr.tetras_libre.unl/unl-tools-main" /> <module name="unl2rdf" options="-Aproject=unl2rdf/unl2rdf" /> <module name="unl2rdf-app" options="-Aproject=fr.tetras_libre.unl/unl2rdf-app" /> </option> diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 2b4139a8f4b4e195acef84bd82ade3c356308c26..16b179c7f21b040289b21d98d1803950aedf596e 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,9 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="Encoding"> - <file url="file://$PROJECT_DIR$/rdf/src/main/java" charset="UTF-8" /> - <file url="file://$PROJECT_DIR$/unl-parser/src/main/java" charset="UTF-8" /> - <file url="file://$PROJECT_DIR$/unl2rdf-app/src/main/java" charset="UTF-8" /> - <file url="file://$PROJECT_DIR$/unl2rdf-app/src/main/resources" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-application/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-core/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-infrastructure/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-main/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-main/src/main/resources" charset="UTF-8" /> </component> </project> \ No newline at end of file diff --git a/.idea/encodings.xml.orig b/.idea/encodings.xml.orig new file mode 100644 index 0000000000000000000000000000000000000000..42753a0d4be3904627a6e3eb0587adfe4c19a097 --- /dev/null +++ b/.idea/encodings.xml.orig @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding"> +<<<<<<< HEAD + <file url="file://$PROJECT_DIR$/rdf/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-parser/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl2rdf-app/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl2rdf-app/src/main/resources" charset="UTF-8" /> +======= + <file url="file://$PROJECT_DIR$/unl-tools-application/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-application/src/main/resources" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-core/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-infrastructure/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-infrastructure/src/main/resources" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-main/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/unl-tools-main/src/main/resources" charset="UTF-8" /> +>>>>>>> RefactoringTowardCleanArchitecture + </component> +</project> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ee0869e4848b1bf27ebe83f42480980b3d8c759e..dbdc2e08bd7bf88ae3851fbcccbd8ff0293f142d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,13 +5,9 @@ <list> <option value="$PROJECT_DIR$/pom.xml" /> <option value="$PROJECT_DIR$/../rdf/pom.xml" /> + <option value="$PROJECT_DIR$/unl-tools-main/pom.xml" /> </list> </option> - <option name="ignoredFiles"> - <set> - <option value="$PROJECT_DIR$/pom.xml" /> - </set> - </option> </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="false" project-jdk-name="11" project-jdk-type="JavaSDK" /> </project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 0224bb787dcab87e5036092ce3e15d7da8eef59c..4e2ba7aaa0d9ef3bee6e1be5b8b77c3500bb2e8a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,11 @@ <project version="4"> <component name="ProjectModuleManager"> <modules> - <module fileurl="file://$PROJECT_DIR$/rdf/rdf.iml" filepath="$PROJECT_DIR$/rdf/rdf.iml" /> - <module fileurl="file://$PROJECT_DIR$/unl-parser/unl-parser.iml" filepath="$PROJECT_DIR$/unl-parser/unl-parser.iml" /> - <module fileurl="file://$PROJECT_DIR$/unl2rdf-app/unl2rdf-app.iml" filepath="$PROJECT_DIR$/unl2rdf-app/unl2rdf-app.iml" /> + <module fileurl="file://$PROJECT_DIR$/unl-tools-application/unl-tools-application.iml" filepath="$PROJECT_DIR$/unl-tools-application/unl-tools-application.iml" /> + <module fileurl="file://$PROJECT_DIR$/unl-tools-core/unl-tools-core.iml" filepath="$PROJECT_DIR$/unl-tools-core/unl-tools-core.iml" /> + <module fileurl="file://$PROJECT_DIR$/unl-tools-infrastructure/unl-tools-infrastructure.iml" filepath="$PROJECT_DIR$/unl-tools-infrastructure/unl-tools-infrastructure.iml" /> + <module fileurl="file://$PROJECT_DIR$/unl-tools-main/unl-tools-main.iml" filepath="$PROJECT_DIR$/unl-tools-main/unl-tools-main.iml" /> + <module fileurl="file://$PROJECT_DIR$/unlTools.iml" filepath="$PROJECT_DIR$/unlTools.iml" /> </modules> </component> </project> \ No newline at end of file diff --git a/pom.xml b/pom.xml index efb2c25f235d8ba8596b3a9c4b41ded9bde4d5c7..ab85d7818315d972b01eb3b16fcfd8f21c48495c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -13,10 +13,13 @@ <packaging>pom</packaging> + <name>unl-tools</name> + <modules> - <module>unl-parser</module> - <module>unl2rdf-app</module> - <module>rdf</module> + <module>unl-tools-core</module> + <module>unl-tools-main</module> + <module>unl-tools-infrastructure</module> + <module>unl-tools-application</module> </modules> <build> diff --git a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/R1SentenceWithExpectedRdf.java b/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/R1SentenceWithExpectedRdf.java deleted file mode 100644 index 98534b938853e58d9335b6a0363abdfcc3a82137..0000000000000000000000000000000000000000 --- a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/R1SentenceWithExpectedRdf.java +++ /dev/null @@ -1,167 +0,0 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; - -import fr.tetras_libre.unltools.unl.*; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; - -import java.util.*; -import java.util.stream.Stream; - -public class R1SentenceWithExpectedRdf implements ArgumentsProvider { - private static LinkedList<UnlDocument> unlDocuments; - - public R1SentenceWithExpectedRdf() { - unlDocuments = new LinkedList<>(); - } - - private static void buildUnlDocument() { - - var unlDocument = new UnlDocument("[D]"); - - var graph = new Graph(); - - // aoj - var restrictions = new TreeSet<Restriction>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("be", new TreeSet<>()))); - restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("ben", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("obj", '>', new UniversalWord("uw", new TreeSet<>()))); - restrictions.add(new Restriction("equ", '>', new UniversalWord("make_possible", new TreeSet<>()))); - var uw = new UniversalWord("allow", restrictions); - var uwNode = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@entry"))); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("group", new TreeSet<>()))); - uw = new UniversalWord("system", restrictions); - var uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@def"))); - - graph.add(new GraphRelation(uwNode, uwNode2, "aoj")); - - // obj - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("be", new TreeSet<>()))); - restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("ben", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("obj", '>', new UniversalWord("uw", new TreeSet<>()))); - restrictions.add(new Restriction("equ", '>', new UniversalWord("make_possible", new TreeSet<>()))); - uw = new UniversalWord("allow", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@entry"))); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("equ", '>', new UniversalWord("assume", new TreeSet<>()))); - restrictions.add(new Restriction("icl", '>', new UniversalWord("change", new TreeSet<>()))); - restrictions.add(new Restriction("obj", '>', new UniversalWord("thing", new TreeSet<>()))); - uw = new UniversalWord("take_on", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>()); - - graph.add(new GraphRelation(uwNode, uwNode2, "obj")); - - // ben - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("be", new TreeSet<>()))); - restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("ben", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("obj", '>', new UniversalWord("uw", new TreeSet<>()))); - restrictions.add(new Restriction("equ", '>', new UniversalWord("make_possible", new TreeSet<>()))); - uw = new UniversalWord("allow", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@entry"))); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("radiowave", new TreeSet<>()))); - uw = new UniversalWord("radiowave", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@indef"))); - - graph.add(new GraphRelation(uwNode, uwNode2, "ben")); - - // aoj - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("equ", '>', new UniversalWord("assume", new TreeSet<>()))); - restrictions.add(new Restriction("icl", '>', new UniversalWord("change", new TreeSet<>()))); - restrictions.add(new Restriction("obj", '>', new UniversalWord("thing", new TreeSet<>()))); - uw = new UniversalWord("take_on", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>()); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("radiowave", new TreeSet<>()))); - uw = new UniversalWord("channel", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@indef"))); - - graph.add(new GraphRelation(uwNode, uwNode2, "aoj")); - - // obj - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); - restrictions.add(new Restriction("equ", '>', new UniversalWord("assume", new TreeSet<>()))); - restrictions.add(new Restriction("icl", '>', new UniversalWord("change", new TreeSet<>()))); - restrictions.add(new Restriction("obj", '>', new UniversalWord("thing", new TreeSet<>()))); - uw = new UniversalWord("take_on", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>()); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("attribute", new TreeSet<>()))); - uw = new UniversalWord("state", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@plu"))); - - graph.add(new GraphRelation(uwNode, uwNode2, "obj")); - - // qua - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("attribute", new TreeSet<>()))); - uw = new UniversalWord("state", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@plu"))); - - uwNode2 = new UniversalWordNode(new UniversalWord("2", new TreeSet<>()), new HashSet<>()); - - graph.add(new GraphRelation(uwNode, uwNode2, "qua")); - - // cnt - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("attribute", new TreeSet<>()))); - uw = new UniversalWord("state", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@plu"))); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("sensing", new TreeSet<>()))); - uw = new UniversalWord("listening", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@plu"))); - - graph.add(new GraphRelation(uwNode, uwNode2, "cnt")); - - // and - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("sensing", new TreeSet<>()))); - uw = new UniversalWord("listening", restrictions); - uwNode = new UniversalWordNode(uw, new HashSet<>()); - - restrictions = new TreeSet<>(); - restrictions.add(new Restriction("icl", '>', new UniversalWord("communication", new TreeSet<>()))); - uw = new UniversalWord("traffic", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>()); - - graph.add(new GraphRelation(uwNode, uwNode2, "and")); - - var unlDocumentNode = new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:R1]", graph); - - unlDocument.add(unlDocumentNode); - - unlDocuments.add(unlDocument); - } - - private static List<UnlDocument> getUnlDocuments() { - if (null == unlDocuments) { - buildUnlDocument(); - } - - return unlDocuments; - } - - - @Override - public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { - buildUnlDocument(); - return Stream.of(Arguments.of(unlDocuments)); - } -} diff --git a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/RelationLabelToUnlPropertyConverterTest.java b/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/RelationLabelToUnlPropertyConverterTest.java deleted file mode 100644 index e1edbec6831d4654e939f27c8fae306df9d15cb4..0000000000000000000000000000000000000000 --- a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/RelationLabelToUnlPropertyConverterTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -class RelationLabelToUnlPropertyConverterTest { - - @Test - public void Check(){ - var relationLabelToUnlProperty = new RelationLabelToUnlPropertyConverter(); - - Assertions.assertDoesNotThrow(() -> relationLabelToUnlProperty.getObjectProperty("aoj", null)); - } -} \ No newline at end of file diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/AllSetenceWithExpectedDotChecker.java b/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/AllSetenceWithExpectedDotChecker.java deleted file mode 100644 index 60bd471cc04bcdc36e2cbcdeea080ed63ad1aed5..0000000000000000000000000000000000000000 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/AllSetenceWithExpectedDotChecker.java +++ /dev/null @@ -1,177 +0,0 @@ -package fr.tetras_libre.unltools.unl; - -public class AllSetenceWithExpectedDotChecker extends SentenceWithExpectedDotChecker { - private static final String ALL = "[D]" + - "[S:R1]\n" + - "{org:en}\n" + - "The system allows a radio channel to take on two states: Listening and Traffic.\n" + - "{/org}\n" + - "{unl}\n" + - "aoj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, system(icl>group).@def )\n" + - "obj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, take_on(aoj>thing, equ>assume,icl>change, obj>thing) )\n" + - "ben( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, channel(icl>radiowave).@indef)\n" + - "aoj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), channel(icl>radiowave).@indef) \n" + - "obj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), state(icl>attribute).@plu ) \n" + - "qua( state(icl>attribute).@plu, 2 ) \n" + - "cnt( state(icl>attribute).@plu, listening(icl>sensing) )\n" + - "and( listening(icl>sensing),traffic(icl>communication) )\n" + - "{/unl}\n" + - "[/S]\n" + - "[S:R2]\n" + - "{org:en}\n" + - "The system displays a channel in green when it is in broadcast state. \n" + - "{/org}\n" + - "{unl}\n" + - "agt(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,system(icl>group).@def)\n" + - "mod(channel(icl>radiowave).@indef,green(icl>adj,iof>color))\n" + - "obj(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,channel(icl>radiowave).@indef)\n" + - "tim(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,when(icl>how,com>always,tim<uw,obj>uw))\n" + - "aoj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,channel(icl>radiowave).@indef)\n" + - "plc:01(state(icl>attribute),broadcast(icl>message))\n" + - "obj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,state(icl>attribute))\n" + - "obj(when(icl>how,com>always,tim<uw,obj>uw),:01)\n" + - "{/unl}\n" + - "[/S] \n" + - "[S:00]\n" + - "{org:en}\n" + - "The black cat and the white cat are eating.\n" + - "{/org}\n" + - "{unl}\n" + - "mod:01(cat1(icl>feline>thing).@entry.@def,black(icl>adj))\n" + - "and:01(cat1(icl>feline>thing).@entry.@def,cat2(icl>feline>thing).@entry.@def)\n" + - "mod:01(cat2(icl>feline>thing).@entry.@def,white(icl>adj))\n" + - "agt(eat(icl>consume>do,agt>living_thing,obj>concrete_thing,ins>thing).@entry.@pl.@present.@progress,:01.@_hn-scope)\n" + - "{/unl}\n" + - "[/S]\n" + - "[/D]"; - - private static final String ALL_DOT = "digraph G {\n" + - "graph [fontname=\"courier\", compound=\"true\"];\n" + - "1 [\n" + - "label=\"allow(aoj>thing,ben>thing,equ>make_possible,icl>be,obj>uw)\\n.@entry\"\n" + - "shape=\"box\"\n" + - "fontname=\"courb\"\n" + - "];\n" + - "2 [\n" + - "label=\"system(icl>group)\\n.@def\"\n" + - "shape=\"box\"\n" + - "];\n" + - "3 [\n" + - "label=\"take_on(aoj>thing,equ>assume,icl>change,obj>thing)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "4 [\n" + - "label=\"channel(icl>radiowave)\\n.@indef\"\n" + - "shape=\"box\"\n" + - "];\n" + - "5 [\n" + - "label=\"state(icl>attribute)\\n.@plu\"\n" + - "shape=\"box\"\n" + - "];\n" + - "6 [\n" + - "label=\"2\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "7 [\n" + - "label=\"listening(icl>sensing)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "8 [\n" + - "label=\"traffic(icl>communication)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "1 -> 2 [label=\"aoj\" ];\n" + - "1 -> 3 [label=\"obj\" ];\n" + - "1 -> 4 [label=\"ben\" ];\n" + - "3 -> 4 [label=\"aoj\" ];\n" + - "3 -> 5 [label=\"obj\" ];\n" + - "5 -> 6 [label=\"qua\" ];\n" + - "5 -> 7 [label=\"cnt\" ];\n" + - "7 -> 8 [label=\"and\" ];\n" + - "}\n" + - "digraph G {\n" + - "graph [fontname=\"courier\", compound=\"true\"];\n" + - "1 [\n" + - "label=\"display(agt>thing,equ>exhibit,icl>show,obj>thing)\\n.@entry.@present\"\n" + - "shape=\"box\"\n" + - "fontname=\"courb\"\n" + - "];\n" + - "2 [\n" + - "label=\"system(icl>group)\\n.@def\"\n" + - "shape=\"box\"\n" + - "];\n" + - "3 [\n" + - "label=\"channel(icl>radiowave)\\n.@indef\"\n" + - "shape=\"box\"\n" + - "];\n" + - "4 [\n" + - "label=\"green(icl>adj,iof>color)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "5 [\n" + - "label=\"when(com>always,icl>how,obj>uw,tim<uw)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "6 [\n" + - "label=\"be_in_a_state(aoj>thing,icl>be,obj>state)\\n.@entry.@present\"\n" + - "shape=\"box\"\n" + - "fontname=\"courb\"\n" + - "];\n" + - "7 [\n" + - "label=\"state(icl>attribute)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "8 [\n" + - "label=\"broadcast(icl>message)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "subgraph cluster_01{\n" + - " color = black;\n" + - " label = \":01\"6 -> 3 [label=\"aoj\" ];\n" + - "7 -> 8 [label=\"plc\" ];\n" + - "6 -> 7 [label=\"obj\" ];\n" + - "}\n" + - "1 -> 2 [label=\"agt\" ];\n" + - "3 -> 4 [label=\"mod\" ];\n" + - "1 -> 3 [label=\"obj\" ];\n" + - "1 -> 5 [label=\"tim\" ];\n" + - "5 -> 6 [label=\"obj\" lhead=\"cluster_01\"];\n" + - "}\n" + - "digraph G {\n" + - "graph [fontname=\"courier\", compound=\"true\"];\n" + - "1 [\n" + - "label=\"cat1(icl>feline(icl>thing))\\n.@def.@entry\"\n" + - "shape=\"box\"\n" + - "fontname=\"courb\"\n" + - "];\n" + - "2 [\n" + - "label=\"black(icl>adj)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "3 [\n" + - "label=\"cat2(icl>feline(icl>thing))\\n.@def.@entry\"\n" + - "shape=\"box\"\n" + - "fontname=\"courb\"\n" + - "];\n" + - "4 [\n" + - "label=\"white(icl>adj)\\n\"\n" + - "shape=\"box\"\n" + - "];\n" + - "5 [\n" + - "label=\"eat(agt>living_thing,icl>consume(icl>do),ins>thing,obj>concrete_thing)\\n.@entry.@pl.@present.@progress\"\n" + - "shape=\"box\"\n" + - "fontname=\"courb\"\n" + - "];\n" + - "subgraph cluster_01{\n" + - " color = black;\n" + - " label = \":01\"1 -> 2 [label=\"mod\" ];\n" + - "1 -> 3 [label=\"and\" ];\n" + - "3 -> 4 [label=\"mod\" ];\n" + - "}\n" + - "5 -> 1 [label=\"agt\" lhead=\"cluster_01\"];\n" + - "}\n"; - - public AllSetenceWithExpectedDotChecker() { - super(ALL, ALL_DOT); - } -} diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/CatSentenceWithExpectedDotChecker.java b/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/CatSentenceWithExpectedDotChecker.java deleted file mode 100644 index 4d398d2ba188013ecfed92bab9d46c3a9dc1177c..0000000000000000000000000000000000000000 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/CatSentenceWithExpectedDotChecker.java +++ /dev/null @@ -1,32 +0,0 @@ -package fr.tetras_libre.unltools.unl; - -public class CatSentenceWithExpectedDotChecker extends SentenceWithExpectedDotChecker { - - private static final String CAT_UNL = "[D]" + - "[S:00]\n" + - "{org:en}\n" + - "The black cat and the white cat are eating.\n" + - "{/org}\n" + - "{unl}\n" + - "mod:01(cat(icl>feline>thing):01.@entry.@def,black(icl>adj))\n" + - "and:01(cat(icl>feline>thing):01.@entry.@def,cat(icl>feline>thing):02.@entry.@def)\n" + - "mod:01(cat(icl>feline>thing):02.@entry.@def,white(icl>adj))\n" + - "agt(eat(icl>consume>do,agt>living_thing,obj>concrete_thing,ins>thing).@entry.@pl.@present.@progress,:01.@_hn-scope)\n" + - "{/unl}\n" + - "[/S]\n"; - - private static final String CAT_DOT = "digraph G {\n" + - "graph [fontname=\"courier\", compound=\"true\"];\n" + - "1 [ label=\"cat(icl>feline(icl>thing)):01\\n.@def.@entry\" shape=\"box\" fontname=\"courb\" ];\n" + - "2 [ label=\"black(icl>adj)\\n\" shape=\"box\" ];\n" + - "3 [ label=\"cat(icl>feline(icl>thing)):02\\n.@def.@entry\" shape=\"box\" fontname=\"courb\" ];\n" + - "4 [ label=\"white(icl>adj)\\n\" shape=\"box\" ];\n" + - "5 [ label=\"eat(agt>living_thing,icl>consume(icl>do),ins>thing,obj>concrete_thing)\\n.@entry.@pl.@present.@progress\" shape=\"box\" fontname=\"courb\" ];" + - " subgraph cluster_01{ color = black; label = \":01\"1 -> 2 [label=\"mod\" ]; 1 -> 3 [label=\"and\" ]; 3 -> 4 [label=\"mod\" ]; }\n" + - "5 -> 1 [label=\"agt\" lhead=\"cluster_01\"];\n" + - "}\n"; - - public CatSentenceWithExpectedDotChecker() { - super(CAT_UNL, CAT_DOT); - } -} diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/print/dotFile/DotFileBuilderTest.java b/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/print/dotFile/DotFileBuilderTest.java deleted file mode 100644 index 3ec313b0088c404fa826b3f95dcd44b3634a6fac..0000000000000000000000000000000000000000 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/print/dotFile/DotFileBuilderTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package fr.tetras_libre.unltools.unl.print.dotFile; - -import fr.tetras_libre.unltools.unl.*; -import fr.tetras_libre.unltools.unl.parser.UnlParser; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestReporter; -import org.junit.jupiter.api.io.TempDir; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Vector; -import java.util.concurrent.atomic.AtomicReference; - -class DotFileBuilderTest { - - @TempDir - static Path SharedTempDir; - - private TestReporter testReporter; - - @Test - public void dotFileBuilderShouldCreateDotFileR1WithoutException(TestReporter testReporter) { - this.testReporter = testReporter; - Path dotPAth = SharedTempDir.resolve("r1.dot"); - writeInFile(dotPAth, new R1SentenceWithExpectedDotChecker()); - } - - @Test - public void dotFileBuilderShouldCreateDotFileWithoutException(TestReporter testReporter) { - this.testReporter = testReporter; - Path dotPAth = SharedTempDir.resolve("r2.dot"); - this.writeInFile(dotPAth, new R2SentenceWithExpectedDotChecker()); - } - - @Test - public void dotFileBuilderShouldCreateDotFileCatWithoutException(TestReporter testReporter) { - this.testReporter = testReporter; - Path dotPAth = SharedTempDir.resolve("cat.dot"); - this.writeInFile(dotPAth, new CatSentenceWithExpectedDotChecker()); - } - - @Test - public void dotFileBuilderShouldCreateDotFileAllWithoutException(TestReporter testReporter) { - this.testReporter = testReporter; - Path dotPAth = SharedTempDir.resolve("all.dot"); - - this.writeInFile(dotPAth, new AllSetenceWithExpectedDotChecker()); - } - - private void writeInFile(Path filePath, SentenceWithExpectedDotChecker sentenceChecker) { - // Startup - UnlParser parser = new UnlParser(new BufferedReader(new StringReader(sentenceChecker.getUnlSentence()))); - AtomicReference<Vector<UnlDocument>> documentsAtomic = new AtomicReference<>(); - Assertions.assertDoesNotThrow(() -> documentsAtomic.set(parser.createUnlDocumentList())); - - AtomicReference<File> outFile = new AtomicReference<>(); - Assertions.assertDoesNotThrow(() -> outFile.set(new File(filePath.toAbsolutePath().toString()))); - - AtomicReference<BufferedWriter> outFileWriter = new AtomicReference<>(); - Assertions.assertDoesNotThrow(() -> outFileWriter.set(new BufferedWriter(new FileWriter(outFile.get(), false)))); - - DotFileBuilder dotFileBuilder = new DotFileBuilder(outFileWriter.get()); - - // Test - - Assertions.assertDoesNotThrow(() -> dotFileBuilder.write(documentsAtomic.get())); - - - // Teardown - Assertions.assertDoesNotThrow(() -> { - outFileWriter.get().flush(); - outFileWriter.get().close(); - }); - Assertions.assertTrue(() -> outFile.get().length() != 0); - Assertions.assertDoesNotThrow(() -> sentenceChecker.setCurrentDotContent(Files.readString(filePath, StandardCharsets.UTF_8))); - sentenceChecker.assetSameAsExpected(); - - } -} \ No newline at end of file diff --git a/unl-tools-application/pom.xml b/unl-tools-application/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..2bf5b4e750f5d9fde94582363addaa0e856a2b8a --- /dev/null +++ b/unl-tools-application/pom.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>unlTools</artifactId> + <groupId>fr.tetras_libre.unl</groupId> + <version>0.9</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>unl-tools-application</artifactId> + + <dependencies> + <dependency> + <groupId>fr.tetras_libre.unl</groupId> + <artifactId>unl-tools-core</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + + +</project> \ No newline at end of file diff --git a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/CommandHandlerResolverBuilder.java b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/CommandHandlerResolverBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..6cb7d831faf03c3b116e5f4f1797d3ec36992877 --- /dev/null +++ b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/CommandHandlerResolverBuilder.java @@ -0,0 +1,25 @@ +package fr.tetras_libre.unltools; + +import fr.tetras_libre.unltools.cqrs.Command; +import fr.tetras_libre.unltools.cqrs.CommandHandler; +import fr.tetras_libre.unltools.cqrs.CommandHandlerResolver; + +import java.util.Dictionary; +import java.util.Hashtable; + +public class CommandHandlerResolverBuilder { + private final Dictionary<Class<? extends Command<?>>, Class<? extends CommandHandler<?,?>>> map; + + public CommandHandlerResolverBuilder() { + this.map = new Hashtable<>(); + } + + public <TResult, THandler extends CommandHandler<TCommand, TResult>, TCommand extends Command<TResult>> CommandHandlerResolverBuilder addHandler(Class<THandler> handler, Class<TCommand> command) { + this.map.put(command, handler); + return this; + } + + public CommandHandlerResolver createCommandResolver() { + return new CommandHandlerResolver(this.map); + } +} diff --git a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocuments.java b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocuments.java new file mode 100644 index 0000000000000000000000000000000000000000..efec7a17bbf3df4ea5cc9d74f09619d43d979314 --- /dev/null +++ b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocuments.java @@ -0,0 +1,31 @@ +package fr.tetras_libre.unltools.Convert; + +import fr.tetras_libre.unltools.cqrs.Command; +import fr.tetras_libre.unltools.cqrs.Result; +import fr.tetras_libre.unltools.unl.GraphImporter; + +import java.io.Writer; + +public class ExportUnlDocuments implements Command<Result> { + private final GraphImporter graphImporter; + private final String exporterName; + private final Writer writer; + + public ExportUnlDocuments(GraphImporter graphImporter, String exporterName, Writer writer) { + this.graphImporter = graphImporter; + this.exporterName = exporterName; + this.writer = writer; + } + + public GraphImporter getGraphImporter() { + return this.graphImporter; + } + + public String getExporterName() { + return this.exporterName; + } + + public Writer getWriter() { + return this.writer; + } +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..62ed3433b85252679ebb70ff5cd605ee980ff57e --- /dev/null +++ b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java @@ -0,0 +1,27 @@ +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.GraphExporterFactory; + +import java.io.IOException; + +public class ExportUnlDocumentsHandler implements CommandHandler<ExportUnlDocuments, Result> { + private final GraphExporterFactory factory; + + public ExportUnlDocumentsHandler(GraphExporterFactory factory) { + this.factory = factory; + } + + @Override + public Result handle(ExportUnlDocuments command) { + try { + var graphExporter = factory.createGraphExporter(command.getWriter(), command.getExporterName()); + graphExporter.write(command.getGraphImporter().Import()); + } catch (IOException e) { + return Result.Failure(String.format("Cannot export unl documents to format '%s'", command.getExporterName()), + e); + } + return Result.Success(); + } +} diff --git a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/DefaultCommandHandlerResolverFactory.java b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/DefaultCommandHandlerResolverFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..5c0f95e525cdbe37e435b2746976117d4e7dc4e7 --- /dev/null +++ b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/DefaultCommandHandlerResolverFactory.java @@ -0,0 +1,14 @@ +package fr.tetras_libre.unltools; + +import fr.tetras_libre.unltools.Convert.ExportUnlDocuments; +import fr.tetras_libre.unltools.Convert.ExportUnlDocumentsHandler; +import fr.tetras_libre.unltools.cqrs.CommandHandlerResolver; + +public class DefaultCommandHandlerResolverFactory { + public static CommandHandlerResolver create() { + var builder = new CommandHandlerResolverBuilder() + .addHandler(ExportUnlDocumentsHandler.class, ExportUnlDocuments.class); + + return builder.createCommandResolver(); + } +} diff --git a/unl2rdf.iml b/unl-tools-application/unl-tools-application.iml similarity index 76% rename from unl2rdf.iml rename to unl-tools-application/unl-tools-application.iml index a1228676ab4a0db53542223375c69006ea8969ba..200cdeaa5287029d1a596c76d68f6181bcf03153 100644 --- a/unl2rdf.iml +++ b/unl-tools-application/unl-tools-application.iml @@ -4,14 +4,14 @@ <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/unl-parser/src/main/java" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/unl-parser/src/main/resources" type="java-resource" /> - <sourceFolder url="file://$MODULE_DIR$/unl-parser/src/test/java" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" generated="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> - <orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" /> + <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="unl-tools-core" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" /> diff --git a/unl-parser/pom.xml b/unl-tools-core/pom.xml similarity index 67% rename from unl-parser/pom.xml rename to unl-tools-core/pom.xml index 4e8a57d3ebd8999c702b97708596e8a7d2f3ff7f..b902356571b0cd5940f6c331c6d89e93a993cd29 100644 --- a/unl-parser/pom.xml +++ b/unl-tools-core/pom.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -10,8 +10,6 @@ <version>0.9</version> </parent> - <artifactId>unl-parser</artifactId> + <artifactId>unl-tools-core</artifactId> <packaging>jar</packaging> - - <name>Unl-parser</name> </project> diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Command.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Command.java new file mode 100644 index 0000000000000000000000000000000000000000..edf837f17845e31d44690493df30c278eb3c2dd0 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Command.java @@ -0,0 +1,4 @@ +package fr.tetras_libre.unltools.cqrs; + +public interface Command<TResult> { +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/CommandHandler.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/CommandHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..2efdaef8637a96cf47e975132b4f472e8b11b137 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/CommandHandler.java @@ -0,0 +1,5 @@ +package fr.tetras_libre.unltools.cqrs; + +public interface CommandHandler<Cmd extends Command<TResult>, TResult> { + TResult handle(Cmd command); +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/CommandHandlerResolver.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/CommandHandlerResolver.java new file mode 100644 index 0000000000000000000000000000000000000000..dc685ae5be1bdb9cd9249f82f71808b5578dd16e --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/CommandHandlerResolver.java @@ -0,0 +1,20 @@ +package fr.tetras_libre.unltools.cqrs; + +import java.util.Dictionary; +import java.util.Enumeration; + +public class CommandHandlerResolver { + private Dictionary<Class<? extends Command<?>>, Class<? extends CommandHandler<?,?>>> associations; + + public CommandHandlerResolver(Dictionary<Class<? extends Command<?>>, Class<? extends CommandHandler<?,?>>> associations) { + this.associations = associations; + } + + public <TResult, TCommand extends Command<TResult>> Class<? extends CommandHandler<Command<TResult>, TResult>> getHandler(Class<? extends TCommand> cmd) { + return (Class<? extends CommandHandler<Command<TResult>, TResult>>) associations.get(cmd); + } + + public Enumeration<Class<? extends CommandHandler<?,?>>> getHandlers() { + return associations.elements(); + } +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Mediator.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Mediator.java new file mode 100644 index 0000000000000000000000000000000000000000..091200f072fca051e7cc9e74de208b1e71f6eb14 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Mediator.java @@ -0,0 +1,16 @@ +package fr.tetras_libre.unltools.cqrs; + +public class Mediator { + + private final ServiceProvider serviceProvider; + + public Mediator(ServiceProvider serviceProvider) { + this.serviceProvider = serviceProvider; + } + + public <TCmd extends Command<TResult>, TResult> TResult Dispatch(TCmd cmd) { + var handlerResolver = (CommandHandlerResolver) serviceProvider.getService(CommandHandlerResolver.class); + var handler = (CommandHandler<Command<TResult>, TResult>) serviceProvider.getService(handlerResolver.getHandler(cmd.getClass())); + return handler.handle(cmd); + } +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Result.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Result.java new file mode 100644 index 0000000000000000000000000000000000000000..c9bd9c71435e095bb4cd9ac40fd4c60d29e5a683 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/Result.java @@ -0,0 +1,42 @@ +package fr.tetras_libre.unltools.cqrs; + +public class Result { + private static Result success = new Result(true); + + private boolean isSuccess; + private String message; + private Exception e; + + private Result(boolean isSuccess) { + this(isSuccess, null, null); + } + + private Result(boolean isSuccess, String message, Exception e) { + if (isSuccess) { + this.isSuccess = true; + } + + if (!isSuccess && null != message) { + this.message = message; + } + + if (!isSuccess && null != e) { + this.e = e; + if (null == this.message || this.message.isBlank()) { + this.message = e.getMessage(); + } + } + } + + public static Result Success() { + return success; + } + + public static Result Failure(String message) { + return new Result(false, message, null); + } + + public static Result Failure(String message, Exception exception) { + return new Result(false, message, exception); + } +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/ServiceProvider.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/ServiceProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..8c506419625aaf23f102c957e0753ae5dfbc3e79 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/cqrs/ServiceProvider.java @@ -0,0 +1,7 @@ +package fr.tetras_libre.unltools.cqrs; + +public interface ServiceProvider { + <T> T getService(Class<T> service); + + <TCmd extends Command<TResult>, TResult> CommandHandler<Command<TResult>, TResult> getHandler(Class<? extends TCmd> command); +} diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/EqualsBuilder.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/EqualsBuilder.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/EqualsBuilder.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/EqualsBuilder.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/Graph.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java similarity index 91% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/Graph.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java index 28288be4e75e1a8c84402fc63629265a3808c027..33197d0d85d44bd13ac62076a486991bb149b41d 100644 --- a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/Graph.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java @@ -140,4 +140,21 @@ public class Graph { return strBuilder.toString(); } + @Override + public boolean equals(Object obj) { + if (null == obj) { + return false; + } + + if (!(obj instanceof Graph)) { + return false; + } + + return equals((Graph) obj); + } + + private boolean equals(Graph other) { + return this.nodes.equals(other.nodes) + && this.relations.equals(other.relations); + } } diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporter.java diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporterFactory.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporterFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..6c9a32aa70687b5997478b0c1635f6e5f651a293 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphExporterFactory.java @@ -0,0 +1,7 @@ +package fr.tetras_libre.unltools.unl; + +import java.io.Writer; + +public interface GraphExporterFactory { + GraphExporter createGraphExporter(Writer writer, String exporterName); +} diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphImporter.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphImporter.java new file mode 100644 index 0000000000000000000000000000000000000000..001f25097062857ae3bc10759e9758508d0da435 --- /dev/null +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphImporter.java @@ -0,0 +1,7 @@ +package fr.tetras_libre.unltools.unl; + +import java.util.List; + +public interface GraphImporter { + List<UnlDocument> Import(); +} diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphNode.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphNode.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphNode.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphNode.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphRelation.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphRelation.java similarity index 63% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphRelation.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphRelation.java index bbd12483d008989f880e59c1965589b6b0eea689..2af346870121f0c00f033c4375e4097004d56d61 100644 --- a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/GraphRelation.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/GraphRelation.java @@ -49,4 +49,32 @@ public class GraphRelation { this.node1.toString(), this.node2.toString()); } + + @Override + public boolean equals(Object obj) { + if (null == obj) { + return false; + } + + if (!(obj instanceof GraphRelation)) { + return false; + } + + return equals((GraphRelation) obj); + } + + private boolean equals(GraphRelation other) { + var equalityBuilder = new EqualsBuilder() + .append(this.node1) + .append(this.node2) + .append(this.SubGraphReferenceLabel) + .append(this.relationLabel); + + return new EqualsBuilder() + .append(other.node1) + .append(other.node2) + .append(other.SubGraphReferenceLabel) + .append(other.relationLabel) + .isEqual(equalityBuilder); + } } diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/HashCodeBuilder.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/HashCodeBuilder.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/HashCodeBuilder.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/HashCodeBuilder.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/NoEntryNodeException.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/NoEntryNodeException.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/NoEntryNodeException.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/NoEntryNodeException.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/Restriction.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Restriction.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/Restriction.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Restriction.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNode.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNode.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNode.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNode.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UniversalWord.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UniversalWord.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UniversalWord.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UniversalWord.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UniversalWordNode.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UniversalWordNode.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UniversalWordNode.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UniversalWordNode.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocument.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocument.java similarity index 81% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocument.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocument.java index 816ab213fef0493639ed39a0aacb7f2ee1b9b199..ed9116ac88c1a896db8abd5b9b748ed1a9810a3c 100644 --- a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocument.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocument.java @@ -70,4 +70,21 @@ public class UnlDocument { return sb.toString(); } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (!(obj instanceof UnlDocument)) { + return false; + } + return equals((UnlDocument) obj); + } + + private boolean equals(UnlDocument other) { + return this.docElements.equals(other.docElements) + && (this.hasError() == other.hasError()); + } } diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNode.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNode.java similarity index 77% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNode.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNode.java index 2b7084175a6e1a2adf762a2df5d9474f9a90e231..6d4c9f25b56035900a7e7f2901bad553658609d5 100644 --- a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNode.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNode.java @@ -72,4 +72,25 @@ public class UnlDocumentNode { throw new IllegalStateException(String.format("Unknown type of sentence node '%s'", this.kindOfNode.toString())); } + + @Override + public boolean equals(Object obj) { + if (null == obj) { + return false; + } + + if (!(obj instanceof UnlDocumentNode)) { + return false; + } + + return this.equals((UnlDocumentNode) obj); + } + + private boolean equals(UnlDocumentNode other) { + return this.docNodeLabel.equals(other.docNodeLabel) + && this.kindOfNode.equals(other.kindOfNode) + && this.hasError() == other.hasError() + && this.graph.equals(other.graph); + + } } diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNodeType.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNodeType.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNodeType.java rename to unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/UnlDocumentNodeType.java diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/EqualsBuilderTest.java b/unl-tools-core/src/test/java/fr/tetras_libre/unltools/unl/EqualsBuilderTest.java similarity index 99% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/EqualsBuilderTest.java rename to unl-tools-core/src/test/java/fr/tetras_libre/unltools/unl/EqualsBuilderTest.java index c6e0a2bd38de304ced67e07471d18596bc91406a..8fd693d581637da9c50bf20d670f09086db35d42 100644 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/EqualsBuilderTest.java +++ b/unl-tools-core/src/test/java/fr/tetras_libre/unltools/unl/EqualsBuilderTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class EqualsBuilderTest { - @Test void isEqual() { String s1 = "qdfsf"; diff --git a/unl-parser/unl-parser.iml b/unl-tools-core/unl-tools-core.iml similarity index 100% rename from unl-parser/unl-parser.iml rename to unl-tools-core/unl-tools-core.iml diff --git a/rdf/pom.xml b/unl-tools-infrastructure/pom.xml similarity index 64% rename from rdf/pom.xml rename to unl-tools-infrastructure/pom.xml index 87305034c425c286c6bc2ae6d685dcebe56e873d..a79f437c5586f6d27f9f13775ffb3ddf197deb84 100644 --- a/rdf/pom.xml +++ b/unl-tools-infrastructure/pom.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -11,9 +11,7 @@ </parent> - <name>rdf2Unl</name> - - <artifactId>rdf</artifactId> + <artifactId>unl-tools-infrastructure</artifactId> <packaging>jar</packaging> <dependencies> @@ -24,10 +22,15 @@ <version>3.14.0</version> </dependency> <dependency> - <groupId>fr.tetras_libre.unl</groupId> - <artifactId>unl-parser</artifactId> - <version>1.0-SNAPSHOT</version> - <scope>compile</scope> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.7.30</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.picocontainer</groupId> + <artifactId>picocontainer</artifactId> + <version>2.15</version> </dependency> <dependency> <groupId>fr.tetras_libre.rdf</groupId> @@ -35,10 +38,15 @@ <version>1.0-SNAPSHOT</version> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-nop</artifactId> - <version>1.7.30</version> - <scope>test</scope> + <groupId>fr.tetras_libre.unl</groupId> + <artifactId>unl-tools-core</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>fr.tetras_libre.unl</groupId> + <artifactId>unl-tools-application</artifactId> + <version>${project.version}</version> </dependency> </dependencies> diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/ApplicationStartup.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/ApplicationStartup.java new file mode 100644 index 0000000000000000000000000000000000000000..d3654e77fcd8398acf428745154e7d9d733a3e52 --- /dev/null +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/ApplicationStartup.java @@ -0,0 +1,29 @@ +package fr.tetras_libre.unltools; + +import fr.tetras_libre.unltools.cqrs.CommandHandlerResolver; +import fr.tetras_libre.unltools.cqrs.Mediator; +import fr.tetras_libre.unltools.cqrs.ServiceProvider; +import fr.tetras_libre.unltools.cqrs.ServiceProviderImpl; +import fr.tetras_libre.unltools.unl.GraphExporterFactory; +import fr.tetras_libre.unltools.unl.exporters.DefaultGraphExporterFactory; +import org.picocontainer.MutablePicoContainer; +import org.picocontainer.containers.TransientPicoContainer; + +public class ApplicationStartup { + + public static ServiceProvider Initialize(CommandHandlerResolver commandHandlerResolver) { + MutablePicoContainer picoContainer = new TransientPicoContainer(); + + picoContainer.addComponent(commandHandlerResolver); + for (var handlerToRegister = commandHandlerResolver.getHandlers(); handlerToRegister.hasMoreElements(); ) { + picoContainer.addComponent(handlerToRegister.nextElement()); + } + + picoContainer.addComponent(GraphExporterFactory.class, DefaultGraphExporterFactory.class); + + var result = new ServiceProviderImpl(picoContainer); + picoContainer.addComponent(ServiceProvider.class, result); + picoContainer.addComponent(Mediator.class); + return result; + } +} diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/cqrs/ServiceProviderImpl.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/cqrs/ServiceProviderImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..45937b80d5b3c0c8e9deee6c5ac3d3d31314d960 --- /dev/null +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/cqrs/ServiceProviderImpl.java @@ -0,0 +1,22 @@ +package fr.tetras_libre.unltools.cqrs; + +import org.picocontainer.PicoContainer; + +public class ServiceProviderImpl implements ServiceProvider { + PicoContainer container; + + public ServiceProviderImpl(PicoContainer container) { + this.container = container; + } + + @Override + public <T> T getService(Class<T> service) { + return this.container.getComponent(service); + } + + @Override + public <TCmd extends Command<TResult>, TResult> CommandHandler<Command<TResult>, TResult> getHandler(Class<? extends TCmd> command) { + var commandResolver = getService(CommandHandlerResolver.class); + return getService(commandResolver.getHandler(command)); + } +} diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/GraphExtensions.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/GraphExtensions.java similarity index 86% rename from rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/GraphExtensions.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/GraphExtensions.java index 817f7091812c973bb9560e132b515786a7cf6b0b..a7f838ec73c7d74318a364783212ec2677359fd3 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/GraphExtensions.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/GraphExtensions.java @@ -1,7 +1,4 @@ -package fr.tetras_libre.unltools.unl.extensions; - -import fr.tetras_libre.unltools.unl.Graph; -import fr.tetras_libre.unltools.unl.GraphRelation; +package fr.tetras_libre.unltools.unl; import java.util.Collection; import java.util.LinkedList; diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/GraphRelationExtensions.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/GraphRelationExtensions.java similarity index 93% rename from rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/GraphRelationExtensions.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/GraphRelationExtensions.java index 429f4c4691437edd236333bbec89cfe385c3bbc6..d66455aca3e056009f39172b9114523da3c06e7d 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/GraphRelationExtensions.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/GraphRelationExtensions.java @@ -1,6 +1,4 @@ -package fr.tetras_libre.unltools.unl.extensions; - -import fr.tetras_libre.unltools.unl.*; +package fr.tetras_libre.unltools.unl; public class GraphRelationExtensions { public static String getRealNode1Id(GraphRelation graphRelation, Graph g) throws NoEntryNodeException { diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/SubGraphReferenceNodeExtensions.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNodeExtensions.java similarity index 66% rename from rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/SubGraphReferenceNodeExtensions.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNodeExtensions.java index 6a9f80d90f0f9addadb0307f79c879d6bb89a0b5..34ae9f7e9dc7a847f4f00196037166e7b7a9ccd8 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/unl/extensions/SubGraphReferenceNodeExtensions.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/SubGraphReferenceNodeExtensions.java @@ -1,8 +1,4 @@ -package fr.tetras_libre.unltools.unl.extensions; - -import fr.tetras_libre.unltools.unl.Graph; -import fr.tetras_libre.unltools.unl.NoEntryNodeException; -import fr.tetras_libre.unltools.unl.SubGraphReferenceNode; +package fr.tetras_libre.unltools.unl; public class SubGraphReferenceNodeExtensions { public static String getScopeNameFromSubGraphReferenceNode(SubGraphReferenceNode g) { diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/DefaultGraphExporterFactory.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/DefaultGraphExporterFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..cb1259519a5af312d7fafeb85efaaacf346a9c06 --- /dev/null +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/DefaultGraphExporterFactory.java @@ -0,0 +1,26 @@ +package fr.tetras_libre.unltools.unl.exporters; + +import fr.tetras_libre.unltools.unl.GraphExporter; +import fr.tetras_libre.unltools.unl.GraphExporterFactory; +import fr.tetras_libre.unltools.unl.exporters.dot.DotFileGraphExporter; +import fr.tetras_libre.unltools.unl.exporters.rdf.RdfFileGraphExporter; + +import java.io.Writer; + +public class DefaultGraphExporterFactory implements GraphExporterFactory { + @Override + public GraphExporter createGraphExporter(Writer writer, String name) { + if (null == writer) throw new IllegalArgumentException("A writer should be provided"); + if (null == name || name.isBlank()) throw new IllegalArgumentException("Graph exporter should be provided"); + + if (GraphExporterNames.RDF_EXPORTER.equals(name)) { + return new RdfFileGraphExporter(writer); + } + + if (GraphExporterNames.DOT_EXPORTER.equals(name)) { + return new DotFileGraphExporter(writer); + } + + throw new IllegalArgumentException(String.format("Unknown graph exporter name (current:'%s')", name)); + } +} diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/GraphExporterNames.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/GraphExporterNames.java new file mode 100644 index 0000000000000000000000000000000000000000..50a8355395539c0a5a8ada9249db5a842769e700 --- /dev/null +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/GraphExporterNames.java @@ -0,0 +1,6 @@ +package fr.tetras_libre.unltools.unl.exporters; + +public class GraphExporterNames { + public static final String DOT_EXPORTER = "DOT"; + public static final String RDF_EXPORTER = "RDF"; +} diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/print/dotFile/DotFileBuilder.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java similarity index 97% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/print/dotFile/DotFileBuilder.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java index 133bbd22145336f98bb042ac09ee3536153c6dc7..77105988e8891fe7eb1494c935e0d029715b39fa 100644 --- a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/print/dotFile/DotFileBuilder.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java @@ -1,4 +1,4 @@ -package fr.tetras_libre.unltools.unl.print.dotFile; +package fr.tetras_libre.unltools.unl.exporters.dot; import fr.tetras_libre.unltools.unl.*; @@ -8,7 +8,7 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; -public class DotFileBuilder implements GraphExporter { +public class DotFileGraphExporter implements GraphExporter { private final Writer writer; /** @@ -17,7 +17,7 @@ public class DotFileBuilder implements GraphExporter { * @param writer the writer * @throws IllegalArgumentException the writer is null */ - public DotFileBuilder(Writer writer) { + public DotFileGraphExporter(Writer writer) { if (null == writer) throw new IllegalArgumentException("The writer is null"); this.writer = writer; } diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/RdfFileBuilder.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/RdfFileGraphExporter.java similarity index 82% rename from rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/RdfFileBuilder.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/RdfFileGraphExporter.java index 856ffc633f78935f9cdafa5c457ecee66f45dc1d..c8c7364b29ac3f2b524c5c2c635aa480cb793b57 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/RdfFileBuilder.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/RdfFileGraphExporter.java @@ -1,4 +1,4 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; +package fr.tetras_libre.unltools.unl.exporters.rdf; import fr.tetras_libre.unltools.unl.GraphExporter; import fr.tetras_libre.unltools.unl.UnlDocument; @@ -8,11 +8,11 @@ import org.apache.jena.rdf.model.ModelFactory; import java.io.Writer; import java.util.List; -public class RdfFileBuilder implements GraphExporter { +public class RdfFileGraphExporter implements GraphExporter { private final UnlDocumentToRdfConverter converter; private final Writer writer; - public RdfFileBuilder(Writer writer) { + public RdfFileGraphExporter(Writer writer) { this.writer = writer; this.converter = new UnlDocumentToRdfConverter(); } diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/RelationLabelToUnlPropertyConverter.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/RelationLabelToUnlPropertyConverter.java similarity index 94% rename from rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/RelationLabelToUnlPropertyConverter.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/RelationLabelToUnlPropertyConverter.java index ac906bcc00bb80125fe18df87cf4c00c4ffb7310..2ab59e8c738215b4ac0260ed2ef491f631b37174 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/RelationLabelToUnlPropertyConverter.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/RelationLabelToUnlPropertyConverter.java @@ -1,8 +1,8 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; +package fr.tetras_libre.unltools.unl.exporters.rdf; +import fr.tetras_libre.rdf.vocabulary.UNL; import org.apache.jena.ontology.ObjectProperty; import org.apache.jena.ontology.OntModel; -import fr.tetras_libre.rdf.vocabulary.UNL; public class RelationLabelToUnlPropertyConverter { diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/Slugify.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/Slugify.java similarity index 73% rename from rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/Slugify.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/Slugify.java index 0fa0ed9b21544a98f35e257a9959133865481154..ef9d7178051a5d8f51b5f67d577dc4160231371b 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/Slugify.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/Slugify.java @@ -1,4 +1,4 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; +package fr.tetras_libre.unltools.unl.exporters.rdf; class Slugify { public static String slugify(String stringSource) { diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/UnlDocumentToRdfConverter.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/UnlDocumentToRdfConverter.java similarity index 95% rename from rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/UnlDocumentToRdfConverter.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/UnlDocumentToRdfConverter.java index 83d04c6db0a79b025b2ff708d624e858bf4ec31b..5b778b41582dfb77d57672ee49b2df7349f485ff 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/UnlDocumentToRdfConverter.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/UnlDocumentToRdfConverter.java @@ -1,9 +1,7 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; +package fr.tetras_libre.unltools.unl.exporters.rdf; import fr.tetras_libre.rdf.vocabulary.UNL; import fr.tetras_libre.unltools.unl.*; -import fr.tetras_libre.unltools.unl.extensions.GraphExtensions; -import fr.tetras_libre.unltools.unl.extensions.SubGraphReferenceNodeExtensions; import org.apache.jena.ontology.Individual; import org.apache.jena.ontology.OntModel; import org.apache.jena.ontology.Ontology; @@ -15,13 +13,11 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; -import static fr.tetras_libre.unltools.rdf.vocabulary.Slugify.slugify; - public class UnlDocumentToRdfConverter { private final static String DOMAIN = "http://rdf-unl.org"; private final static String Lang = null; - private RelationLabelToUnlPropertyConverter relationLabelToUnlPropertyConverter; + private final RelationLabelToUnlPropertyConverter relationLabelToUnlPropertyConverter; public UnlDocumentToRdfConverter() { relationLabelToUnlPropertyConverter = new RelationLabelToUnlPropertyConverter(); @@ -78,7 +74,7 @@ public class UnlDocumentToRdfConverter { var uw = (UniversalWordNode) sentenceNode; // Création de l'universalWord dans le dictionnaire - var universalWordIndividual = sentenceOntModel.createIndividual(String.format("%s/%s#%s", DOMAIN, uniqId, slugify(uw.getUniversalWord().toString())), UNL.UW_Lexeme); + var universalWordIndividual = sentenceOntModel.createIndividual(String.format("%s/%s#%s", DOMAIN, uniqId, Slugify.slugify(uw.getUniversalWord().toString())), UNL.UW_Lexeme); universalWordIndividual.addLabel(uw.getUniversalWord().toString(), UnlDocumentToRdfConverter.Lang); // Création de l'occurence du l'universalWord @@ -164,9 +160,9 @@ public class UnlDocumentToRdfConverter { public static String constructRelationUri(String scopeName, GraphRelation graphRelation) { return String.format("%s%s_%s_%s", scopeName, - slugify(constructRelationUri(graphRelation.getNode1())), + Slugify.slugify(constructRelationUri(graphRelation.getNode1())), graphRelation.getRelationLabel(), - slugify(constructRelationUri(graphRelation.getNode2()))); + Slugify.slugify(constructRelationUri(graphRelation.getNode2()))); } private static String constructRelationUri(GraphNode node) { diff --git a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/UtilGraphNodeUri.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/UtilGraphNodeUri.java similarity index 84% rename from rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/UtilGraphNodeUri.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/UtilGraphNodeUri.java index 9737041f4a44cd5141f3bc6d43826dba1896766c..5c20e5658328b1598552a858c13ab21650461a5b 100644 --- a/rdf/src/main/java/fr/tetras_libre/unltools/rdf/vocabulary/UtilGraphNodeUri.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/rdf/UtilGraphNodeUri.java @@ -1,11 +1,11 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; +package fr.tetras_libre.unltools.unl.exporters.rdf; import fr.tetras_libre.unltools.unl.GraphNode; import fr.tetras_libre.unltools.unl.SubGraphReferenceNode; +import fr.tetras_libre.unltools.unl.SubGraphReferenceNodeExtensions; import fr.tetras_libre.unltools.unl.UniversalWordNode; -import fr.tetras_libre.unltools.unl.extensions.SubGraphReferenceNodeExtensions; -import static fr.tetras_libre.unltools.rdf.vocabulary.Slugify.slugify; +import static fr.tetras_libre.unltools.unl.exporters.rdf.Slugify.slugify; class UtilGraphNodeUri { public static String constructGraphNodeUri(String namespace, GraphNode node) { diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/ParseException.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/ParseException.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/ParseException.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/ParseException.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/SimpleCharStream.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/SimpleCharStream.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/SimpleCharStream.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/SimpleCharStream.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/Token.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/Token.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/Token.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/Token.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/TokenMgrError.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/TokenMgrError.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/TokenMgrError.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/TokenMgrError.java 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 new file mode 100644 index 0000000000000000000000000000000000000000..f293807504a8bc545bdd7fa27ee2f18c7c2d8518 --- /dev/null +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java @@ -0,0 +1,33 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.GraphImporter; +import fr.tetras_libre.unltools.unl.UnlDocument; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.List; + +public class UnlGraphImporterFromUnlParser implements GraphImporter { + private List<UnlDocument> documents; + private BufferedReader bufferedReader; + + public UnlGraphImporterFromUnlParser(BufferedReader bufferedReader) { + this.bufferedReader = bufferedReader; + } + + public static UnlGraphImporterFromUnlParser FromInputReader(InputStreamReader inputStreamReader) { + return new UnlGraphImporterFromUnlParser(new BufferedReader(inputStreamReader)); + } + + @Override + public List<UnlDocument> Import() { + if (documents == null) { + try { + documents = new UnlParser(this.bufferedReader).createUnlDocumentList(); + } catch (ParseException e) { + e.printStackTrace(); + } + } + return documents; + } +} diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.jj b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.jj similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.jj rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParser.jj diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserConstants.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserConstants.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserConstants.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserConstants.java diff --git a/unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserTokenManager.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserTokenManager.java similarity index 100% rename from unl-parser/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserTokenManager.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlParserTokenManager.java diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/ApplicationStartupTest.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/ApplicationStartupTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e03137e20b486b6a049467884b6306f0f6602ee5 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/ApplicationStartupTest.java @@ -0,0 +1,49 @@ +package fr.tetras_libre.unltools; + +import fr.tetras_libre.unltools.Convert.ExportUnlDocuments; +import fr.tetras_libre.unltools.Convert.ExportUnlDocumentsHandler; +import fr.tetras_libre.unltools.cqrs.CommandHandlerResolver; +import fr.tetras_libre.unltools.cqrs.Result; +import fr.tetras_libre.unltools.unl.CatsUnl; +import fr.tetras_libre.unltools.unl.exporters.GraphExporterNames; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.concurrent.atomic.AtomicReference; + +public class ApplicationStartupTest { + + @Test + public void ApplicationShouldCreateSimpleHandlerWithoutException() { + var appService = ApplicationStartup.Initialize(CreateDefaultCommandResolver()); + var testCommand = new TestCommand(); + var handler = appService.getHandler(TestCommand.class); + + + AtomicReference<Result> resultAtomicReference = new AtomicReference<>(); + Assertions.assertDoesNotThrow(() -> resultAtomicReference.set(handler.handle(testCommand))); + Assertions.assertSame(resultAtomicReference.get(), Result.Success()); + } + + @Test + public void ApplicationShouldCreateHandlerWithContructorInjectionWithoutException() throws IOException { + var appService = ApplicationStartup.Initialize(CreateDefaultCommandResolver()); + var stringWriter = new StringWriter(); + var exportCommand = new ExportUnlDocuments(new CatsUnl(), GraphExporterNames.DOT_EXPORTER, stringWriter); + var handler = appService.getHandler(ExportUnlDocuments.class); + AtomicReference<Result> resultAtomicReference = new AtomicReference<>(); + + Assertions.assertDoesNotThrow(() -> resultAtomicReference.set(handler.handle(exportCommand))); + Assertions.assertFalse(stringWriter.toString().isBlank()); + stringWriter.close(); + } + + CommandHandlerResolver CreateDefaultCommandResolver() { + return new CommandHandlerResolverBuilder() + .addHandler(TestCommandHandler.class, TestCommand.class) + .addHandler(ExportUnlDocumentsHandler.class, ExportUnlDocuments.class) + .createCommandResolver(); + } +} \ No newline at end of file diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/TestCommand.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/TestCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..fc18c3fced86679d5156b6df6db5fdcc5744bea4 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/TestCommand.java @@ -0,0 +1,8 @@ +package fr.tetras_libre.unltools; + +import fr.tetras_libre.unltools.cqrs.Command; +import fr.tetras_libre.unltools.cqrs.Result; + +public class TestCommand implements Command<Result> { + +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/TestCommandHandler.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/TestCommandHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..6cfccd0b142ac0fc472080ca54d2f4a809d9f308 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/TestCommandHandler.java @@ -0,0 +1,16 @@ +package fr.tetras_libre.unltools; + +import fr.tetras_libre.unltools.cqrs.CommandHandler; +import fr.tetras_libre.unltools.cqrs.Result; + +public class TestCommandHandler implements CommandHandler<TestCommand, Result> { + + public TestCommandHandler() { + + } + + @Override + public Result handle(TestCommand command) { + return Result.Success(); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AbstractFlyweightUnlArgumentProvider.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AbstractFlyweightUnlArgumentProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..b1569e89e9f8173d09dad09d3470792b249f9568 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AbstractFlyweightUnlArgumentProvider.java @@ -0,0 +1,27 @@ +package fr.tetras_libre.unltools.unl; + +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.List; + +public abstract class AbstractFlyweightUnlArgumentProvider extends AbstractUnlArgumentProvider implements GraphImporter { + private static final Dictionary<Class<?>, List<UnlDocument>> values = new Hashtable<>(); + + protected abstract List<UnlDocument> buildUnlDocuments(); + + final public List<UnlDocument> getUnlDocuments() { + if (null == values.get(this.getClass())) { + synchronized (AbstractFlyweightUnlArgumentProvider.class) { + if (null == values.get(this.getClass())) { + values.put(this.getClass(), this.buildUnlDocuments()); + } + } + } + + return values.get(this.getClass()); + } + + final public List<UnlDocument> Import() { + return getUnlDocuments(); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AbstractUnlArgumentProvider.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AbstractUnlArgumentProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..8c9ac6b0b3171ad35bb0431bd53c49713ef0f930 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AbstractUnlArgumentProvider.java @@ -0,0 +1,18 @@ +package fr.tetras_libre.unltools.unl; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; + +import java.util.List; +import java.util.stream.Stream; + +public abstract class AbstractUnlArgumentProvider implements ArgumentsProvider { + + public abstract List<UnlDocument> getUnlDocuments(); + + @Override + public Stream<? extends Arguments> provideArguments(ExtensionContext context) { + return Stream.of(Arguments.of(getUnlDocuments())); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AllUnl.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AllUnl.java new file mode 100644 index 0000000000000000000000000000000000000000..43274beb44c472e96ea37a9739ec652c46c62084 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/AllUnl.java @@ -0,0 +1,17 @@ +package fr.tetras_libre.unltools.unl; + +import java.util.Collections; +import java.util.List; + +public class AllUnl extends AbstractFlyweightUnlArgumentProvider { + @Override + protected List<UnlDocument> buildUnlDocuments() { + var unlDocument = new UnlDocument("[D]"); + + unlDocument.add(R1Unl.buildSentenceNode()); + unlDocument.add(R2Unl.buildSentenceNode()); + unlDocument.add(CatsUnl.buildSentenceNode()); + + return Collections.singletonList(unlDocument); + } +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..951f79d7bb43909b9b76eccb287ce12f671a3ac5 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/CatsUnl.java @@ -0,0 +1,74 @@ +package fr.tetras_libre.unltools.unl; + +import java.util.*; + +public class CatsUnl extends AbstractFlyweightUnlArgumentProvider implements GraphImporter { + public static UnlDocumentNode buildSentenceNode() { + var graph = new Graph(); + + // mod + var restrictions = new TreeSet<Restriction>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("feline", new TreeSet<>(Collections.singletonList(new Restriction("icl", '>', new UniversalWord("thing", new TreeSet<>()))))))); + var uw = new UniversalWord("cat1", restrictions); + GraphNode uwNode = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@def")), ":01"); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("adj", new TreeSet<>()))); + uw = new UniversalWord("black", restrictions); + GraphNode uwNode2 = new UniversalWordNode(uw, new HashSet<>()); + + graph.add(new GraphRelation(uwNode, uwNode2, "mod", ":01")); + + // and + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("feline", new TreeSet<>(Collections.singletonList(new Restriction("icl", '>', new UniversalWord("thing", new TreeSet<>()))))))); + uw = new UniversalWord("cat1", restrictions); + uwNode = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@def")), ":01"); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("feline", new TreeSet<>(Collections.singletonList(new Restriction("icl", '>', new UniversalWord("thing", new TreeSet<>()))))))); + uw = new UniversalWord("cat2", restrictions); + uwNode2 = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@def")), ":02"); + + graph.add(new GraphRelation(uwNode, uwNode2, "and", ":01")); + + // mod + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("feline", new TreeSet<>(Collections.singletonList(new Restriction("icl", '>', new UniversalWord("thing", new TreeSet<>()))))))); + uw = new UniversalWord("cat2", restrictions); + uwNode = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@def")), ":02"); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("adj", new TreeSet<>()))); + uw = new UniversalWord("white", restrictions); + uwNode2 = new UniversalWordNode(uw, new HashSet<>()); + + graph.add(new GraphRelation(uwNode, uwNode2, "mod", ":01")); + + + // agt + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("consume", new TreeSet<>(Collections.singletonList(new Restriction("icl", '>', new UniversalWord("do", new TreeSet<>()))))))); + restrictions.add(new Restriction("agt", '>', new UniversalWord("living_thing", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("concrete_thing", new TreeSet<>()))); + restrictions.add(new Restriction("ins", '>', new UniversalWord("thing", new TreeSet<>()))); + uw = new UniversalWord("eat", restrictions); + uwNode = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@pl", ".@present", ".@progress"))); + + uwNode2 = new SubGraphReferenceNode(":01", new HashSet<>(Collections.singletonList(".@_hn-scope"))); + + graph.add(new GraphRelation(uwNode, uwNode2, "agt")); + + return new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:00]", graph); + } + + protected List<UnlDocument> buildUnlDocuments() { + var unlDocument = new UnlDocument("[D]"); + + UnlDocumentNode unlDocumentNode = buildSentenceNode(); + + unlDocument.add(unlDocumentNode); + + return Collections.singletonList(unlDocument); + } +} diff --git a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/CatUnlSentence.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/R1Unl.java similarity index 91% rename from rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/CatUnlSentence.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/R1Unl.java index 3e6d86d168740f2284f48960fc570d52f66f3bae..8d8af44297fde4546b232eafec06667d57d0d8da 100644 --- a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/CatUnlSentence.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/R1Unl.java @@ -1,21 +1,16 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; - -import fr.tetras_libre.unltools.unl.*; +package fr.tetras_libre.unltools.unl; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.TreeSet; -public class CatUnlSentence { - private static List<UnlDocument> unlDocuments; - - private static void buildUnlDocuments() { - var unlDocument = new UnlDocument("[D]"); +public class R1Unl extends AbstractFlyweightUnlArgumentProvider { + public static UnlDocumentNode buildSentenceNode() { var graph = new Graph(); - // aoj + // agt var restrictions = new TreeSet<Restriction>(); restrictions.add(new Restriction("icl", '>', new UniversalWord("be", new TreeSet<>()))); restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); @@ -64,7 +59,7 @@ public class CatUnlSentence { restrictions = new TreeSet<>(); restrictions.add(new Restriction("icl", '>', new UniversalWord("radiowave", new TreeSet<>()))); - uw = new UniversalWord("radiowave", restrictions); + uw = new UniversalWord("channel", restrictions); uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@indef"))); graph.add(new GraphRelation(uwNode, uwNode2, "ben")); @@ -120,7 +115,7 @@ public class CatUnlSentence { restrictions = new TreeSet<>(); restrictions.add(new Restriction("icl", '>', new UniversalWord("sensing", new TreeSet<>()))); uw = new UniversalWord("listening", restrictions); - uwNode2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@plu"))); + uwNode2 = new UniversalWordNode(uw, new HashSet<>()); graph.add(new GraphRelation(uwNode, uwNode2, "cnt")); @@ -137,18 +132,18 @@ public class CatUnlSentence { graph.add(new GraphRelation(uwNode, uwNode2, "and")); - var unlDocumentNode = new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:R1]", graph); + return new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:R1]", graph); + } - unlDocument.add(unlDocumentNode); + @Override + final protected List<UnlDocument> buildUnlDocuments() { - unlDocuments.add(unlDocument); - } + var unlDocument = new UnlDocument("[D]"); + + UnlDocumentNode unlDocumentNode = buildSentenceNode(); - public static List<UnlDocument> getUnlDocuments() { - if (null == unlDocuments) { - buildUnlDocuments(); - } + unlDocument.add(unlDocumentNode); - return unlDocuments; + return Collections.singletonList(unlDocument); } } diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/R2Unl.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/R2Unl.java new file mode 100644 index 0000000000000000000000000000000000000000..78bf75398a11eb551c2efa6fe29efc70d934a963 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/R2Unl.java @@ -0,0 +1,145 @@ +package fr.tetras_libre.unltools.unl; + +import java.util.*; + +public class R2Unl extends AbstractFlyweightUnlArgumentProvider { + + public static UnlDocumentNode buildSentenceNode() { + var graph = new Graph(); + + // agt + var restrictions = new TreeSet<Restriction>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("show", new TreeSet<>()))); + restrictions.add(new Restriction("equ", '>', new UniversalWord("exhibit", new TreeSet<>()))); + restrictions.add(new Restriction("agt", '>', new UniversalWord("thing", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("thing", new TreeSet<>()))); + var uw = new UniversalWord("display", restrictions); + GraphNode node1 = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@present"))); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("group", new TreeSet<>()))); + uw = new UniversalWord("system", restrictions); + GraphNode node2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@def"))); + + graph.add(new GraphRelation(node1, node2, "agt")); + + // mod + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("radiowave", new TreeSet<>()))); + uw = new UniversalWord("channel", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@indef"))); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("adj", new TreeSet<>()))); + restrictions.add(new Restriction("iof", '>', new UniversalWord("color", new TreeSet<>()))); + uw = new UniversalWord("green", restrictions); + node2 = new UniversalWordNode(uw, new HashSet<>()); + + graph.add(new GraphRelation(node1, node2, "mod")); + + // obj + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("show", new TreeSet<>()))); + restrictions.add(new Restriction("equ", '>', new UniversalWord("exhibit", new TreeSet<>()))); + restrictions.add(new Restriction("agt", '>', new UniversalWord("thing", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("thing", new TreeSet<>()))); + uw = new UniversalWord("display", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@present"))); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("radiowave", new TreeSet<>()))); + uw = new UniversalWord("channel", restrictions); + node2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@indef"))); + + graph.add(new GraphRelation(node1, node2, "obj")); + + // tim + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("show", new TreeSet<>()))); + restrictions.add(new Restriction("equ", '>', new UniversalWord("exhibit", new TreeSet<>()))); + restrictions.add(new Restriction("agt", '>', new UniversalWord("thing", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("thing", new TreeSet<>()))); + uw = new UniversalWord("display", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@present"))); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("how", new TreeSet<>()))); + restrictions.add(new Restriction("com", '>', new UniversalWord("always", new TreeSet<>()))); + restrictions.add(new Restriction("tim", '<', new UniversalWord("uw", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("uw", new TreeSet<>()))); + uw = new UniversalWord("when", restrictions); + node2 = new UniversalWordNode(uw, new HashSet<>()); + + graph.add(new GraphRelation(node1, node2, "tim")); + + // aoj + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); + restrictions.add(new Restriction("icl", '>', new UniversalWord("be", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("state", new TreeSet<>()))); + uw = new UniversalWord("be_in_a_state", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@present"))); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("radiowave", new TreeSet<>()))); + uw = new UniversalWord("channel", restrictions); + node2 = new UniversalWordNode(uw, new HashSet<>(Collections.singletonList(".@indef"))); + + graph.add(new GraphRelation(node1, node2, "aoj", ":01")); + + // plc + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("attribute", new TreeSet<>()))); + uw = new UniversalWord("state", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>()); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("message", new TreeSet<>()))); + uw = new UniversalWord("broadcast", restrictions); + node2 = new UniversalWordNode(uw, new HashSet<>()); + + graph.add(new GraphRelation(node1, node2, "plc", ":01")); + + // obj + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("aoj", '>', new UniversalWord("thing", new TreeSet<>()))); + restrictions.add(new Restriction("icl", '>', new UniversalWord("be", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("state", new TreeSet<>()))); + uw = new UniversalWord("be_in_a_state", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>(Arrays.asList(".@entry", ".@present"))); + + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("attribute", new TreeSet<>()))); + uw = new UniversalWord("state", restrictions); + node2 = new UniversalWordNode(uw, new HashSet<>()); + + graph.add(new GraphRelation(node1, node2, "obj", ":01")); + + // obj + restrictions = new TreeSet<>(); + restrictions.add(new Restriction("icl", '>', new UniversalWord("how", new TreeSet<>()))); + restrictions.add(new Restriction("com", '>', new UniversalWord("always", new TreeSet<>()))); + restrictions.add(new Restriction("tim", '<', new UniversalWord("uw", new TreeSet<>()))); + restrictions.add(new Restriction("obj", '>', new UniversalWord("uw", new TreeSet<>()))); + uw = new UniversalWord("when", restrictions); + node1 = new UniversalWordNode(uw, new HashSet<>()); + + node2 = new SubGraphReferenceNode(":01"); + + graph.add(new GraphRelation(node1, node2, "obj")); + + return new UnlDocumentNode(UnlDocumentNodeType.Sentence, "[S:R2]", graph); + } + + @Override + final protected List<UnlDocument> buildUnlDocuments() { + + var unlDocument = new UnlDocument("[D]"); + + UnlDocumentNode unlDocumentNode = buildSentenceNode(); + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..6c4c52527cd1caedf7d7090a10d26d500f7080bb --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/UnlSentences.java @@ -0,0 +1,96 @@ +package fr.tetras_libre.unltools.unl; + +public class UnlSentences { + public static final String R1 = "[D]\n" + + "[S:R1]\n" + + "{org:en}\n" + + "The system allows a radio channel to take on two states: Listening and Traffic.\n" + + "{/org}\n" + + "{unl}\n" + + "aoj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, system(icl>group).@def )\n" + + "obj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, take_on(aoj>thing, equ>assume,icl>change, obj>thing) )\n" + + "ben( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, channel(icl>radiowave).@indef)\n" + + "aoj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), channel(icl>radiowave).@indef ) \n" + + "obj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), state(icl>attribute).@plu ) \n" + + "qua( state(icl>attribute).@plu, 2 ) \n" + + "cnt( state(icl>attribute).@plu, listening(icl>sensing) )\n" + + "and( listening(icl>sensing),traffic(icl>communication) )\n" + + "{/unl}\n" + + "[/S]\n" + + "[/D]"; + + public static final String R2 = "[D]\n" + + "[S:R2]\n" + + "{org:en}\n" + + "The system displays a channel in green when it is in broadcast state. \n" + + "{/org}\n" + + "{unl}\n" + + "agt(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,system(icl>group).@def)\n" + + "mod(channel(icl>radiowave).@indef,green(icl>adj,iof>color))\n" + + "obj(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,channel(icl>radiowave).@indef)\n" + + "tim(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,when(icl>how,com>always,tim<uw,obj>uw))\n" + + "aoj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,channel(icl>radiowave).@indef)\n" + + "plc:01(state(icl>attribute),broadcast(icl>message))\n" + + "obj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,state(icl>attribute))\n" + + "obj(when(icl>how,com>always,tim<uw,obj>uw),:01)\n" + + "{/unl}\n" + + "[/S] \n" + + "[/D] \n"; + + public static final String Cats = "[D]" + + "[S:00]\n" + + "{org:en}\n" + + "The black cat and the white cat are eating.\n" + + "{/org}\n" + + "{unl}\n" + + "mod:01(cat1(icl>feline>thing):01.@entry.@def,black(icl>adj))\n" + + "and:01(cat1(icl>feline>thing):01.@entry.@def,cat2(icl>feline>thing):02.@entry.@def)\n" + + "mod:01(cat2(icl>feline>thing):02.@entry.@def,white(icl>adj))\n" + + "agt(eat(icl>consume>do,agt>living_thing,obj>concrete_thing,ins>thing).@entry.@pl.@present.@progress,:01.@_hn-scope)\n" + + "{/unl}\n" + + "[/S]\n"; + + public static final String All = "[D]" + + "[S:R1]\n" + + "{org:en}\n" + + "The system allows a radio channel to take on two states: Listening and Traffic.\n" + + "{/org}\n" + + "{unl}\n" + + "aoj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, system(icl>group).@def )\n" + + "obj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, take_on(aoj>thing, equ>assume,icl>change, obj>thing) )\n" + + "ben( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, channel(icl>radiowave).@indef)\n" + + "aoj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), channel(icl>radiowave).@indef) \n" + + "obj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), state(icl>attribute).@plu ) \n" + + "qua( state(icl>attribute).@plu, 2 ) \n" + + "cnt( state(icl>attribute).@plu, listening(icl>sensing) )\n" + + "and( listening(icl>sensing),traffic(icl>communication) )\n" + + "{/unl}\n" + + "[/S]\n" + + "[S:R2]\n" + + "{org:en}\n" + + "The system displays a channel in green when it is in broadcast state. \n" + + "{/org}\n" + + "{unl}\n" + + "agt(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,system(icl>group).@def)\n" + + "mod(channel(icl>radiowave).@indef,green(icl>adj,iof>color))\n" + + "obj(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,channel(icl>radiowave).@indef)\n" + + "tim(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,when(icl>how,com>always,tim<uw,obj>uw))\n" + + "aoj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,channel(icl>radiowave).@indef)\n" + + "plc:01(state(icl>attribute),broadcast(icl>message))\n" + + "obj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,state(icl>attribute))\n" + + "obj(when(icl>how,com>always,tim<uw,obj>uw),:01)\n" + + "{/unl}\n" + + "[/S] \n" + + "[S:00]\n" + + "{org:en}\n" + + "The black cat and the white cat are eating.\n" + + "{/org}\n" + + "{unl}\n" + + "mod:01(cat1(icl>feline>thing):01.@entry.@def,black(icl>adj))\n" + + "and:01(cat1(icl>feline>thing):01.@entry.@def,cat2(icl>feline>thing):02.@entry.@def)\n" + + "mod:01(cat2(icl>feline>thing):02.@entry.@def,white(icl>adj))\n" + + "agt(eat(icl>consume>do,agt>living_thing,obj>concrete_thing,ins>thing).@entry.@pl.@present.@progress,:01.@_hn-scope)\n" + + "{/unl}\n" + + "[/S]\n" + + "[/D]"; +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/AllSetenceWithExpectedDotChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/AllSetenceWithExpectedDotChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..1d014e578ca4384825db0cbb2eedc01c9a79dbd6 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/AllSetenceWithExpectedDotChecker.java @@ -0,0 +1,114 @@ +package fr.tetras_libre.unltools.unl.exporters.dot; + +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class AllSetenceWithExpectedDotChecker extends SentenceWithExpectedDotChecker { + private static final String ALL = UnlSentences.All; + + private static final String ALL_DOT = "digraph G {\n" + + "graph [fontname=\"courier\", compound=\"true\"];\n" + + "1 [\n" + + "label=\"allow(aoj>thing,ben>thing,equ>make_possible,icl>be,obj>uw)\\n.@entry\"\n" + + "shape=\"box\"\n" + + "fontname=\"courb\"\n" + + "];\n" + + "2 [\n" + + "label=\"system(icl>group)\\n.@def\"\n" + + "shape=\"box\"\n" + + "];\n" + + "3 [\n" + + "label=\"take_on(aoj>thing,equ>assume,icl>change,obj>thing)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "4 [\n" + + "label=\"channel(icl>radiowave)\\n.@indef\"\n" + + "shape=\"box\"\n" + + "];\n" + + "5 [\n" + + "label=\"state(icl>attribute)\\n.@plu\"\n" + + "shape=\"box\"\n" + + "];\n" + + "6 [\n" + + "label=\"2\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "7 [\n" + + "label=\"listening(icl>sensing)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "8 [\n" + + "label=\"traffic(icl>communication)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "1 -> 2 [label=\"aoj\" ];\n" + + "1 -> 3 [label=\"obj\" ];\n" + + "1 -> 4 [label=\"ben\" ];\n" + + "3 -> 4 [label=\"aoj\" ];\n" + + "3 -> 5 [label=\"obj\" ];\n" + + "5 -> 6 [label=\"qua\" ];\n" + + "5 -> 7 [label=\"cnt\" ];\n" + + "7 -> 8 [label=\"and\" ];\n" + + "}\n" + + "digraph G {\n" + + "graph [fontname=\"courier\", compound=\"true\"];\n" + + "1 [\n" + + "label=\"display(agt>thing,equ>exhibit,icl>show,obj>thing)\\n.@entry.@present\"\n" + + "shape=\"box\"\n" + + "fontname=\"courb\"\n" + + "];\n" + + "2 [\n" + + "label=\"system(icl>group)\\n.@def\"\n" + + "shape=\"box\"\n" + + "];\n" + + "3 [\n" + + "label=\"channel(icl>radiowave)\\n.@indef\"\n" + + "shape=\"box\"\n" + + "];\n" + + "4 [\n" + + "label=\"green(icl>adj,iof>color)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "5 [\n" + + "label=\"when(com>always,icl>how,obj>uw,tim<uw)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "6 [\n" + + "label=\"be_in_a_state(aoj>thing,icl>be,obj>state)\\n.@entry.@present\"\n" + + "shape=\"box\"\n" + + "fontname=\"courb\"\n" + + "];\n" + + "7 [\n" + + "label=\"state(icl>attribute)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "8 [\n" + + "label=\"broadcast(icl>message)\\n\"\n" + + "shape=\"box\"\n" + + "];\n" + + "subgraph cluster_01{\n" + + " color = black;\n" + + " label = \":01\"6 -> 3 [label=\"aoj\" ];\n" + + "7 -> 8 [label=\"plc\" ];\n" + + "6 -> 7 [label=\"obj\" ];\n" + + "}\n" + + "1 -> 2 [label=\"agt\" ];\n" + + "3 -> 4 [label=\"mod\" ];\n" + + "1 -> 3 [label=\"obj\" ];\n" + + "1 -> 5 [label=\"tim\" ];\n" + + "5 -> 6 [label=\"obj\" lhead=\"cluster_01\"];\n" + + "}\n" + + "digraph G {\n" + + "graph [fontname=\"courier\", compound=\"true\"];\n" + + "1 [ label=\"cat1(icl>feline(icl>thing)):01\\n.@def.@entry\" shape=\"box\" fontname=\"courb\" ];\n" + + "2 [ label=\"black(icl>adj)\\n\" shape=\"box\" ];\n" + + "3 [ label=\"cat2(icl>feline(icl>thing)):02\\n.@def.@entry\" shape=\"box\" fontname=\"courb\" ];\n" + + "4 [ label=\"white(icl>adj)\\n\" shape=\"box\" ];\n" + + "5 [ label=\"eat(agt>living_thing,icl>consume(icl>do),ins>thing,obj>concrete_thing)\\n.@entry.@present.@pl.@progress\" shape=\"box\" fontname=\"courb\" ];" + + " subgraph cluster_01{ color = black; label = \":01\"1 -> 2 [label=\"mod\" ]; 1 -> 3 [label=\"and\" ]; 3 -> 4 [label=\"mod\" ]; }\n" + + "5 -> 1 [label=\"agt\" lhead=\"cluster_01\"];\n" + + "}\n"; + + public AllSetenceWithExpectedDotChecker() { + super(ALL, ALL_DOT); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/CatSentenceWithExpectedDotChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/CatSentenceWithExpectedDotChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..6a0e545c1e4ccbe6d90591dd1769126916b4f473 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/CatSentenceWithExpectedDotChecker.java @@ -0,0 +1,23 @@ +package fr.tetras_libre.unltools.unl.exporters.dot; + +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class CatSentenceWithExpectedDotChecker extends SentenceWithExpectedDotChecker { + + private static final String CAT_UNL = UnlSentences.Cats; + + private static final String CAT_DOT = "digraph G {\n" + + "graph [fontname=\"courier\", compound=\"true\"];\n" + + "1 [ label=\"cat1(icl>feline(icl>thing)):01\\n.@def.@entry\" shape=\"box\" fontname=\"courb\" ];\n" + + "2 [ label=\"black(icl>adj)\\n\" shape=\"box\" ];\n" + + "3 [ label=\"cat2(icl>feline(icl>thing)):02\\n.@def.@entry\" shape=\"box\" fontname=\"courb\" ];\n" + + "4 [ label=\"white(icl>adj)\\n\" shape=\"box\" ];\n" + + "5 [ label=\"eat(agt>living_thing,icl>consume(icl>do),ins>thing,obj>concrete_thing)\\n.@entry.@present.@pl.@progress\" shape=\"box\" fontname=\"courb\" ];" + + " subgraph cluster_01{ color = black; label = \":01\"1 -> 2 [label=\"mod\" ]; 1 -> 3 [label=\"and\" ]; 3 -> 4 [label=\"mod\" ]; }\n" + + "5 -> 1 [label=\"agt\" lhead=\"cluster_01\"];\n" + + "}\n"; + + public CatSentenceWithExpectedDotChecker() { + super(CAT_UNL, CAT_DOT); + } +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..daba156b658c145b6815099d0f69851f5130489f --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileBuilderTest.java @@ -0,0 +1,49 @@ +package fr.tetras_libre.unltools.unl.exporters.dot; + +import fr.tetras_libre.unltools.unl.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.StringWriter; +import java.io.Writer; +import java.util.List; + +class DotFileBuilderTest { + + @Test + public void r1ShouldBeConvertedToDotFileWithoutException() { + writeInFile(new R1Unl().getUnlDocuments(), new R1SentenceWithExpectedDotChecker()); + } + + @Test + public void r2ShouldBeConvertedToDotFileWithoutException() { + this.writeInFile(new R2Unl().getUnlDocuments(), new R2SentenceWithExpectedDotChecker()); + } + + @Test + public void CatsShouldBeConvertedToDotFileWithoutException() { + this.writeInFile(new CatsUnl().getUnlDocuments(), new CatSentenceWithExpectedDotChecker()); + } + + @Test + public void allShouldBeConvertedToDotFileWithoutException() { + this.writeInFile(new AllUnl().getUnlDocuments(), new AllSetenceWithExpectedDotChecker()); + } + + private void writeInFile(List<UnlDocument> unlDocuments, SentenceWithExpectedDotChecker sentenceChecker) { + // Startup + Writer strResult = new StringWriter(); + DotFileGraphExporter dotFileBuilder = new DotFileGraphExporter(strResult); + + // Test + Assertions.assertDoesNotThrow(() -> dotFileBuilder.write(unlDocuments)); + + // Teardown + Assertions.assertDoesNotThrow(() -> strResult.flush()); + Assertions.assertTrue(() -> strResult.toString().length() != 0); + Assertions.assertDoesNotThrow(() -> sentenceChecker.setCurrentDotContent(strResult.toString())); + sentenceChecker.assetSameAsExpected(); + Assertions.assertDoesNotThrow(() -> strResult.close()); + + } +} \ No newline at end of file diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/R1SentenceWithExpectedDotChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/R1SentenceWithExpectedDotChecker.java similarity index 60% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/R1SentenceWithExpectedDotChecker.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/R1SentenceWithExpectedDotChecker.java index 39601661872053bdbd59ee07a0e9206d05ad8d60..62f8bb45e2738b0d148596c28a639fc37e27e08a 100644 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/R1SentenceWithExpectedDotChecker.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/R1SentenceWithExpectedDotChecker.java @@ -1,23 +1,9 @@ -package fr.tetras_libre.unltools.unl; +package fr.tetras_libre.unltools.unl.exporters.dot; + +import fr.tetras_libre.unltools.unl.UnlSentences; public class R1SentenceWithExpectedDotChecker extends SentenceWithExpectedDotChecker { - private static final String R1_UNL = "[D]\n" + - "[S:R1]\n" + - "{org:en}\n" + - "The system allows a radio channel to take on two states: Listening and Traffic.\n" + - "{/org}\n" + - "{unl}\n" + - "aoj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, system(icl>group).@def )\n" + - "obj( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, take_on(aoj>thing, equ>assume,icl>change, obj>thing) )\n" + - "ben( allow(icl>be, aoj>thing, ben>thing, obj>uw, equ>make_possible).@entry, channel(icl>radiowave).@indef)\n" + - "aoj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), channel(icl>radiowave).@indef ) \n" + - "obj( take_on(aoj>thing, equ>assume, icl>change, obj>thing), state(icl>attribute).@plu ) \n" + - "qua( state(icl>attribute).@plu, 2 ) \n" + - "cnt( state(icl>attribute).@plu, listening(icl>sensing) )\n" + - "and( listening(icl>sensing),traffic(icl>communication) )\n" + - "{/unl}\n" + - "[/S]\n" + - "[/D]"; + private static final String R1_UNL = UnlSentences.R1; private static final String R1_DOT = "digraph G {\n" + "graph [fontname=\"courier\", compound=\"true\"];\n" + diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/R2SentenceWithExpectedDotChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/R2SentenceWithExpectedDotChecker.java similarity index 63% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/R2SentenceWithExpectedDotChecker.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/R2SentenceWithExpectedDotChecker.java index 141d786c2a8d37075b65bcedaddf9c72c70ae143..374cc97df7dfe70b20263f70d5a99d615058653f 100644 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/R2SentenceWithExpectedDotChecker.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/R2SentenceWithExpectedDotChecker.java @@ -1,23 +1,9 @@ -package fr.tetras_libre.unltools.unl; +package fr.tetras_libre.unltools.unl.exporters.dot; + +import fr.tetras_libre.unltools.unl.UnlSentences; public class R2SentenceWithExpectedDotChecker extends SentenceWithExpectedDotChecker { - private static final String R2_UNL = "[D]\n" + - "[S:R2]\n" + - "{org:en}\n" + - "The system displays a channel in green when it is in broadcast state. \n" + - "{/org}\n" + - "{unl}\n" + - "agt(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,system(icl>group).@def)\n" + - "mod(channel(icl>radiowave).@indef,green(icl>adj,iof>color))\n" + - "obj(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,channel(icl>radiowave).@indef)\n" + - "tim(display(icl>show,equ>exhibit,agt>thing,obj>thing).@entry.@present,when(icl>how,com>always,tim<uw,obj>uw))\n" + - "aoj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,channel(icl>radiowave).@indef)\n" + - "plc:01(state(icl>attribute),broadcast(icl>message))\n" + - "obj:01(be_in_a_state(aoj>thing,icl>be,obj>state).@entry.@present,state(icl>attribute))\n" + - "obj(when(icl>how,com>always,tim<uw,obj>uw),:01)\n" + - "{/unl}\n" + - "[/S] \n" + - "[/D] \n"; + private static final String R2_UNL = UnlSentences.R2; private static final String R2_DOT = "digraph G {\n" + "graph [fontname=\"courier\", compound=\"true\"];\n" + diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/SentenceWithExpectedDotArgumentProvider.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/SentenceWithExpectedDotArgumentProvider.java similarity index 93% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/SentenceWithExpectedDotArgumentProvider.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/SentenceWithExpectedDotArgumentProvider.java index f8a239dfe1ffefd7480d0966b5cd3915d3085824..769aae6efab7482cfc9a4b0fd64fa17dc2e6c8d6 100644 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/SentenceWithExpectedDotArgumentProvider.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/SentenceWithExpectedDotArgumentProvider.java @@ -1,4 +1,4 @@ -package fr.tetras_libre.unltools.unl; +package fr.tetras_libre.unltools.unl.exporters.dot; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/SentenceWithExpectedDotChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/SentenceWithExpectedDotChecker.java similarity index 79% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/SentenceWithExpectedDotChecker.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/SentenceWithExpectedDotChecker.java index 93b691de260eab2c65d41b4e45f703c1b54145dd..e59ac0be81b363497640cde1c95b414168103347 100644 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/SentenceWithExpectedDotChecker.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/dot/SentenceWithExpectedDotChecker.java @@ -1,4 +1,4 @@ -package fr.tetras_libre.unltools.unl; +package fr.tetras_libre.unltools.unl.exporters.dot; import org.junit.jupiter.api.Assertions; @@ -19,18 +19,10 @@ public abstract class SentenceWithExpectedDotChecker { return this.unlSentence; } - protected void setUnlSentence(String unlSentence) { - this.unlSentence = null == unlSentence ? "" : unlSentence; - } - public String getExpectedDotContent() { return this.expectedDotContent; } - public void setExpectedDotContent(String expectedDotContent) { - this.expectedDotContent = expectedDotContent; - } - public String getCurrentDotContent() { return currentDotContent; } diff --git a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/RdfSchemaOfUNLTest.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/rdf/RdfSchemaOfUNLTest.java similarity index 67% rename from rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/RdfSchemaOfUNLTest.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/rdf/RdfSchemaOfUNLTest.java index 7e0ec8743d592a551f9cdf1e7df5afa6603263c4..701283599fd9e618f7dee6ebd678c5b61b799233 100644 --- a/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/RdfSchemaOfUNLTest.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/rdf/RdfSchemaOfUNLTest.java @@ -1,6 +1,7 @@ -package fr.tetras_libre.unltools.rdf.vocabulary; +package fr.tetras_libre.unltools.unl.exporters.rdf; import fr.tetras_libre.rdf.vocabulary.UNL; +import fr.tetras_libre.unltools.unl.R1Unl; import fr.tetras_libre.unltools.unl.UnlDocument; import org.apache.jena.rdf.model.ModelFactory; import org.junit.jupiter.api.Assertions; @@ -11,21 +12,28 @@ import org.junit.jupiter.params.provider.ArgumentsSource; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.util.LinkedList; +import java.util.List; class RdfSchemaOfUNLTest { @Test - void createRdfOfUnlSentence() throws IOException { + void createIndividualsWithSameUriGivesSameInstance() { var model = ModelFactory.createOntologyModel(); var el1 = model.createIndividual("blablabla", UNL.UNL_Sentence); var el2 = model.createIndividual("blablabla", UNL.UNL_Sentence); - // egalité réference - var refEquals = el1 == el2; + // reference equality + Assertions.assertSame(el1, el2); + + // content equality + Assertions.assertEquals(el1, el2); + } - // egalite de contenu - var contentEquals = el1.equals(el2); + @Test + void createRdfOfUnlSentence() throws IOException { + var model = ModelFactory.createOntologyModel(); + var el1 = model.createIndividual("blablabla", UNL.UNL_Sentence); + var el2 = model.createIndividual("blablabla", UNL.UNL_Sentence); Writer writer = new StringWriter(); model.write(writer, "TURTLE"); @@ -35,8 +43,8 @@ class RdfSchemaOfUNLTest { } @ParameterizedTest - @ArgumentsSource(R1SentenceWithExpectedRdf.class) - void createUnlDocument(LinkedList<UnlDocument> unlDocuments) throws IOException { + @ArgumentsSource(R1Unl.class) + void createUnlDocument(List<UnlDocument> unlDocuments) throws IOException { var unlDocumentToRdfConverter = new UnlDocumentToRdfConverter(); var ontModels = unlDocumentToRdfConverter.convertToOntModel(unlDocuments); diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/rdf/RelationLabelToUnlPropertyConverterTest.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/rdf/RelationLabelToUnlPropertyConverterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a6d4200b0ecd8623b6c54f0560c3358546a822e7 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/exporters/rdf/RelationLabelToUnlPropertyConverterTest.java @@ -0,0 +1,28 @@ +package fr.tetras_libre.unltools.unl.exporters.rdf; + +import org.apache.jena.ontology.ObjectProperty; +import org.apache.jena.rdf.model.ModelFactory; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.atomic.AtomicReference; + +class RelationLabelToUnlPropertyConverterTest { + + @Test + public void getObjectPropertyShouldGiveAssociatedUNLressource() { + var relationLabelToUnlProperty = new RelationLabelToUnlPropertyConverter(); + + Assertions.assertDoesNotThrow(() -> relationLabelToUnlProperty.getObjectProperty("aoj", null)); + } + + @Test + public void getObjectPropertyShouldNotThrowOnUnknownResource() { + AtomicReference<ObjectProperty> objectPropertyAtomicReference = new AtomicReference<>(); + var relationLabelToUnlProperty = new RelationLabelToUnlPropertyConverter(); + var unknownProperty = "dfadsfijoplknkjadfljgliukjelkjkdm"; + var docModel = ModelFactory.createOntologyModel(); + + Assertions.assertDoesNotThrow(() -> objectPropertyAtomicReference.set(relationLabelToUnlProperty.getObjectProperty(unknownProperty, docModel))); + } +} \ No newline at end of file diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/AllSentenceWithExpectedUnlDocumentsChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/AllSentenceWithExpectedUnlDocumentsChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..da29d161263291a6eda0e3651471db6586a2a165 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/AllSentenceWithExpectedUnlDocumentsChecker.java @@ -0,0 +1,10 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.AllUnl; +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class AllSentenceWithExpectedUnlDocumentsChecker extends SentenceWithExpectedUnlDocumentsChecker { + public AllSentenceWithExpectedUnlDocumentsChecker() { + super(UnlSentences.All, new AllUnl().getUnlDocuments()); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/CatsSentenceWithExpectedUnlDocumentsChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/CatsSentenceWithExpectedUnlDocumentsChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..51b46f7da87e32ae411d8aa0a45b6a9c55773d12 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/CatsSentenceWithExpectedUnlDocumentsChecker.java @@ -0,0 +1,10 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.CatsUnl; +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class CatsSentenceWithExpectedUnlDocumentsChecker extends SentenceWithExpectedUnlDocumentsChecker { + public CatsSentenceWithExpectedUnlDocumentsChecker() { + super(UnlSentences.Cats, new CatsUnl().getUnlDocuments()); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/R1SentenceWithExpectedUnlDocumentsChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/R1SentenceWithExpectedUnlDocumentsChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..b6aa89b3d068946c1e7b6be56276e949ba3b3e43 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/R1SentenceWithExpectedUnlDocumentsChecker.java @@ -0,0 +1,10 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.R1Unl; +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class R1SentenceWithExpectedUnlDocumentsChecker extends SentenceWithExpectedUnlDocumentsChecker { + public R1SentenceWithExpectedUnlDocumentsChecker() { + super(UnlSentences.R1, new R1Unl().getUnlDocuments()); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/R2SentenceWithExpectedUnlDocumentsChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/R2SentenceWithExpectedUnlDocumentsChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..15fdeb5ed60b5895e6ce6848770d32cafc3e2593 --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/R2SentenceWithExpectedUnlDocumentsChecker.java @@ -0,0 +1,10 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.R2Unl; +import fr.tetras_libre.unltools.unl.UnlSentences; + +public class R2SentenceWithExpectedUnlDocumentsChecker extends SentenceWithExpectedUnlDocumentsChecker { + public R2SentenceWithExpectedUnlDocumentsChecker() { + super(UnlSentences.R2, new R2Unl().getUnlDocuments()); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/SentenceWithExpectedUnlDocumentsArgumentProvider.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/SentenceWithExpectedUnlDocumentsArgumentProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..b3d7f6ba1249646b6b984bbe3808a220d82d6fda --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/SentenceWithExpectedUnlDocumentsArgumentProvider.java @@ -0,0 +1,21 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.exporters.dot.AllSetenceWithExpectedDotChecker; +import fr.tetras_libre.unltools.unl.exporters.dot.CatSentenceWithExpectedDotChecker; +import fr.tetras_libre.unltools.unl.exporters.dot.R1SentenceWithExpectedDotChecker; +import fr.tetras_libre.unltools.unl.exporters.dot.R2SentenceWithExpectedDotChecker; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; + +import java.util.stream.Stream; + +public class SentenceWithExpectedUnlDocumentsArgumentProvider implements ArgumentsProvider { + @Override + public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { + return Stream.of(Arguments.of(new R1SentenceWithExpectedDotChecker()), + Arguments.of(new R2SentenceWithExpectedDotChecker()), + Arguments.of(new CatSentenceWithExpectedDotChecker()), + Arguments.of(new AllSetenceWithExpectedDotChecker())); + } +} diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/SentenceWithExpectedUnlDocumentsChecker.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/SentenceWithExpectedUnlDocumentsChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..6aebfb090b220c1edb6b0fafdf0b8b6736ff9f1f --- /dev/null +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/SentenceWithExpectedUnlDocumentsChecker.java @@ -0,0 +1,40 @@ +package fr.tetras_libre.unltools.unl.parser; + +import fr.tetras_libre.unltools.unl.UnlDocument; +import org.junit.jupiter.api.Assertions; + +import java.util.List; + +public class SentenceWithExpectedUnlDocumentsChecker { + private final List<UnlDocument> expectedUnlDocuments; + private String unlSentence; + private List<UnlDocument> currentUnlDocuments; + + public SentenceWithExpectedUnlDocumentsChecker(String unlSentence, List<UnlDocument> expectedUnlDocuments) { + if ((null == unlSentence) || (null == expectedUnlDocuments)) { + throw new IllegalArgumentException(); + } + this.unlSentence = unlSentence; + this.expectedUnlDocuments = expectedUnlDocuments; + } + + public String getUnlSentence() { + return this.unlSentence; + } + + public List<UnlDocument> getExpectedDotContent() { + return this.expectedUnlDocuments; + } + + public List<UnlDocument> getCurrentDotContent() { + return this.currentUnlDocuments; + } + + public void setCurrentUnlDocuments(List<UnlDocument> currentUnlDocuments) { + this.currentUnlDocuments = currentUnlDocuments; + } + + public void assetSameAsExpected() { + Assertions.assertIterableEquals(this.expectedUnlDocuments, this.currentUnlDocuments); + } +} diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactory.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactory.java similarity index 100% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactory.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactory.java diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactoryFromString.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactoryFromString.java similarity index 100% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactoryFromString.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserFactoryFromString.java diff --git a/unl-parser/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 similarity index 56% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserTest.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/UnlParserTest.java index ff62eaa5989bf05b825fbd28fc1d9ddd344dc933..7bc9410c46b7cfd8b6c8a661f7b236345b116839 100644 --- a/unl-parser/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 @@ -1,28 +1,29 @@ package fr.tetras_libre.unltools.unl.parser; -import fr.tetras_libre.unltools.unl.SentenceWithExpectedDotArgumentProvider; -import fr.tetras_libre.unltools.unl.SentenceWithExpectedDotChecker; import fr.tetras_libre.unltools.unl.UnlDocument; +import fr.tetras_libre.unltools.unl.UnlSentences; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; class UnlParserTest { - @ParameterizedTest - @ArgumentsSource(SentenceWithExpectedDotArgumentProvider.class) - void UnlParserShouldParseSimpleSentenceWithoutException(SentenceWithExpectedDotChecker input) { - UnlParserFactory unlFactory = new UnlParserFactoryFromString(input.getUnlSentence()); - createAndCheckUnlParserValidity(unlFactory); + private static Stream<SentenceWithExpectedUnlDocumentsChecker> unlParserShouldParseSentenceAndGetExpectedUnlDocuments() { + return Stream.of(new R1SentenceWithExpectedUnlDocumentsChecker(), + new R2SentenceWithExpectedUnlDocumentsChecker(), + new CatsSentenceWithExpectedUnlDocumentsChecker(), + new AllSentenceWithExpectedUnlDocumentsChecker()); } @ParameterizedTest - @ArgumentsSource(SentenceWithExpectedDotArgumentProvider.class) - void UnlDocumentsShouldBeSerializedToStringWithoutException(SentenceWithExpectedDotChecker input) { - UnlParserFactory unlFactory = new UnlParserFactoryFromString(input.getUnlSentence()); - WrapperUnlParser wrapper = createAndCheckUnlParserValidity(unlFactory); + @ValueSource(strings = {UnlSentences.R1, UnlSentences.R2, UnlSentences.Cats, UnlSentences.All}) + void unlParserShouldParseSimpleSentenceWithoutException(String input) { + UnlParserFactory unlFactory = new UnlParserFactoryFromString(input); + var wrapper = createAndCheckUnlParserValidity(unlFactory); for (UnlDocument unlDocument : wrapper.getUnlDocumentList()) { AtomicReference<String> stringOfUnlDocument = new AtomicReference<>(); @@ -48,4 +49,14 @@ class UnlParserTest { return unlParser.get(); } + @ParameterizedTest + @MethodSource + void unlParserShouldParseSentenceAndGetExpectedUnlDocuments(SentenceWithExpectedUnlDocumentsChecker input) { + UnlParserFactory unlFactory = new UnlParserFactoryFromString(input.getUnlSentence()); + var wrapper = createAndCheckUnlParserValidity(unlFactory); + + input.setCurrentUnlDocuments(wrapper.getUnlDocumentList()); + input.assetSameAsExpected(); + } + } \ No newline at end of file diff --git a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java similarity index 65% rename from unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java rename to unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java index 054fa22bcb57b8c828df85aab5574cca994b436d..cd4cb337aadada7a853575000b0aaa1e96f7b9c1 100644 --- a/unl-parser/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java +++ b/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java @@ -15,18 +15,31 @@ public class WrapperUnlParser { this.errors = null; } + /** + * get UnlDocuments once the parsing is done + * + * @return A list of UnlDocuments + */ public Vector<UnlDocument> getUnlDocumentList() { - initializeIfNecessary(); + parseContentIfNecessary(); return this.documents; } - private void initializeIfNecessary() { + /** + * Parse the content with the local parser if not already done. + */ + private void parseContentIfNecessary() { if (null == this.documents) { - initialize(); + parseContentAndRetrieveErrors(); } } - private void initialize() { + + /** + * Parse the content with the local parser. + * Retrieves also errors during parsing + */ + private void parseContentAndRetrieveErrors() { this.errors = new ErrorCollection(false); try { this.documents = this.parser.createUnlDocumentList(); @@ -40,10 +53,13 @@ public class WrapperUnlParser { return; } - fillErrors(); + getUnlDocumentsErrors(); } - private void fillErrors() { + /** + * retrieves errors within documents + */ + private void getUnlDocumentsErrors() { for (UnlDocument document : this.documents) { if (document.HasError()) { this.errors.addError(document.getError()); @@ -51,13 +67,23 @@ public class WrapperUnlParser { } } + /** + * An error as occured during the parsing + * + * @return true if an error occured, false otherwise + */ public boolean hasError() { - initializeIfNecessary(); + parseContentIfNecessary(); return errors.hasError; } + /** + * Get errors of parsing + * + * @return A vector of errors + */ public Vector<String> getErrors() { - initializeIfNecessary(); + parseContentIfNecessary(); return errors.errors; } @@ -71,7 +97,7 @@ public class WrapperUnlParser { } public void addError(String error) { - hasError = true; + this.hasError = true; if (!this.errors.contains(error)) { this.errors.add(error); } diff --git a/rdf/rdf.iml b/unl-tools-infrastructure/unl-tools-infrastructure.iml similarity index 93% rename from rdf/rdf.iml rename to unl-tools-infrastructure/unl-tools-infrastructure.iml index 49fb05cc94b27103a411e8947161739fdf839048..c0652aa7fcab02741b0df74f1ca464cc3740e76b 100644 --- a/rdf/rdf.iml +++ b/unl-tools-infrastructure/unl-tools-infrastructure.iml @@ -1,17 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> -<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11"> <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="library" name="rdf-vocabulary-1.0-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: org.apache.jena:jena-shacl:3.14.0" level="project" /> <orderEntry type="library" name="Maven: org.apache.jena:jena-arq:3.14.0" level="project" /> <orderEntry type="library" name="Maven: org.apache.jena:jena-core:3.14.0" level="project" /> @@ -44,9 +42,11 @@ <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-index:3.14.0" level="project" /> <orderEntry type="library" name="Maven: org.apache.jena:jena-rdfconnection:3.14.0" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.26" level="project" /> - <orderEntry type="library" name="Maven: fr.tetras_libre.unl:unl-parser:1.0-SNAPSHOT" level="project" /> - <orderEntry type="library" name="Maven: fr.tetras_libre.rdf:rdf-unl-java-vocabulary:1.0-SNAPSHOT" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-nop:1.7.30" level="project" /> + <orderEntry type="library" name="Maven: org.picocontainer:picocontainer:2.15" level="project" /> + <orderEntry type="library" name="Maven: fr.tetras_libre.rdf:rdf-unl-java-vocabulary:1.0-SNAPSHOT" level="project" /> + <orderEntry type="module" module-name="unl-tools-core" /> + <orderEntry type="module" module-name="unl-tools-application" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" /> diff --git a/unl2rdf-app/pom.xml b/unl-tools-main/pom.xml similarity index 84% rename from unl2rdf-app/pom.xml rename to unl-tools-main/pom.xml index 8407035518bd72d3f6e3599728b2d5ce40200ad9..bb352e484cb97649dcde023cab6c14c29f01ff1a 100644 --- a/unl2rdf-app/pom.xml +++ b/unl-tools-main/pom.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -10,8 +10,7 @@ <version>0.9</version> </parent> - <name>main-App</name> - <artifactId>unl2rdf-app</artifactId> + <artifactId>unl-tools-main</artifactId> <packaging>jar</packaging> @@ -67,13 +66,15 @@ </excludes> </artifactSet> <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <ManifestEntries> <mainClass>unl2rdf.Unl2Rdf</mainClass> <Build-Number>1</Build-Number> </ManifestEntries> </transformer> - <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"> </transformer> </transformers> <relocations> @@ -101,21 +102,16 @@ </dependency> <dependency> <groupId>fr.tetras_libre.unl</groupId> - <artifactId>unl-parser</artifactId> + <artifactId>unl-tools-infrastructure</artifactId> <version>${project.version}</version> + <scope>compile</scope> </dependency> <dependency> <groupId>fr.tetras_libre.unl</groupId> - <artifactId>rdf</artifactId> - <version>1.0-SNAPSHOT</version> + <artifactId>unl-tools-application</artifactId> + <version>${project.version}</version> <scope>compile</scope> </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-nop</artifactId> - <version>1.7.30</version> - <scope>test</scope> - </dependency> </dependencies> diff --git a/unl2rdf-app/src/main/java/unl2rdf/Options.java b/unl-tools-main/src/main/java/unl2rdf/Options.java similarity index 100% rename from unl2rdf-app/src/main/java/unl2rdf/Options.java rename to unl-tools-main/src/main/java/unl2rdf/Options.java diff --git a/unl2rdf-app/src/main/java/unl2rdf/OutFileType.java b/unl-tools-main/src/main/java/unl2rdf/OutFileType.java similarity index 100% rename from unl2rdf-app/src/main/java/unl2rdf/OutFileType.java rename to unl-tools-main/src/main/java/unl2rdf/OutFileType.java diff --git a/unl2rdf-app/src/main/java/unl2rdf/Unl2Rdf.java b/unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java similarity index 54% rename from unl2rdf-app/src/main/java/unl2rdf/Unl2Rdf.java rename to unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java index fb796a3890e4f03f678f72ed3b41e97cf139b080..555b7e7be9d9ec4eeb8e61124ca2f5574b562dfa 100644 --- a/unl2rdf-app/src/main/java/unl2rdf/Unl2Rdf.java +++ b/unl-tools-main/src/main/java/unl2rdf/Unl2Rdf.java @@ -1,20 +1,21 @@ package unl2rdf; -import fr.tetras_libre.unltools.rdf.vocabulary.RdfFileBuilder; -import fr.tetras_libre.unltools.unl.GraphExporter; -import fr.tetras_libre.unltools.unl.UnlDocument; -import fr.tetras_libre.unltools.unl.parser.ParseException; -import fr.tetras_libre.unltools.unl.parser.UnlParser; -import fr.tetras_libre.unltools.unl.print.dotFile.DotFileBuilder; +import fr.tetras_libre.unltools.ApplicationStartup; +import fr.tetras_libre.unltools.Convert.ExportUnlDocuments; +import fr.tetras_libre.unltools.DefaultCommandHandlerResolverFactory; +import fr.tetras_libre.unltools.cqrs.ServiceProvider; +import fr.tetras_libre.unltools.unl.exporters.GraphExporterNames; +import fr.tetras_libre.unltools.unl.parser.UnlGraphImporterFromUnlParser; import picocli.CommandLine; -import java.io.BufferedReader; import java.io.FileWriter; import java.io.IOException; -import java.util.Vector; public class Unl2Rdf { - public static void main(String[] args) throws ParseException, IOException { + + private static ServiceProvider serviceProvider; + + public static void main(String[] args) throws IOException { Options options = new Options(); @@ -22,6 +23,7 @@ public class Unl2Rdf { CommandLine.ParseResult parseResult = new CommandLine(options).parseArgs(args); if (!CommandLine.printHelpIfRequested(parseResult)) { + serviceProvider = ApplicationStartup.Initialize(DefaultCommandHandlerResolverFactory.create()); runProgram(options); } } catch (CommandLine.ParameterException e) { @@ -30,17 +32,19 @@ public class Unl2Rdf { } } - private static void runProgram(Options options) throws ParseException, IOException { + private static void runProgram(Options options) throws IOException { System.out.println(String.format("Source file : '%s'", options.getInputFile().getAbsolutePath())); - BufferedReader bufferedReader = new BufferedReader(options.getInputStream()); - UnlParser parser = new UnlParser(bufferedReader); - Vector<UnlDocument> documents = parser.createUnlDocumentList(); + + + var importer = UnlGraphImporterFromUnlParser.FromInputReader(options.getInputStream()); + var handler = serviceProvider.getHandler(ExportUnlDocuments.class); for (OutFileType outType : options.getOutputFileType()) { String extension = ToExtension(outType); String outfileName = options.getOutputFile() + extension; FileWriter fileWriter = new FileWriter(outfileName, false); - GetExporter(outType, fileWriter).write(documents); + var convertCommand = new ExportUnlDocuments(importer, GetExporterName(outType), fileWriter); + handler.handle(convertCommand); fileWriter.close(); System.out.println(String.format("Graph writen into file '%s'", outfileName)); } @@ -57,14 +61,16 @@ public class Unl2Rdf { throw new IllegalArgumentException(String.format("unknown fileType '%s", outFileType.toString())); } - private static GraphExporter GetExporter(OutFileType fileType, FileWriter writer) { + private static String GetExporterName(OutFileType fileType) { + String exporterName = null; switch (fileType) { case rdf: - return new RdfFileBuilder(writer); + return GraphExporterNames.RDF_EXPORTER; case dot: - return new DotFileBuilder(writer); + return GraphExporterNames.DOT_EXPORTER; } - throw new IllegalArgumentException(String.format("unknown fileType '%s", fileType.toString())); + + throw new IllegalArgumentException(); } } diff --git a/unl2rdf-app/src/main/resources/META-INF/MANIFEST.MF b/unl-tools-main/src/main/resources/META-INF/MANIFEST.MF similarity index 100% rename from unl2rdf-app/src/main/resources/META-INF/MANIFEST.MF rename to unl-tools-main/src/main/resources/META-INF/MANIFEST.MF diff --git a/unl2rdf-app/src/test/java/unl2rdf/Unl2RdfTest.java b/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java similarity index 92% rename from unl2rdf-app/src/test/java/unl2rdf/Unl2RdfTest.java rename to unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java index b0d28dac74dcde47cebdd1b36982e5ae9fa8de33..4a9dfb91cf582313bae6e2e722270098042db815 100644 --- a/unl2rdf-app/src/test/java/unl2rdf/Unl2RdfTest.java +++ b/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java @@ -22,25 +22,25 @@ class Unl2RdfTest { @Tag("integration") @Test - public void r1ShouldBeConvertedToRdfFile(){ + public void r1ShouldBeConvertedToRdfFile() { Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "r1", "--output-type", "rdf"})); } @Tag("integration") @Test - public void r2ShouldBeConvertedToRdfFile(){ + public void r2ShouldBeConvertedToRdfFile() { Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "r2", "--output-type", "rdf"})); } @Tag("integration") @Test - public void catShouldBeConvertedToRdfFile(){ + public void catShouldBeConvertedToRdfFile() { Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "cat", "--output-type", "rdf"})); } @Tag("integration") @Test - public void exemplesShouldBeConvertedToRdfFile(){ + public void exemplesShouldBeConvertedToRdfFile() { Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "exemples_unl", "--output-type", "rdf"})); } diff --git a/unl-tools-main/unl-tools-main.iml b/unl-tools-main/unl-tools-main.iml new file mode 100644 index 0000000000000000000000000000000000000000..b15bc6475a9109b8bedc65ef7a912516814a1fef --- /dev/null +++ b/unl-tools-main/unl-tools-main.iml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4"> + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11"> + <output url="file://$MODULE_DIR$/target/classes" /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" generated="true" /> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="Maven: info.picocli:picocli:4.2.0" level="project" /> + <orderEntry type="module" module-name="unl-tools-infrastructure" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-shacl:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-arq:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-core:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-iri:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" /> + <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.13" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-base:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.7" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" /> + <orderEntry type="library" name="Maven: com.github.andrewoma.dexx:collection:0.7" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-shaded-guava:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.10" level="project" /> + <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.12" level="project" /> + <orderEntry type="library" name="Maven: com.github.jsonld-java:jsonld-java:0.12.5" level="project" /> + <orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.1" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.1" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.1" level="project" /> + <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient-cache:4.5.10" level="project" /> + <orderEntry type="library" name="Maven: org.apache.thrift:libthrift:0.13.0" level="project" /> + <orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" /> + <orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.26" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-tdb:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-tdb2:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-storage:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-trans-data:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-transaction:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-base:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-dboe-index:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.apache.jena:jena-rdfconnection:3.14.0" level="project" /> + <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.26" level="project" /> + <orderEntry type="library" name="Maven: org.picocontainer:picocontainer:2.15" level="project" /> + <orderEntry type="library" name="Maven: fr.tetras_libre.rdf:rdf-unl-java-vocabulary:1.0-SNAPSHOT" level="project" /> + <orderEntry type="module" module-name="unl-tools-core" /> + <orderEntry type="module" module-name="unl-tools-application" /> + <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.0-M1" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0-M1" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.0-M1" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.0-M1" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0-M1" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0-M1" level="project" /> + </component> +</module> \ No newline at end of file diff --git a/unl2rdf-app/unl2rdf-app.iml b/unlTools.iml similarity index 64% rename from unl2rdf-app/unl2rdf-app.iml rename to unlTools.iml index 4ec4afb9ad50871eaaad6c703990c80d173ee682..a10c5f4e27a534c8a61e3aee63c689c48e514499 100644 --- a/unl2rdf-app/unl2rdf-app.iml +++ b/unlTools.iml @@ -4,19 +4,10 @@ <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" generated="true" /> - <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="library" name="Maven: info.picocli:picocli:4.2.0" level="project" /> - <orderEntry type="module" module-name="unl-parser" /> - <orderEntry type="library" name="Maven: fr.tetras_libre.unl:rdf:1.0-SNAPSHOT" level="project" /> - <orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-nop:1.7.30" level="project" /> - <orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />