From aa3aa88b8e17296664bd767c163e4de550a30eb1 Mon Sep 17 00:00:00 2001 From: Andrea Turbati Date: Mon, 25 Feb 2019 12:42:05 +0100 Subject: [PATCH] removed unused dependency which caused problem during runtime added a property file s and two executable (sh and bat) to launch the tool changed the pom.xml to generate the zip file containing all the files to properly execute the tool --- TBXcoreStructV02.dtd | 246 +++++++++++++++++++++ pom.xml | 365 ++++++++++++++++++------------- src/java/tbx2rdf/Main.java | 85 ++++++- src/java/tbx2rdf/SAXHandler.java | 3 - tbx2rdf.properties | 14 ++ tbx2rdfConversion.bat | 1 + tbx2rdfConversion.sh | 2 + 7 files changed, 545 insertions(+), 171 deletions(-) create mode 100644 TBXcoreStructV02.dtd create mode 100644 tbx2rdf.properties create mode 100644 tbx2rdfConversion.bat create mode 100644 tbx2rdfConversion.sh diff --git a/TBXcoreStructV02.dtd b/TBXcoreStructV02.dtd new file mode 100644 index 0000000..665bb1d --- /dev/null +++ b/TBXcoreStructV02.dtd @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 23f60c9..f557657 100644 --- a/pom.xml +++ b/pom.xml @@ -1,166 +1,219 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - eu.liderproject - 0.1 - tbx2rdf - jar + eu.liderproject + 0.2-SNAPSHOT + tbx2rdf + jar - TBX2RDF Converter + TBX2RDF Converter - - UTF-8 - + + UTF-8 + - - - project.local - project - file:${project.basedir}/repo - - - - - - junit - junit - 4.8.2 - test - - - org.mockito - mockito-all - 1.9.5 - test - - - org.apache.jena - apache-jena-libs - pom - 2.11.1 - + + + project.local + project + file:${project.basedir}/repo + + + + + + junit + junit + 4.8.2 + test + + + org.mockito + mockito-all + 1.9.5 + test + + + org.apache.jena + apache-jena-libs + pom + 2.11.1 + + + log4j + log4j + 1.2.17 + + + virt_jena + virt_jena + 1.0 + + + virt_jena2 + virt_jena2 + 1.0 + - crimson - crimson - 1.1.3 + virtjdbc3 + virtjdbc3 + 1.0 - log4j - log4j - 1.2.17 - - - virt_jena - virt_jena - 1.0 - - - virt_jena2 - virt_jena2 - 1.0 - - - virtjdbc3 - virtjdbc3 - 1.0 - - - tbxcheck-1.2.9 - tbxcheck - 1.2.9 - system - ${project.basedir}/doc/reference/TBX-resources/tbxcheck-1.2.9.jar - - - - - - - - src/java - **/*.java - - - - src/java - test - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-shade-plugin - 1.6 - - - package - - shade - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - true - tbx2rdf.Main - - - - - - org.codehaus.mojo - exec-maven-plugin - - - - java - - - - - tbx2rdf.Main - - - - maven-resources-plugin - 2.6 - - - copy-resources - - validate - - copy-resources - - - ${basedir}/target - - - doc/reference/TBX-resources - true - - - - - - - - - - - + tbxcheck-1.2.9 + tbxcheck + 1.2.9 + system + ${project.basedir}/doc/reference/TBX-resources/tbxcheck-1.2.9.jar + + + + + + + + src/java + + **/*.java + + + + + src/java + test + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.1 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/forZip/lib + false + false + true + + + + + + + + + maven-antrun-plugin + 1.7 + + + install + + + + + + + + + + + + + + + + + + + + run + + + + + + + + diff --git a/src/java/tbx2rdf/Main.java b/src/java/tbx2rdf/Main.java index 4d23ebb..d7181d0 100644 --- a/src/java/tbx2rdf/Main.java +++ b/src/java/tbx2rdf/Main.java @@ -4,10 +4,13 @@ import com.hp.hpl.jena.rdf.model.Model; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.xml.parsers.ParserConfigurationException; @@ -51,35 +54,93 @@ public class Main { public static Mappings mappings; // The base namespace of the dataset public static String DATA_NAMESPACE = "http://tbx2rdf.lider-project.eu/data/iate/"; + //the system id used for relative URI + //public static String systemIdForRelativeURI; /** * Main method. */ - public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException { + public static void main(String[] args) { PropertyConfigurator.configure("log4j.properties"); - boolean ok = parseParams(args); + try { + readConfigurationFile(args[0]); + mappings = Mappings.readInMappings(mapping_file); + + if (big) { + convertBigFile(); + } else { + convertSmallFile(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + /*boolean ok = parseParams(args); if (!ok) { System.exit(-1); - } + }*/ //READ MAPPINGS - System.err.println("Using mapping file: " + mapping_file + "\n"); - mappings = Mappings.readInMappings(mapping_file); + //System.err.println("Using mapping file: " + mapping_file + "\n"); + /*mappings = Mappings.readInMappings(mapping_file); if (big) { convertBigFile(); } else { convertSmallFile(); - } + }*/ } - /** + private static void readConfigurationFile(String propFile) throws Exception { + File fileProp = new File(propFile); + Properties prop = new Properties(); + prop.load(new FileInputStream(fileProp)); + + String bigFile = prop.getProperty("bigfile", "false"); + big = Boolean.parseBoolean(bigFile); + + String tbxfile = prop.getProperty("tbxfile"); + input_file = tbxfile; + File file = new File(input_file); + if (!file.exists()) { + System.err.println("The file " + input_file + " does not exist"); + throw new FileNotFoundException("The file " + input_file + " does not exist"); + } + + String output = prop.getProperty("output", "").trim(); + if(output.length()==0) { + output_file = input_file.replaceAll("\\.(xml|tbx)", "\\.rdf"); + if (!output_file.endsWith(".rdf")) { + output_file += ".rdf"; + } + } + + String namespace = prop.getProperty("namespace", ""); + if(namespace.length()==0) { + throw new Exception("namespace value is missing in the property file"); + } + DATA_NAMESPACE = namespace; + + String mappings = prop.getProperty("mappings", "mappings.default"); + mapping_file = mappings; + + //recap al values that will be used + System.out.println("The following values will be used:"); + System.out.println("\tbig = "+big); + System.out.println("\tinput_file = "+input_file); + System.out.println("\toutput_file = "+output_file); + System.out.println("\tnamespace = "+DATA_NAMESPACE); + System.out.println("\tmapping_file = "+mapping_file); + + } + + /** * Parses the command line parameters */ - public static boolean parseParams(String[] args) { + /*public static boolean parseParams(String[] args) { String ejecutando = ""; for (String ejecutandox : args) { ejecutando += " " + ejecutandox; @@ -139,7 +200,7 @@ public static boolean parseParams(String[] args) { } } return true; - } + }*/ /** * This is the conversion to be invoked for large files, that will be processed in a stream @@ -175,14 +236,14 @@ public static boolean convertBigFile() { */ public static boolean convertSmallFile() { try { - System.err.println("Doing the standard conversion (not a big file)\n"); + System.out.println("Doing the standard conversion (not a big file)\n"); //READ TBX XML - System.err.println("Opening file " + input_file + "\n"); + System.out.println("Opening file " + input_file + "\n"); BufferedReader reader = new BufferedReader(new FileReader(input_file)); TBX2RDF_Converter converter = new TBX2RDF_Converter(); TBX_Terminology terminology = converter.convert(reader, mappings); //WRITE. This one has been obtained from - System.err.println("Writting output to " + output_file + "\n"); + System.out.println("Writting output to " + output_file + "\n"); // final Model model = terminology.getModel("file:" + output_file); final Model model = terminology.getModel(Main.DATA_NAMESPACE); RDFDataMgr.write(new FileOutputStream(output_file), model, Lang.TURTLE); diff --git a/src/java/tbx2rdf/SAXHandler.java b/src/java/tbx2rdf/SAXHandler.java index 5e8f80e..6f7c324 100644 --- a/src/java/tbx2rdf/SAXHandler.java +++ b/src/java/tbx2rdf/SAXHandler.java @@ -21,8 +21,6 @@ import tbx2rdf.vocab.LIME; import tbx2rdf.vocab.ONTOLEX; -import org.apache.crimson.tree.XmlDocumentBuilder; - /** * This class makes the XML parsing of the TBX using the SAX lexiconsModel. @@ -35,7 +33,6 @@ public class SAXHandler extends DefaultHandler { /// private MartifHeader header; ///Internal use - XmlDocumentBuilder consumer; XMLReader producer; //Languages present in the file diff --git a/tbx2rdf.properties b/tbx2rdf.properties new file mode 100644 index 0000000..083cc6e --- /dev/null +++ b/tbx2rdf.properties @@ -0,0 +1,14 @@ +#use big file conversion +bigfile=false + +#path of the tbx to convert +tbxfile= + +#path of the output file (optional) +output= + +#mapping file (optional) +mappings=mappings.default + +#namespace for the generated resources +namespace=http://test.it/ diff --git a/tbx2rdfConversion.bat b/tbx2rdfConversion.bat new file mode 100644 index 0000000..d083fa7 --- /dev/null +++ b/tbx2rdfConversion.bat @@ -0,0 +1 @@ +java -Xmx800M -Dlog4j.configuration=log4j.properties -cp "lib/*" tbx2rdf.Main tbx2rdf.properties diff --git a/tbx2rdfConversion.sh b/tbx2rdfConversion.sh new file mode 100644 index 0000000..366c37a --- /dev/null +++ b/tbx2rdfConversion.sh @@ -0,0 +1,2 @@ +#! /bin/bash +java -Xmx800M -Dlog4j.configuration=log4j.properties -cp "lib/*" tbx2rdf.Main tbx2rdf.properties