From 595365845561150684d32a15611d4e3c5f172749 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Sun, 24 Sep 2023 15:58:48 +0200 Subject: [PATCH 01/12] changed database calls to use the changed names in recent SEP3 demo files. Moved parameters for database to properties file. --- db.properties | 7 ++ .../java/org/sep3tools/JavaConnector.java | 112 ++++++++++++++---- src/main/java/org/sep3tools/Launch.java | 6 + src/main/java/org/sep3tools/LaunchBML.java | 9 +- .../java/org/sep3tools/BmlExamplesTest.java | 13 +- .../java/org/sep3tools/SepExamplesTest.java | 14 +-- 6 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 db.properties diff --git a/db.properties b/db.properties new file mode 100644 index 0000000..8ec6509 --- /dev/null +++ b/db.properties @@ -0,0 +1,7 @@ +URL=jdbc:postgresql://localhost/petroparser +USER=petroparser +PASSWORD=petroparser +WOERTERBUCH=woerterbuch.woerterbuch +SCHLUESSELTYPEN=woerterbuch.schluesseltypen +SCHLUESSELMAPPING=bml.bml_schluesselmapping +DATEFIELD=PETRO diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index 47f70b3..6e907e6 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -1,6 +1,12 @@ package org.sep3tools; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.sql.*; +import java.util.Enumeration; +import java.util.Properties; import java.util.logging.Logger; /** @@ -12,25 +18,54 @@ */ public final class JavaConnector { + private static boolean credChanged = true; + private static final Logger LOG = Logger.getLogger(JavaConnector.class.getName()); - private static String m_url = "jdbc:default:connection"; + private static String m_url; + + private static String user; - private static String user = ""; + private static String pass; - private static String pass = ""; + private static String wb; - private static String wb = "woerterbuch.\"Woerterbuch\""; + private static String st; - private static String st = "woerterbuch.\"Schluesseltypen\""; + private static String sm; - private static String sm = "bml.bml_schluesselmapping"; + private static String df; - private static String df = "PETRO"; + private static Connection conn; private JavaConnector() { } + public static void setPropertiesFile(String filename) { + credChanged = true; + try { + File file = new File(filename); + FileInputStream fileInput = new FileInputStream(file); + Properties properties = new Properties(); + properties.load(fileInput); + fileInput.close(); + + setUrl(properties.getProperty("URL")); + setUser(properties.getProperty("USER")); + setPass(properties.getProperty("PASSWORD")); + setWb(properties.getProperty("WOERTERBUCH")); + setSt(properties.getProperty("SCHLUESSELTYPEN")); + setSm(properties.getProperty("SCHLUESSELMAPPING")); + setDf(properties.getProperty("DATEFIELD")); + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + public static void setWb(String wb) { JavaConnector.wb = wb; } @@ -47,20 +82,29 @@ public static void setDf(String df) { JavaConnector.df = df; } - public static void setUser(String user) { - JavaConnector.user = user; + public static void setUser(String newUser) { + credChanged = true; + JavaConnector.user = newUser; } - public static void setPass(String pass) { - JavaConnector.pass = pass; + public static void setPass(String newPass) { + credChanged = true; + JavaConnector.pass = newPass; } - public static void setUrl(String url) { - JavaConnector.m_url = url; + public static void setUrl(String newUrl) { + credChanged = true; + JavaConnector.m_url = newUrl; } // String query = "SELECT Klartext from woerterbuch.Woerterbuch where Kuerzel="; + private static void setConn(String url, String user, String pass) throws SQLException { + if (conn != null && !conn.isClosed()) + conn.close(); + JavaConnector.conn = DriverManager.getConnection(url, user, pass); + } + /** * translates a SEP3 code to clear text * @param sep3Code code for translation @@ -68,11 +112,12 @@ public static void setUrl(String url) { * @throws SQLException if DB error occurs */ public static String getS3Name(String sep3Code) throws SQLException { - Connection conn = DriverManager.getConnection(m_url, user, pass); - String query = "select \"Kuerzel\", \"Klartext\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Datenfeld\" = '" + df + "' " - + "OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; + String query = "select kuerzel, klartext from " + wb + " w join " + st + " s " + + "on w.typ = s.nebentypbez where (s.datenfeld = '" + df + "' " + + "OR s.datenfeld = 'diverse') AND kuerzel= ?"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); LOG.fine("Executing statement: " + stmt); @@ -83,6 +128,10 @@ public static String getS3Name(String sep3Code) throws SQLException { result = rs.getString(2); } LOG.fine("Returning: " + result); + + rs.close(); + stmt.close(); + return result; } } @@ -94,9 +143,10 @@ public static String getS3Name(String sep3Code) throws SQLException { * @throws SQLException if DB error occurs */ public static String getS3AsBMmlLitho(String sep3Code) throws SQLException { - Connection conn = DriverManager.getConnection(m_url, user, pass); String query = "select bml_code from " + sm + " where sep3_codelist = 'S3PETRO' AND sep3_code = ?"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); LOG.fine("Executing statement: " + stmt); @@ -107,6 +157,10 @@ public static String getS3AsBMmlLitho(String sep3Code) throws SQLException { result = rs.getString(1); } LOG.fine("Returning: " + result); + + rs.close(); + stmt.close(); + return result; } } @@ -118,10 +172,10 @@ public static String getS3AsBMmlLitho(String sep3Code) throws SQLException { * @throws SQLException if DB error occurs */ public static String getAllowedAttribs(String sep3Code) throws SQLException { - Connection conn = DriverManager.getConnection(m_url, user, pass); - String query = "select \"Kuerzel\", \"Attribute\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" " - + "where (s.\"Datenfeld\" = 'PETRO' OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; + String query = "select kuerzel, attribute from " + wb + " w join " + st + " s " + "on w.typ = s.nebentypbez " + + "where (s.datenfeld = 'PETRO' OR s.datenfeld = 'diverse') AND kuerzel= ?"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); LOG.fine("Executing statement: " + stmt); @@ -132,6 +186,10 @@ public static String getAllowedAttribs(String sep3Code) throws SQLException { result = rs.getString(2); } LOG.fine("Returning: " + result); + + rs.close(); + stmt.close(); + return result; } } @@ -150,9 +208,10 @@ public static String getBodenQuant(String sep3Code, String quant) throws SQLExce allowedAttributes = getAllowedAttribs(sep3Code); quantBez = getQuantBezFromAttribs(allowedAttributes); - Connection conn = DriverManager.getConnection(m_url, user, pass); - String query = "select w.\"Kuerzel\", w.\"Klartext\", s.\"Nebentypbez\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Nebentypbez\" = ? AND w.\"Kuerzel\" = ?);"; + String query = "select w.kuerzel, w.klartext, s.nebentypbez from " + wb + " w join " + st + " s " + + "on w.typ = s.nebentypbez where (s.nebentypbez = ? AND w.kuerzel = ?);"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, quantBez); stmt.setString(2, quant); @@ -165,6 +224,9 @@ public static String getBodenQuant(String sep3Code, String quant) throws SQLExce } LOG.fine("Returning: " + result); + rs.close(); + stmt.close(); + return result; } } diff --git a/src/main/java/org/sep3tools/Launch.java b/src/main/java/org/sep3tools/Launch.java index 8e72958..b818e84 100644 --- a/src/main/java/org/sep3tools/Launch.java +++ b/src/main/java/org/sep3tools/Launch.java @@ -7,6 +7,8 @@ import org.postgresql.pljava.annotation.Function; import org.sep3tools.gen.*; +import java.sql.SQLException; + /** * Command line launcher for SEP3 tools * @@ -38,6 +40,10 @@ else if (args.length == 0 || args[0].isEmpty()) { else if (args.length == 1) { sep3String = args[0]; } + else if (args.length == 2) { + JavaConnector.setPropertiesFile(args[0]); + sep3String = args[1]; + } else { System.out.println("Aufruf mit folgenden Parametern:\n" + "[JDBC-URL] [DB-User] [DB-Passwort] [Woerterbuch-Tabelle] [Schlüsseltypen-Tabelle] <SEP3-String>\n\n" diff --git a/src/main/java/org/sep3tools/LaunchBML.java b/src/main/java/org/sep3tools/LaunchBML.java index 637c94f..83a0f37 100644 --- a/src/main/java/org/sep3tools/LaunchBML.java +++ b/src/main/java/org/sep3tools/LaunchBML.java @@ -8,12 +8,13 @@ import org.sep3tools.gen.PetroGrammarLexer; import org.sep3tools.gen.PetroGrammarParser; +import java.sql.SQLException; import java.util.*; import static java.util.Objects.isNull; /** - * Command line launcher for SEP3 to BML tool + * Command line launcher for SEP3 to BML tool. * * @author Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> */ @@ -21,7 +22,7 @@ public class LaunchBML { /** * Launches SEP3 tool with arguments: - * @param args DB URL, DB user, DB password, Schluesselmapping table name SEP3 string + * @param args DB URL, DB user, DB password, Schluesselmapping table name SEP3 string. * to process */ public static void main(String[] args) { @@ -120,10 +121,10 @@ public static String S3_AsBmlLitho(String s3String, String sm) { * @return BML format of SEP3 input */ @Function - public static String S3_AsBmlLitho_verbose(String s3String, String sm) { + public static String s3AsBmlLithoVerbose(final String s3String, final String sm) { JavaConnector.setSm(sm); String result = S3_AsBmlLitho(s3String); return result; } -} \ No newline at end of file +} diff --git a/src/test/java/org/sep3tools/BmlExamplesTest.java b/src/test/java/org/sep3tools/BmlExamplesTest.java index ebef69a..97d5389 100644 --- a/src/test/java/org/sep3tools/BmlExamplesTest.java +++ b/src/test/java/org/sep3tools/BmlExamplesTest.java @@ -18,6 +18,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.SQLException; import java.util.Enumeration; import java.util.Properties; @@ -28,20 +29,12 @@ @Ignore("Class not ready for automatic tests, integrations tests depend on running database") public class BmlExamplesTest { - static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; - static final String USER = "petroparser"; - static final String PASS = "PetroParser"; - static final String SMTABLE = "bml.bml_schluesselmapping"; - @Test public void verifyBmlExamples() { - JavaConnector.setUrl(DB_URL); - JavaConnector.setUser(USER); - JavaConnector.setPass(PASS); - JavaConnector.setSm(SMTABLE); - try { + JavaConnector.setPropertiesFile("db.properties"); + File file = new File("bmltest.properties"); FileInputStream fileInput = new FileInputStream(file); Properties properties = new Properties(); diff --git a/src/test/java/org/sep3tools/SepExamplesTest.java b/src/test/java/org/sep3tools/SepExamplesTest.java index 7db6bbd..d89c796 100644 --- a/src/test/java/org/sep3tools/SepExamplesTest.java +++ b/src/test/java/org/sep3tools/SepExamplesTest.java @@ -21,6 +21,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.SQLException; import java.util.Enumeration; import java.util.Properties; @@ -29,11 +30,7 @@ @Ignore("Class not ready for automatic tests, integrations tests depend on running database") public class SepExamplesTest { - static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; - static final String USER = "petroparser"; - static final String PASS = "PetroParser"; - static final String WBTABLE = "woerterbuch.\"Woerterbuch\""; - static final String STTABLE = "woerterbuch.\"Schluesseltypen\""; + static final String DBPROPFILENAME = "db.properties"; @Test public void verifyPetroExamples() { @@ -77,11 +74,8 @@ public void verifyFarbeExamples() { public void verifySepExamples(String df, String propFile) { - JavaConnector.setUrl(DB_URL); - JavaConnector.setUser(USER); - JavaConnector.setPass(PASS); - JavaConnector.setWb(WBTABLE); - JavaConnector.setSt(STTABLE); + JavaConnector.setPropertiesFile(DBPROPFILENAME); + JavaConnector.setDf(df); try { From d08e822cd0c4817c776a32b56f1128d32d97b600 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Sun, 23 Apr 2023 19:14:14 +0200 Subject: [PATCH 02/12] added test strings with expected result for sep3 and bml in properties files. Added tests for sep3 and bml that verify the test cases in the properties files. --- bmltest.properties | 3 + septest.properties | 16 +++ src/main/java/org/sep3tools/LaunchTests.java | 107 ++++++++++++++++++ .../java/org/sep3tools/BmlExamplesTest.java | 68 +++++++++++ .../java/org/sep3tools/SepExamplesTest.java | 71 ++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 bmltest.properties create mode 100644 septest.properties create mode 100644 src/main/java/org/sep3tools/LaunchTests.java create mode 100644 src/test/java/org/sep3tools/BmlExamplesTest.java create mode 100644 src/test/java/org/sep3tools/SepExamplesTest.java diff --git a/bmltest.properties b/bmltest.properties new file mode 100644 index 0000000..b60438b --- /dev/null +++ b/bmltest.properties @@ -0,0 +1,3 @@ +^hzk,\ fS(ms2,\ "gl"2)=fS,mS +G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg2,mx(voe))=G,fG,gG,mS,gS,eG,X,fS,mG +U(hz(res),H(res),zg1)=U,Pfl,H \ No newline at end of file diff --git a/septest.properties b/septest.properties new file mode 100644 index 0000000..0550202 --- /dev/null +++ b/septest.properties @@ -0,0 +1,16 @@ +^ms=Mittelsandstein +^u=Schluffstein +^gs=Grobsandstein +W,^gs(l-fs),^u=Wasser, Grobsandstein (lehmig bis feinsandig), Schluffstein +^ms(r2,r3(tw),gs(lw,r2-r3)),^u(t,lw),^gs(r3,bei(113),nf?)=Mittelsandstein (kantengerundet, mäßig gerundet (teilweise), grobsandig (lagenweise, kantengerundet bis mäßig gerundet)), Schluffstein (tonig, lagenweise), Grobsandstein (mäßig gerundet, bei 113, Nachfall (fraglich)) +^ksw-^kal(mas,fe,spt,brc,cav2(bei(25.5)),p(unz,tv(40.4))),Rfl("ca"),^if2(knl,bei(31.4,32.8,34.65,35.8,40.4))=Schwammkalk bis Algenkalk (massig, fest, splittrig, brechend, schwach kavernös (bei 25,5), porös (unten zunehmend, Teufe von 40,4)), Hohlraumfüllung (Kalzit), wenig Flint (knollig, bei 31,4, 32,8, 34,65, 35,8, 40,4) +G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg,mx(voe))=Kies [gerundet] (feinkiesig bis grobkiesig, mittelsandig bis grobsandig, Schwarzwaldmaterial, alpines Material, grusig (teilweise)), Feinsteinstücke [2,0-6,3 mm] bis Mittelsteinstücke [6,3-20 mm] (alpines Material), Mittelsand [0,2-0,63 mm] (feinsandig, grusig, feinkiesig bis mittelkiesig, mittelsteinig (vereinzelt vorhanden)) +G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg2,mx(voe))=Kies [gerundet] (feinkiesig bis grobkiesig, mittelsandig bis grobsandig, Schwarzwaldmaterial, alpines Material, grusig (teilweise)), Feinsteinstücke [2,0-6,3 mm] bis Mittelsteinstücke [6,3-20 mm] (alpines Material), Mittelsand [0,2-0,63 mm] (feinsandig, grusig, feinkiesig bis schwach mittelkiesig, mittelsteinig (vereinzelt vorhanden)) +U(hz(res),H(res),zg1)=Schluff (Holzreste (Reste), Torf (Reste), sehr schwach zersetzt) +(S-G)(u,t,pf(zg,vw))=(Sand [allgemein] bis Kies [gerundet]) (schluffig, tonig, Pflanzenreste (zersetzt, verwittert)) +U(ms2,x(+Gr(gro(0.005))))=Schluff (schwach mittelsandig, steinig (Granit (groß 0,005))) +(^u(fs)-^fs(u)),^d(u,"ba")=(Schluffstein (feinsandig) bis Feinsandstein (schluffig)), Dolomitstein (schluffig, Baryt) +(fG-gG)(x)=(Feinkies [2,0-6,3 mm] bis Grobkies [20-63 mm]) (steinig) +(^u(t,fs(tw)),^gs,^fs,^d(s,ikl))(wl)=(Schluffstein (tonig, feinsandig (teilweise)), Grobsandstein, Feinsandstein, Dolomitstein (sandig, intraklastisch)) (wechsellagernd) +(U,fS)(ms2)=(Schluff, Feinsand [0,063-0,2 mm]) (schwach mittelsandig) +(^k(mas,fla,pof,bel)),(fls(rgu))=Kalkstein (massig, flaserig, Porifera, Belemniten), Flasern (unregelmäßig) \ No newline at end of file diff --git a/src/main/java/org/sep3tools/LaunchTests.java b/src/main/java/org/sep3tools/LaunchTests.java new file mode 100644 index 0000000..58a244f --- /dev/null +++ b/src/main/java/org/sep3tools/LaunchTests.java @@ -0,0 +1,107 @@ +package org.sep3tools;/*---------------------------------------------------------------------------- + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +----------------------------------------------------------------------------*/ + +import java.util.Enumeration; +import java.util.Properties; + +import org.postgresql.pljava.annotation.Function; + +public class LaunchTests { + + @Function + public static String verifySepExamples(String wb, String st) { + JavaConnector.setWb(wb); + JavaConnector.setSt(st); + + Properties testCases = new Properties(); + + testCases.put("^ms", "Mittelsandstein"); + testCases.put("^u", "Schluffstein"); + testCases.put("^gs", "Grobsandstein"); + testCases.put("W,^gs(l-fs),^u", "Wasser, Grobsandstein (lehmig bis feinsandig), Schluffstein"); + testCases.put("^ms(r2,r3(tw),gs(lw,r2-r3)),^u(t,lw),^gs(r3,bei(113),nf?)", + "Mittelsandstein (kantengerundet, mäßig gerundet (teilweise), grobsandig (lagenweise, kantengerundet bis mäßig gerundet)), Schluffstein (tonig, lagenweise), Grobsandstein (mäßig gerundet, bei 113, Nachfall (fraglich))"); + testCases.put( + "^ksw-^kal(mas,fe,spt,brc,cav2(bei(25.5)),p(unz,tv(40.4))),Rfl(\"ca\"),^if2(knl,bei(31.4,32.8,34.65,35.8,40.4))", + "Schwammkalk bis Algenkalk (massig, fest, splittrig, brechend, schwach kavernös (bei 25,5), porös (unten zunehmend, Teufe von 40,4)), Hohlraumfüllung (Kalzit), wenig Flint (knollig, bei 31,4, 32,8, 34,65, 35,8, 40,4)"); + testCases.put("G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg,mx(voe))", + "Kies [gerundet] (feinkiesig bis grobkiesig, mittelsandig bis grobsandig, Schwarzwaldmaterial, alpines Material, grusig (teilweise)), Feinsteinstücke [2,0-6,3 mm] bis Mittelsteinstücke [6,3-20 mm] (alpines Material), Mittelsand [0,2-0,63 mm] (feinsandig, grusig, feinkiesig bis mittelkiesig, mittelsteinig (vereinzelt vorhanden))"); + testCases.put("G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg2,mx(voe))", + "Kies [gerundet] (feinkiesig bis grobkiesig, mittelsandig bis grobsandig, Schwarzwaldmaterial, alpines Material, grusig (teilweise)), Feinsteinstücke [2,0-6,3 mm] bis Mittelsteinstücke [6,3-20 mm] (alpines Material), Mittelsand [0,2-0,63 mm] (feinsandig, grusig, feinkiesig bis schwach mittelkiesig, mittelsteinig (vereinzelt vorhanden))"); + testCases.put("U(hz(res),H(res),zg1)", "Schluff (Holzreste (Reste), Torf (Reste), sehr schwach zersetzt)"); + testCases.put("(S-G)(u,t,pf(zg,vw))", + "(Sand [allgemein] bis Kies [gerundet]) (schluffig, tonig, Pflanzenreste (zersetzt, verwittert))"); + testCases.put("U(ms2,x(+Gr(gro(0.005))))", "Schluff (schwach mittelsandig, steinig (Granit (groß 0,005)))"); + testCases.put("(^u(fs)-^fs(u)),^d(u,\"ba\")", + "(Schluffstein (feinsandig) bis Feinsandstein (schluffig)), Dolomitstein (schluffig, Baryt)"); + testCases.put("(fG-gG)(x)", "(Feinkies [2,0-6,3 mm] bis Grobkies [20-63 mm]) (steinig)"); + testCases.put("(^u(t,fs(tw)),^gs,^fs,^d(s,ikl))(wl)", + "(Schluffstein (tonig, feinsandig (teilweise)), Grobsandstein, Feinsandstein, Dolomitstein (sandig, intraklastisch)) (wechsellagernd)"); + testCases.put("(U,fS)(ms2)", "(Schluff, Feinsand [0,063-0,2 mm]) (schwach mittelsandig)"); + testCases.put("(^k(mas,fla,pof,bel)),(fls(rgu))", + "Kalkstein (massig, flaserig, Porifera, Belemniten), Flasern (unregelmäßig)"); + + String passed = "Passed Tests:\n"; + String failed = "Failed Tests:\n"; + + Enumeration enuKeys = testCases.keys(); + while (enuKeys.hasMoreElements()) { + String sep3String = (String) enuKeys.nextElement(); + String expectedTranslation = testCases.getProperty(sep3String); + String translation = Launch.S3_AsText(sep3String); + if (translation.equals(expectedTranslation)) { + passed = passed + sep3String + "\n"; + // result = result + sep3String + " translated to " + translation + " - OK + // \n"; + } + else { + failed = failed + "Test failed: " + sep3String + " translated to " + translation + " but " + + expectedTranslation + " was expected.\n"; + } + } + return passed + "\n" + failed; + } + + @Function + public static String verifyBmlExamples(String sm) { + JavaConnector.setSm(sm); + + Properties testCases = new Properties(); + + testCases.put("^hzk, fS(ms2, \"gl\"2)", "fS,mS"); + testCases.put("G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg2,mx(voe))", + "G,fG,gG,mS,gS,eG,X,fS,mG"); + testCases.put("U(hz(res),H(res),zg1)", "U,Pfl,H"); + + String passed = "Passed Tests:\n"; + String failed = "Failed Tests:\n"; + + Enumeration enuKeys = testCases.keys(); + while (enuKeys.hasMoreElements()) { + String sep3String = (String) enuKeys.nextElement(); + String expectedTranslation = testCases.getProperty(sep3String); + String translation = LaunchBML.S3_AsBmlLitho(sep3String); + if (translation.equals(expectedTranslation)) { + passed = passed + sep3String + "\n"; + } + else { + failed = failed + "Test failed: " + sep3String + " translated to " + translation + " but " + + expectedTranslation + " was expected.\n"; + } + } + return passed + "\n" + failed; + + } + +} diff --git a/src/test/java/org/sep3tools/BmlExamplesTest.java b/src/test/java/org/sep3tools/BmlExamplesTest.java new file mode 100644 index 0000000..80b2194 --- /dev/null +++ b/src/test/java/org/sep3tools/BmlExamplesTest.java @@ -0,0 +1,68 @@ +package org.sep3tools;/*---------------------------------------------------------------------------- + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +----------------------------------------------------------------------------*/ + +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Properties; + +import org.hamcrest.CoreMatchers; +import org.junit.Test; + +public class BmlExamplesTest { + + static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; + static final String USER = "petroparser"; + static final String PASS = "PetroParser"; + static final String SMTABLE = "bml.bml_schluesselmapping"; + + @Test + public void verifyBmlExamples() { + + JavaConnector.setUrl(DB_URL); + JavaConnector.setUser(USER); + JavaConnector.setPass(PASS); + JavaConnector.setSm(SMTABLE); + + try { + File file = new File("bmltest.properties"); + FileInputStream fileInput = new FileInputStream(file); + Properties properties = new Properties(); + properties.load(fileInput); + fileInput.close(); + + Enumeration enuKeys = properties.keys(); + while (enuKeys.hasMoreElements()) { + String sep3String = (String) enuKeys.nextElement(); + String expectedTranslation = properties.getProperty(sep3String); + String translation = LaunchBML.S3_AsBmlLitho(sep3String); + assertThat(translation, CoreMatchers.is(expectedTranslation)); + // System.out.println(sep3String + " transation matched expected value: " + // + translation); + } + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/test/java/org/sep3tools/SepExamplesTest.java b/src/test/java/org/sep3tools/SepExamplesTest.java new file mode 100644 index 0000000..09308c9 --- /dev/null +++ b/src/test/java/org/sep3tools/SepExamplesTest.java @@ -0,0 +1,71 @@ +package org.sep3tools;/*---------------------------------------------------------------------------- + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +----------------------------------------------------------------------------*/ + +import org.junit.Test; + +import org.hamcrest.CoreMatchers; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class SepExamplesTest { + + static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; + static final String USER = "petroparser"; + static final String PASS = "PetroParser"; + static final String WBTABLE = "woerterbuch.\"Woerterbuch\""; + static final String STTABLE = "woerterbuch.\"Schluesseltypen\""; + + @Test + public void verifySepExamples() { + + JavaConnector.setUrl(DB_URL); + JavaConnector.setUser(USER); + JavaConnector.setPass(PASS); + JavaConnector.setWb(WBTABLE); + JavaConnector.setSt(STTABLE); + + try { + File file = new File("septest.properties"); + FileInputStream fileInput = new FileInputStream(file); + Properties properties = new Properties(); + properties.load(fileInput); + fileInput.close(); + + Enumeration enuKeys = properties.keys(); + while (enuKeys.hasMoreElements()) { + String sep3String = (String) enuKeys.nextElement(); + String expectedTranslation = properties.getProperty(sep3String); + String translation = Launch.S3_AsText(sep3String); + assertThat(translation, CoreMatchers.is(expectedTranslation)); + // System.out.println(sep3String + " transation matched expected value: " + // + translation); + } + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + + } + +} From 7439d8e8970530c7fd86668a148f18f9fb32585d Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Sat, 20 May 2023 10:35:42 +0200 Subject: [PATCH 03/12] added recognition for several other "Datenfeld" entries. --- src/main/java/org/sep3tools/JavaConnector.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index 3a77afc..0087aef 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -64,8 +64,11 @@ public static void setUrl(String url) { public static String getS3Name(String sep3Code) throws SQLException { Connection conn = DriverManager.getConnection(m_url, user, pass); String query = "select \"Kuerzel\", \"Klartext\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" " - + "where (s.\"Datenfeld\" = 'PETRO' OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; + + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Datenfeld\" = 'PETRO' " + + "OR s.\"Datenfeld\" = 'BESCHBG' OR s.\"Datenfeld\" = 'BESCHBV' " + + "OR s.\"Datenfeld\" = 'BGRUPPE' OR s.\"Datenfeld\" = 'GENESE' " + + "OR s.\"Datenfeld\" = 'KALKGEH' OR s.\"Datenfeld\" = 'ZUSATZ' " + + "OR s.\"Datenfeld\" = 'FARBE' OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); From 6aaa55245de2f68b1aee06d1f0642fb5ad758136 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Wed, 24 May 2023 23:23:42 +0200 Subject: [PATCH 04/12] added Datenfeld as parameter for commanline and in database function call. Separated tests and test properties files for each Datenfeld. --- beschbgtest.properties | 1 + beschbvtest.properties | 1 + bgruppetest.properties | 1 + farbetest.properties | 24 ++++++++++ genesetest.properties | 1 + kalkgehtest.properties | 1 + septest.properties => petrotest.properties | 0 .../antlr4/org/sep3tools/gen/PetroGrammar.g4 | 2 +- .../java/org/sep3tools/JavaConnector.java | 13 +++--- src/main/java/org/sep3tools/Launch.java | 13 +++--- .../java/org/sep3tools/SepExamplesTest.java | 44 ++++++++++++++++++- zusatztest.properties | 1 + 12 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 beschbgtest.properties create mode 100644 beschbvtest.properties create mode 100644 bgruppetest.properties create mode 100644 farbetest.properties create mode 100644 genesetest.properties create mode 100644 kalkgehtest.properties rename septest.properties => petrotest.properties (100%) create mode 100644 zusatztest.properties diff --git a/beschbgtest.properties b/beschbgtest.properties new file mode 100644 index 0000000..3349e2a --- /dev/null +++ b/beschbgtest.properties @@ -0,0 +1 @@ +kb2,kb3(un)=schlechte Kornbindung, mäßige Kornbindung (unten) \ No newline at end of file diff --git a/beschbvtest.properties b/beschbvtest.properties new file mode 100644 index 0000000..1e4fa59 --- /dev/null +++ b/beschbvtest.properties @@ -0,0 +1 @@ +spvl(30%-40%,tv(29.02-29.23))=Spülverlust [Prozent] (30% bis 40%, Teufe von (29,02 bis 29,23)) \ No newline at end of file diff --git a/bgruppetest.properties b/bgruppetest.properties new file mode 100644 index 0000000..81bc73e --- /dev/null +++ b/bgruppetest.properties @@ -0,0 +1 @@ +GE=Kies, enggestuft \ No newline at end of file diff --git a/farbetest.properties b/farbetest.properties new file mode 100644 index 0000000..6725632 --- /dev/null +++ b/farbetest.properties @@ -0,0 +1,24 @@ +ro=rot +bn=braun +dro=dunkelrot +hbn=hellbraun +gr=grau +bl=blau +dd=sehr dunkel +hgr=hellgrau +mt=matt +ol=oliv +olst=olivstichig +sw=schwarz +ge=gelb +dgr=dunkelgrau +gn=grün +rs=rosa +gnli=grünlich +grst=graustichig +# robn= +# blro=blaurot +# drohbngr,blro,ddro,hgrbn,mtgr,mtol,mtolst= +dro-hgr=dunkelrot bis hellgrau +# robn,sw,ge,dgr-gn,swgerobnrs= +gnli,grst=grünlich, graustichig \ No newline at end of file diff --git a/genesetest.properties b/genesetest.properties new file mode 100644 index 0000000..bc7d506 --- /dev/null +++ b/genesetest.properties @@ -0,0 +1 @@ +as,Lou(lok)=Abspülung, Schwemmlöss (lokal) \ No newline at end of file diff --git a/kalkgehtest.properties b/kalkgehtest.properties new file mode 100644 index 0000000..017857d --- /dev/null +++ b/kalkgehtest.properties @@ -0,0 +1 @@ +zg1-zg2(ob)=sehr schwach zersetzt bis schwach zersetzt (oben) \ No newline at end of file diff --git a/septest.properties b/petrotest.properties similarity index 100% rename from septest.properties rename to petrotest.properties diff --git a/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 b/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 index 090566f..2bc6921 100644 --- a/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 +++ b/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 @@ -36,6 +36,6 @@ attribut: TIEFE: ([0-9]|'.')+; TEIL: ANY+; UNBEKANNT: ANY+; -ANY: [a-z]|[A-Z]|[0-9]|'^'|'*'|'+'|'"'; +ANY: [a-z]|[A-Z]|[0-9]|'^'|'*'|'+'|'"'|'%'; FRAGLICH: '?'; SICHER: '!'; \ No newline at end of file diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index 0087aef..47f70b3 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -26,6 +26,8 @@ public final class JavaConnector { private static String sm = "bml.bml_schluesselmapping"; + private static String df = "PETRO"; + private JavaConnector() { } @@ -41,6 +43,10 @@ public static void setSm(String sm) { JavaConnector.sm = sm; } + public static void setDf(String df) { + JavaConnector.df = df; + } + public static void setUser(String user) { JavaConnector.user = user; } @@ -64,11 +70,8 @@ public static void setUrl(String url) { public static String getS3Name(String sep3Code) throws SQLException { Connection conn = DriverManager.getConnection(m_url, user, pass); String query = "select \"Kuerzel\", \"Klartext\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Datenfeld\" = 'PETRO' " - + "OR s.\"Datenfeld\" = 'BESCHBG' OR s.\"Datenfeld\" = 'BESCHBV' " - + "OR s.\"Datenfeld\" = 'BGRUPPE' OR s.\"Datenfeld\" = 'GENESE' " - + "OR s.\"Datenfeld\" = 'KALKGEH' OR s.\"Datenfeld\" = 'ZUSATZ' " - + "OR s.\"Datenfeld\" = 'FARBE' OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; + + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Datenfeld\" = '" + df + "' " + + "OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); diff --git a/src/main/java/org/sep3tools/Launch.java b/src/main/java/org/sep3tools/Launch.java index 312cfa9..8e72958 100644 --- a/src/main/java/org/sep3tools/Launch.java +++ b/src/main/java/org/sep3tools/Launch.java @@ -23,13 +23,14 @@ public class Launch { */ public static void main(String[] args) { String sep3String; - if (args.length == 6) { + if (args.length == 7) { JavaConnector.setUrl(args[0]); JavaConnector.setUser(args[1]); JavaConnector.setPass(args[2]); JavaConnector.setWb(args[3]); JavaConnector.setSt(args[4]); - sep3String = args[5]; + JavaConnector.setDf(args[5]); + sep3String = args[6]; } else if (args.length == 0 || args[0].isEmpty()) { sep3String = "^ms(r2,r3(tw),gs(lw,r2-r3)),^u(t,lw),^gs(r3,bei(113),nf?)"; @@ -42,7 +43,7 @@ else if (args.length == 1) { + "[JDBC-URL] [DB-User] [DB-Passwort] [Woerterbuch-Tabelle] [Schlüsseltypen-Tabelle] <SEP3-String>\n\n" + "Beispiel für Parameter:\n" + "\"jdbc:postgresql://localhost/petroparser\" " + "\"petroDB\" " + "\"PetroPass\" " + "\"woerterbuch.\\\"\"Woerterbuch\\\"\" " - + "\"woerterbuch.\\\"\"Schluesseltypen\\\"\" " + + "\"woerterbuch.\\\"\"Schluesseltypen\\\"\" PETRO " + "\"G(fg-gg,ms-gs,mats,mata,grs(tw)),fX-mX(mata),mS(fs,grs,fg-mg2,mx(voe))\""); return; } @@ -75,10 +76,11 @@ protected static String S3_AsText(String s3String) { * @return human readable format of SEP3 input */ @Function - public static String S3_AsText(String s3String, String wb, String st) { + public static String S3_AsText(String s3String, String wb, String st, String df) { try { JavaConnector.setWb(wb); JavaConnector.setSt(st); + JavaConnector.setDf(df); return S3_AsText(s3String); } catch (Exception e) { @@ -95,9 +97,10 @@ public static String S3_AsText(String s3String, String wb, String st) { * @return human readable format of SEP3 input */ @Function - public static String S3_AsText_verbose(String s3String, String wb, String st) { + public static String S3_AsText_verbose(String s3String, String wb, String st, String df) { JavaConnector.setWb(wb); JavaConnector.setSt(st); + JavaConnector.setDf(df); return S3_AsText(s3String); } diff --git a/src/test/java/org/sep3tools/SepExamplesTest.java b/src/test/java/org/sep3tools/SepExamplesTest.java index 09308c9..6a913aa 100644 --- a/src/test/java/org/sep3tools/SepExamplesTest.java +++ b/src/test/java/org/sep3tools/SepExamplesTest.java @@ -34,16 +34,56 @@ public class SepExamplesTest { static final String STTABLE = "woerterbuch.\"Schluesseltypen\""; @Test - public void verifySepExamples() { + public void verifyPetroExamples() { + verifySepExamples("PETRO", "petrotest.properties"); + } + + @Test + public void verifyBeschbgExamples() { + verifySepExamples("BESCHBG", "beschbgtest.properties"); + } + + @Test + public void verifyBeschbvExamples() { + verifySepExamples("BESCHBV", "beschbvtest.properties"); + } + + @Test + public void verifyBgruppeExamples() { + verifySepExamples("BGRUPPE", "bgruppetest.properties"); + } + + @Test + public void verifyGeneseExamples() { + verifySepExamples("GENESE", "genesetest.properties"); + } + + @Test + public void verifyKalkgehExamples() { + verifySepExamples("KALKGEH", "kalkgehtest.properties"); + } + + @Test + public void verifyZusatzExamples() { + verifySepExamples("ZUSATZ", "zusatztest.properties"); + } + + @Test + public void verifyFarbeExamples() { + verifySepExamples("FARBE", "farbetest.properties"); + } + + public void verifySepExamples(String df, String propFile) { JavaConnector.setUrl(DB_URL); JavaConnector.setUser(USER); JavaConnector.setPass(PASS); JavaConnector.setWb(WBTABLE); JavaConnector.setSt(STTABLE); + JavaConnector.setDf(df); try { - File file = new File("septest.properties"); + File file = new File(propFile); FileInputStream fileInput = new FileInputStream(file); Properties properties = new Properties(); properties.load(fileInput); diff --git a/zusatztest.properties b/zusatztest.properties new file mode 100644 index 0000000..de8200e --- /dev/null +++ b/zusatztest.properties @@ -0,0 +1 @@ +AS=Sattelfläche \ No newline at end of file From 8cb07ac76933ce7586c3a830840379cbaa18f128 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Wed, 24 May 2023 23:29:19 +0200 Subject: [PATCH 05/12] changed test due to add percent character to grammar --- src/test/java/org/sep3tools/ParserTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/sep3tools/ParserTest.java b/src/test/java/org/sep3tools/ParserTest.java index 6161680..70efc55 100644 --- a/src/test/java/org/sep3tools/ParserTest.java +++ b/src/test/java/org/sep3tools/ParserTest.java @@ -68,13 +68,13 @@ public void verifyThatAttributesWithoutQuotesAreParsed() { */ @Test public void verifyThatCharacterNotInGrammarIsNotParsed() { - CharStream input = CharStreams.fromString("^kal(%Rfl(\"ca\"))"); + CharStream input = CharStreams.fromString("^kal({Rfl(\"ca\"))"); PetroGrammarLexer lexer = new PetroGrammarLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); PetroGrammarParser parser = new PetroGrammarParser(tokens); ParseTree tree = parser.schichtbeschreibung(); - assertThat(tree.getText(), not("^kal(%Rfl(\"ca\"))")); + assertThat(tree.getText(), not("^kal({Rfl(\"ca\"))")); } } From eb0014de60f32bcd73bb971fb2111e844799f3ec Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Thu, 25 May 2023 00:00:59 +0200 Subject: [PATCH 06/12] disabled database dependend integration tests --- src/test/java/org/sep3tools/BmlExamplesTest.java | 2 ++ src/test/java/org/sep3tools/SepExamplesTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/test/java/org/sep3tools/BmlExamplesTest.java b/src/test/java/org/sep3tools/BmlExamplesTest.java index 80b2194..ebef69a 100644 --- a/src/test/java/org/sep3tools/BmlExamplesTest.java +++ b/src/test/java/org/sep3tools/BmlExamplesTest.java @@ -22,8 +22,10 @@ import java.util.Properties; import org.hamcrest.CoreMatchers; +import org.junit.Ignore; import org.junit.Test; +@Ignore("Class not ready for automatic tests, integrations tests depend on running database") public class BmlExamplesTest { static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; diff --git a/src/test/java/org/sep3tools/SepExamplesTest.java b/src/test/java/org/sep3tools/SepExamplesTest.java index 6a913aa..7db6bbd 100644 --- a/src/test/java/org/sep3tools/SepExamplesTest.java +++ b/src/test/java/org/sep3tools/SepExamplesTest.java @@ -12,6 +12,7 @@ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ----------------------------------------------------------------------------*/ +import org.junit.Ignore; import org.junit.Test; import org.hamcrest.CoreMatchers; @@ -25,6 +26,7 @@ import static org.hamcrest.MatcherAssert.assertThat; +@Ignore("Class not ready for automatic tests, integrations tests depend on running database") public class SepExamplesTest { static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; From fa347449b2018ba30b669795d7c415c82adb46c9 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Sun, 24 Sep 2023 15:58:48 +0200 Subject: [PATCH 07/12] changed database calls to use the changed names in recent SEP3 demo files. Moved parameters for database to properties file. --- db.properties | 7 ++ .../java/org/sep3tools/JavaConnector.java | 112 ++++++++++++++---- src/main/java/org/sep3tools/Launch.java | 6 + src/main/java/org/sep3tools/LaunchBML.java | 9 +- .../java/org/sep3tools/BmlExamplesTest.java | 13 +- .../java/org/sep3tools/SepExamplesTest.java | 14 +-- 6 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 db.properties diff --git a/db.properties b/db.properties new file mode 100644 index 0000000..8ec6509 --- /dev/null +++ b/db.properties @@ -0,0 +1,7 @@ +URL=jdbc:postgresql://localhost/petroparser +USER=petroparser +PASSWORD=petroparser +WOERTERBUCH=woerterbuch.woerterbuch +SCHLUESSELTYPEN=woerterbuch.schluesseltypen +SCHLUESSELMAPPING=bml.bml_schluesselmapping +DATEFIELD=PETRO diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index 47f70b3..6e907e6 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -1,6 +1,12 @@ package org.sep3tools; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.sql.*; +import java.util.Enumeration; +import java.util.Properties; import java.util.logging.Logger; /** @@ -12,25 +18,54 @@ */ public final class JavaConnector { + private static boolean credChanged = true; + private static final Logger LOG = Logger.getLogger(JavaConnector.class.getName()); - private static String m_url = "jdbc:default:connection"; + private static String m_url; + + private static String user; - private static String user = ""; + private static String pass; - private static String pass = ""; + private static String wb; - private static String wb = "woerterbuch.\"Woerterbuch\""; + private static String st; - private static String st = "woerterbuch.\"Schluesseltypen\""; + private static String sm; - private static String sm = "bml.bml_schluesselmapping"; + private static String df; - private static String df = "PETRO"; + private static Connection conn; private JavaConnector() { } + public static void setPropertiesFile(String filename) { + credChanged = true; + try { + File file = new File(filename); + FileInputStream fileInput = new FileInputStream(file); + Properties properties = new Properties(); + properties.load(fileInput); + fileInput.close(); + + setUrl(properties.getProperty("URL")); + setUser(properties.getProperty("USER")); + setPass(properties.getProperty("PASSWORD")); + setWb(properties.getProperty("WOERTERBUCH")); + setSt(properties.getProperty("SCHLUESSELTYPEN")); + setSm(properties.getProperty("SCHLUESSELMAPPING")); + setDf(properties.getProperty("DATEFIELD")); + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + public static void setWb(String wb) { JavaConnector.wb = wb; } @@ -47,20 +82,29 @@ public static void setDf(String df) { JavaConnector.df = df; } - public static void setUser(String user) { - JavaConnector.user = user; + public static void setUser(String newUser) { + credChanged = true; + JavaConnector.user = newUser; } - public static void setPass(String pass) { - JavaConnector.pass = pass; + public static void setPass(String newPass) { + credChanged = true; + JavaConnector.pass = newPass; } - public static void setUrl(String url) { - JavaConnector.m_url = url; + public static void setUrl(String newUrl) { + credChanged = true; + JavaConnector.m_url = newUrl; } // String query = "SELECT Klartext from woerterbuch.Woerterbuch where Kuerzel="; + private static void setConn(String url, String user, String pass) throws SQLException { + if (conn != null && !conn.isClosed()) + conn.close(); + JavaConnector.conn = DriverManager.getConnection(url, user, pass); + } + /** * translates a SEP3 code to clear text * @param sep3Code code for translation @@ -68,11 +112,12 @@ public static void setUrl(String url) { * @throws SQLException if DB error occurs */ public static String getS3Name(String sep3Code) throws SQLException { - Connection conn = DriverManager.getConnection(m_url, user, pass); - String query = "select \"Kuerzel\", \"Klartext\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Datenfeld\" = '" + df + "' " - + "OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; + String query = "select kuerzel, klartext from " + wb + " w join " + st + " s " + + "on w.typ = s.nebentypbez where (s.datenfeld = '" + df + "' " + + "OR s.datenfeld = 'diverse') AND kuerzel= ?"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); LOG.fine("Executing statement: " + stmt); @@ -83,6 +128,10 @@ public static String getS3Name(String sep3Code) throws SQLException { result = rs.getString(2); } LOG.fine("Returning: " + result); + + rs.close(); + stmt.close(); + return result; } } @@ -94,9 +143,10 @@ public static String getS3Name(String sep3Code) throws SQLException { * @throws SQLException if DB error occurs */ public static String getS3AsBMmlLitho(String sep3Code) throws SQLException { - Connection conn = DriverManager.getConnection(m_url, user, pass); String query = "select bml_code from " + sm + " where sep3_codelist = 'S3PETRO' AND sep3_code = ?"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); LOG.fine("Executing statement: " + stmt); @@ -107,6 +157,10 @@ public static String getS3AsBMmlLitho(String sep3Code) throws SQLException { result = rs.getString(1); } LOG.fine("Returning: " + result); + + rs.close(); + stmt.close(); + return result; } } @@ -118,10 +172,10 @@ public static String getS3AsBMmlLitho(String sep3Code) throws SQLException { * @throws SQLException if DB error occurs */ public static String getAllowedAttribs(String sep3Code) throws SQLException { - Connection conn = DriverManager.getConnection(m_url, user, pass); - String query = "select \"Kuerzel\", \"Attribute\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" " - + "where (s.\"Datenfeld\" = 'PETRO' OR s.\"Datenfeld\" = 'diverse') AND \"Kuerzel\"= ?"; + String query = "select kuerzel, attribute from " + wb + " w join " + st + " s " + "on w.typ = s.nebentypbez " + + "where (s.datenfeld = 'PETRO' OR s.datenfeld = 'diverse') AND kuerzel= ?"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, sep3Code); LOG.fine("Executing statement: " + stmt); @@ -132,6 +186,10 @@ public static String getAllowedAttribs(String sep3Code) throws SQLException { result = rs.getString(2); } LOG.fine("Returning: " + result); + + rs.close(); + stmt.close(); + return result; } } @@ -150,9 +208,10 @@ public static String getBodenQuant(String sep3Code, String quant) throws SQLExce allowedAttributes = getAllowedAttribs(sep3Code); quantBez = getQuantBezFromAttribs(allowedAttributes); - Connection conn = DriverManager.getConnection(m_url, user, pass); - String query = "select w.\"Kuerzel\", w.\"Klartext\", s.\"Nebentypbez\" from " + wb + " w join " + st + " s " - + "on w.\"Typ\" = s.\"Nebentypbez\" where (s.\"Nebentypbez\" = ? AND w.\"Kuerzel\" = ?);"; + String query = "select w.kuerzel, w.klartext, s.nebentypbez from " + wb + " w join " + st + " s " + + "on w.typ = s.nebentypbez where (s.nebentypbez = ? AND w.kuerzel = ?);"; + if (credChanged) + setConn(m_url, user, pass); PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, quantBez); stmt.setString(2, quant); @@ -165,6 +224,9 @@ public static String getBodenQuant(String sep3Code, String quant) throws SQLExce } LOG.fine("Returning: " + result); + rs.close(); + stmt.close(); + return result; } } diff --git a/src/main/java/org/sep3tools/Launch.java b/src/main/java/org/sep3tools/Launch.java index 8e72958..b818e84 100644 --- a/src/main/java/org/sep3tools/Launch.java +++ b/src/main/java/org/sep3tools/Launch.java @@ -7,6 +7,8 @@ import org.postgresql.pljava.annotation.Function; import org.sep3tools.gen.*; +import java.sql.SQLException; + /** * Command line launcher for SEP3 tools * @@ -38,6 +40,10 @@ else if (args.length == 0 || args[0].isEmpty()) { else if (args.length == 1) { sep3String = args[0]; } + else if (args.length == 2) { + JavaConnector.setPropertiesFile(args[0]); + sep3String = args[1]; + } else { System.out.println("Aufruf mit folgenden Parametern:\n" + "[JDBC-URL] [DB-User] [DB-Passwort] [Woerterbuch-Tabelle] [Schlüsseltypen-Tabelle] <SEP3-String>\n\n" diff --git a/src/main/java/org/sep3tools/LaunchBML.java b/src/main/java/org/sep3tools/LaunchBML.java index 637c94f..83a0f37 100644 --- a/src/main/java/org/sep3tools/LaunchBML.java +++ b/src/main/java/org/sep3tools/LaunchBML.java @@ -8,12 +8,13 @@ import org.sep3tools.gen.PetroGrammarLexer; import org.sep3tools.gen.PetroGrammarParser; +import java.sql.SQLException; import java.util.*; import static java.util.Objects.isNull; /** - * Command line launcher for SEP3 to BML tool + * Command line launcher for SEP3 to BML tool. * * @author Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> */ @@ -21,7 +22,7 @@ public class LaunchBML { /** * Launches SEP3 tool with arguments: - * @param args DB URL, DB user, DB password, Schluesselmapping table name SEP3 string + * @param args DB URL, DB user, DB password, Schluesselmapping table name SEP3 string. * to process */ public static void main(String[] args) { @@ -120,10 +121,10 @@ public static String S3_AsBmlLitho(String s3String, String sm) { * @return BML format of SEP3 input */ @Function - public static String S3_AsBmlLitho_verbose(String s3String, String sm) { + public static String s3AsBmlLithoVerbose(final String s3String, final String sm) { JavaConnector.setSm(sm); String result = S3_AsBmlLitho(s3String); return result; } -} \ No newline at end of file +} diff --git a/src/test/java/org/sep3tools/BmlExamplesTest.java b/src/test/java/org/sep3tools/BmlExamplesTest.java index ebef69a..97d5389 100644 --- a/src/test/java/org/sep3tools/BmlExamplesTest.java +++ b/src/test/java/org/sep3tools/BmlExamplesTest.java @@ -18,6 +18,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.SQLException; import java.util.Enumeration; import java.util.Properties; @@ -28,20 +29,12 @@ @Ignore("Class not ready for automatic tests, integrations tests depend on running database") public class BmlExamplesTest { - static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; - static final String USER = "petroparser"; - static final String PASS = "PetroParser"; - static final String SMTABLE = "bml.bml_schluesselmapping"; - @Test public void verifyBmlExamples() { - JavaConnector.setUrl(DB_URL); - JavaConnector.setUser(USER); - JavaConnector.setPass(PASS); - JavaConnector.setSm(SMTABLE); - try { + JavaConnector.setPropertiesFile("db.properties"); + File file = new File("bmltest.properties"); FileInputStream fileInput = new FileInputStream(file); Properties properties = new Properties(); diff --git a/src/test/java/org/sep3tools/SepExamplesTest.java b/src/test/java/org/sep3tools/SepExamplesTest.java index 7db6bbd..d89c796 100644 --- a/src/test/java/org/sep3tools/SepExamplesTest.java +++ b/src/test/java/org/sep3tools/SepExamplesTest.java @@ -21,6 +21,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.SQLException; import java.util.Enumeration; import java.util.Properties; @@ -29,11 +30,7 @@ @Ignore("Class not ready for automatic tests, integrations tests depend on running database") public class SepExamplesTest { - static final String DB_URL = "jdbc:postgresql://localhost/petroparser"; - static final String USER = "petroparser"; - static final String PASS = "PetroParser"; - static final String WBTABLE = "woerterbuch.\"Woerterbuch\""; - static final String STTABLE = "woerterbuch.\"Schluesseltypen\""; + static final String DBPROPFILENAME = "db.properties"; @Test public void verifyPetroExamples() { @@ -77,11 +74,8 @@ public void verifyFarbeExamples() { public void verifySepExamples(String df, String propFile) { - JavaConnector.setUrl(DB_URL); - JavaConnector.setUser(USER); - JavaConnector.setPass(PASS); - JavaConnector.setWb(WBTABLE); - JavaConnector.setSt(STTABLE); + JavaConnector.setPropertiesFile(DBPROPFILENAME); + JavaConnector.setDf(df); try { From 030621a2669b46b8b9e0e3487a00abb658811786 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Mon, 25 Sep 2023 00:58:28 +0200 Subject: [PATCH 08/12] moved properties files and fixed database connection for in database use --- .../java/org/sep3tools/JavaConnector.java | 3 +-- .../main/resources/beschbgtest.properties | 0 .../main/resources/beschbvtest.properties | 0 .../main/resources/bgruppetest.properties | 0 .../main/resources/bmltest.properties | 0 .../main/resources/farbetest.properties | 0 .../main/resources/genesetest.properties | 0 .../main/resources/kalkgehtest.properties | 0 .../main/resources/petrotest.properties | 4 +++- .../main/resources/zusatztest.properties | 0 .../java/org/sep3tools/SepExamplesTest.java | 19 ++++++++----------- 11 files changed, 12 insertions(+), 14 deletions(-) rename beschbgtest.properties => src/main/resources/beschbgtest.properties (100%) rename beschbvtest.properties => src/main/resources/beschbvtest.properties (100%) rename bgruppetest.properties => src/main/resources/bgruppetest.properties (100%) rename bmltest.properties => src/main/resources/bmltest.properties (100%) rename farbetest.properties => src/main/resources/farbetest.properties (100%) rename genesetest.properties => src/main/resources/genesetest.properties (100%) rename kalkgehtest.properties => src/main/resources/kalkgehtest.properties (100%) rename petrotest.properties => src/main/resources/petrotest.properties (97%) rename zusatztest.properties => src/main/resources/zusatztest.properties (100%) diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index 6e907e6..186d98c 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -5,7 +5,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.sql.*; -import java.util.Enumeration; import java.util.Properties; import java.util.logging.Logger; @@ -22,7 +21,7 @@ public final class JavaConnector { private static final Logger LOG = Logger.getLogger(JavaConnector.class.getName()); - private static String m_url; + private static String m_url = "jdbc:default:connection"; private static String user; diff --git a/beschbgtest.properties b/src/main/resources/beschbgtest.properties similarity index 100% rename from beschbgtest.properties rename to src/main/resources/beschbgtest.properties diff --git a/beschbvtest.properties b/src/main/resources/beschbvtest.properties similarity index 100% rename from beschbvtest.properties rename to src/main/resources/beschbvtest.properties diff --git a/bgruppetest.properties b/src/main/resources/bgruppetest.properties similarity index 100% rename from bgruppetest.properties rename to src/main/resources/bgruppetest.properties diff --git a/bmltest.properties b/src/main/resources/bmltest.properties similarity index 100% rename from bmltest.properties rename to src/main/resources/bmltest.properties diff --git a/farbetest.properties b/src/main/resources/farbetest.properties similarity index 100% rename from farbetest.properties rename to src/main/resources/farbetest.properties diff --git a/genesetest.properties b/src/main/resources/genesetest.properties similarity index 100% rename from genesetest.properties rename to src/main/resources/genesetest.properties diff --git a/kalkgehtest.properties b/src/main/resources/kalkgehtest.properties similarity index 100% rename from kalkgehtest.properties rename to src/main/resources/kalkgehtest.properties diff --git a/petrotest.properties b/src/main/resources/petrotest.properties similarity index 97% rename from petrotest.properties rename to src/main/resources/petrotest.properties index 0550202..4903dca 100644 --- a/petrotest.properties +++ b/src/main/resources/petrotest.properties @@ -13,4 +13,6 @@ U(ms2,x(+Gr(gro(0.005))))=Schluff (schwach mittelsandig, steinig (Granit (gro (fG-gG)(x)=(Feinkies [2,0-6,3 mm] bis Grobkies [20-63 mm]) (steinig) (^u(t,fs(tw)),^gs,^fs,^d(s,ikl))(wl)=(Schluffstein (tonig, feinsandig (teilweise)), Grobsandstein, Feinsandstein, Dolomitstein (sandig, intraklastisch)) (wechsellagernd) (U,fS)(ms2)=(Schluff, Feinsand [0,063-0,2 mm]) (schwach mittelsandig) -(^k(mas,fla,pof,bel)),(fls(rgu))=Kalkstein (massig, flaserig, Porifera, Belemniten), Flasern (unregelmäßig) \ No newline at end of file +(^k(mas,fla,pof,bel)),(fls(rgu))=Kalkstein (massig, flaserig, Porifera, Belemniten), Flasern (unregelmäßig) +"ca"=Kalzit +ca=Calamiten diff --git a/zusatztest.properties b/src/main/resources/zusatztest.properties similarity index 100% rename from zusatztest.properties rename to src/main/resources/zusatztest.properties diff --git a/src/test/java/org/sep3tools/SepExamplesTest.java b/src/test/java/org/sep3tools/SepExamplesTest.java index d89c796..9b9ec06 100644 --- a/src/test/java/org/sep3tools/SepExamplesTest.java +++ b/src/test/java/org/sep3tools/SepExamplesTest.java @@ -21,7 +21,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.sql.SQLException; import java.util.Enumeration; import java.util.Properties; @@ -34,42 +33,42 @@ public class SepExamplesTest { @Test public void verifyPetroExamples() { - verifySepExamples("PETRO", "petrotest.properties"); + verifySepExamples("PETRO", "src/main/resources/petrotest.properties"); } @Test public void verifyBeschbgExamples() { - verifySepExamples("BESCHBG", "beschbgtest.properties"); + verifySepExamples("BESCHBG", "src/main/resources/beschbgtest.properties"); } @Test public void verifyBeschbvExamples() { - verifySepExamples("BESCHBV", "beschbvtest.properties"); + verifySepExamples("BESCHBV", "src/main/resources/beschbvtest.properties"); } @Test public void verifyBgruppeExamples() { - verifySepExamples("BGRUPPE", "bgruppetest.properties"); + verifySepExamples("BGRUPPE", "src/main/resources/bgruppetest.properties"); } @Test public void verifyGeneseExamples() { - verifySepExamples("GENESE", "genesetest.properties"); + verifySepExamples("GENESE", "src/main/resources/genesetest.properties"); } @Test public void verifyKalkgehExamples() { - verifySepExamples("KALKGEH", "kalkgehtest.properties"); + verifySepExamples("KALKGEH", "src/main/resources/kalkgehtest.properties"); } @Test public void verifyZusatzExamples() { - verifySepExamples("ZUSATZ", "zusatztest.properties"); + verifySepExamples("ZUSATZ", "src/main/resources/zusatztest.properties"); } @Test public void verifyFarbeExamples() { - verifySepExamples("FARBE", "farbetest.properties"); + verifySepExamples("FARBE", "src/main/resources/farbetest.properties"); } public void verifySepExamples(String df, String propFile) { @@ -91,8 +90,6 @@ public void verifySepExamples(String df, String propFile) { String expectedTranslation = properties.getProperty(sep3String); String translation = Launch.S3_AsText(sep3String); assertThat(translation, CoreMatchers.is(expectedTranslation)); - // System.out.println(sep3String + " transation matched expected value: " - // + translation); } } catch (FileNotFoundException e) { From 3cec44c2d763db9dd1aab5f71e3442f27e90e153 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Wed, 27 Sep 2023 15:46:40 +0200 Subject: [PATCH 09/12] added missing statement when the connection was changed with new credentials --- src/main/java/org/sep3tools/JavaConnector.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index 186d98c..e932446 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -102,6 +102,7 @@ private static void setConn(String url, String user, String pass) throws SQLExce if (conn != null && !conn.isClosed()) conn.close(); JavaConnector.conn = DriverManager.getConnection(url, user, pass); + credChanged = false; } /** From fe2114c8da61a2195da985635e1821209a0c9011 Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Tue, 3 Oct 2023 11:02:25 +0200 Subject: [PATCH 10/12] added support for mutliple uebergaenge --- src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 | 2 +- src/main/java/org/sep3tools/BmlVisitor.java | 11 +++++++++-- src/main/java/org/sep3tools/PetroVisitor.java | 12 +++++++++--- src/main/resources/petrotest.properties | 1 + src/test/java/org/sep3tools/BmlExamplesTest.java | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 b/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 index 2bc6921..65b7c50 100644 --- a/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 +++ b/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 @@ -10,7 +10,7 @@ bestandteile: ; uebergang_bes: - b1=bestandteil '-' b2=bestandteil + bestandteil ('-' bestandteil)+ | '(' uebergang_bes ')' ( '(' attribute ')' )? ; diff --git a/src/main/java/org/sep3tools/BmlVisitor.java b/src/main/java/org/sep3tools/BmlVisitor.java index 0da39cb..cafc261 100644 --- a/src/main/java/org/sep3tools/BmlVisitor.java +++ b/src/main/java/org/sep3tools/BmlVisitor.java @@ -122,14 +122,21 @@ public String visitAttr(PetroGrammarParser.AttrContext ctx) { */ @Override public String visitUebergang_bes(PetroGrammarParser.Uebergang_besContext ctx) { - String teile; + String teile = ""; String attrib; if (ctx.getText().startsWith(" (")) { teile = visit(ctx.uebergang_bes()); } else { - teile = visit(ctx.b1) + ", " + visit(ctx.b2); + for (PetroGrammarParser.BestandteilContext teil : ctx.bestandteil()) { + if (teile.isEmpty()) { + teile = visit(teil); + } + else { + teile = teile + ", " + visit(teil); + } + } } if (isNull(ctx.attribute())) { attrib = ""; diff --git a/src/main/java/org/sep3tools/PetroVisitor.java b/src/main/java/org/sep3tools/PetroVisitor.java index befb1e0..3837ae7 100644 --- a/src/main/java/org/sep3tools/PetroVisitor.java +++ b/src/main/java/org/sep3tools/PetroVisitor.java @@ -170,15 +170,21 @@ public String visitAttr(PetroGrammarParser.AttrContext ctx) { */ @Override public String visitUebergang_bes(PetroGrammarParser.Uebergang_besContext ctx) { - String teile; + String teile = ""; String attrib; if (ctx.getText().trim().startsWith("(")) { teile = "(" + visit(ctx.uebergang_bes()) + ")"; } else { - teile = visit(ctx.b1) + " bis " + visit(ctx.b2); + for (PetroGrammarParser.BestandteilContext teil : ctx.bestandteil()) { + if (teile.isEmpty()) { + teile = visit(teil); + } + else { + teile = teile + " bis " + visit(teil); + } + } } - if (isNull(ctx.attribute())) { attrib = ""; } diff --git a/src/main/resources/petrotest.properties b/src/main/resources/petrotest.properties index 4903dca..bb2cbd8 100644 --- a/src/main/resources/petrotest.properties +++ b/src/main/resources/petrotest.properties @@ -16,3 +16,4 @@ U(ms2,x(+Gr(gro(0.005))))=Schluff (schwach mittelsandig, steinig (Granit (gro (^k(mas,fla,pof,bel)),(fls(rgu))=Kalkstein (massig, flaserig, Porifera, Belemniten), Flasern (unregelmäßig) "ca"=Kalzit ca=Calamiten +(gG-mG-fG)(gs-fs)=(Grobkies [20-63 mm] bis Mittelkies [6,3-20 mm] bis Feinkies [2,0-6,3 mm]) (grobsandig bis feinsandig) diff --git a/src/test/java/org/sep3tools/BmlExamplesTest.java b/src/test/java/org/sep3tools/BmlExamplesTest.java index 97d5389..b22cc6e 100644 --- a/src/test/java/org/sep3tools/BmlExamplesTest.java +++ b/src/test/java/org/sep3tools/BmlExamplesTest.java @@ -35,7 +35,7 @@ public void verifyBmlExamples() { try { JavaConnector.setPropertiesFile("db.properties"); - File file = new File("bmltest.properties"); + File file = new File("src/main/resources/bmltest.properties"); FileInputStream fileInput = new FileInputStream(file); Properties properties = new Properties(); properties.load(fileInput); From cda62e75ee803a7b60443e191fa7672b88e8384e Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Tue, 3 Oct 2023 12:30:09 +0200 Subject: [PATCH 11/12] added properties fraglich and sicher for bestandteil --- .../antlr4/org/sep3tools/gen/PetroGrammar.g4 | 10 +++-- src/main/java/org/sep3tools/BmlVisitor.java | 32 +++++++++++---- src/main/java/org/sep3tools/PetroVisitor.java | 40 ++++++++++++++++--- src/main/resources/petrotest.properties | 2 + 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 b/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 index 65b7c50..2324732 100644 --- a/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 +++ b/src/main/antlr4/org/sep3tools/gen/PetroGrammar.g4 @@ -15,8 +15,11 @@ uebergang_bes: ; bestandteil: - TEIL ( '(' attribute ')' )? - | '(' TEIL ( '(' attribute ')' )? ')'; + TEIL ( '(' attribute ')' )? # bestandteil_simple + | '(' bestandteil ')' # bestandteil_klammer + | bestandteil FRAGLICH # bestandteil_fraglich + | bestandteil SICHER # bestandteil_sicher +; attribute: attribut # att @@ -24,6 +27,7 @@ attribute: | attr=attribute '(' unter=attribute ')' # unter_Attribute | attribute ',' attribute # Aufzaehlung_a ; + uebergang_att: attribut '-' attribut; attribut: @@ -31,7 +35,7 @@ attribut: | attribut FRAGLICH # attr_fraglich | attribut SICHER # attr_sicher | TIEFE # attr_tiefe - ; +; TIEFE: ([0-9]|'.')+; TEIL: ANY+; diff --git a/src/main/java/org/sep3tools/BmlVisitor.java b/src/main/java/org/sep3tools/BmlVisitor.java index cafc261..8513df6 100644 --- a/src/main/java/org/sep3tools/BmlVisitor.java +++ b/src/main/java/org/sep3tools/BmlVisitor.java @@ -46,13 +46,11 @@ public String visitSchichtbeschreibung(PetroGrammarParser.SchichtbeschreibungCon return visitChildren(ctx); } - /** - * process single soil, remove quantifier, if present - * @param ctx the parse tree - * @return translated string for soil parse tree - */ - @Override - public String visitBestandteil(PetroGrammarParser.BestandteilContext ctx) { + public String visitBestandteil_klammer(PetroGrammarParser.Bestandteil_klammerContext ctx) { + return visitBestandteil_simple((PetroGrammarParser.Bestandteil_simpleContext) ctx.bestandteil()); + } + + public String visitBestandteil_simple(PetroGrammarParser.Bestandteil_simpleContext ctx) { String boden = getBodenTerm(ctx.TEIL().getText()); String attrib; if (isNull(ctx.attribute())) { @@ -73,6 +71,26 @@ else if (attr.startsWith(" (")) { return boden + "," + attrib; } + /** + * Visit a parse tree produced by the {@code bestandteil_sicher} labeled alternative + * in {@link PetroGrammarParser}. + * @param ctx the parse tree + * @return the visitor result + */ + public String visitBestandteil_sicher(PetroGrammarParser.Bestandteil_sicherContext ctx) { + return visitChildren(ctx); + } + + /** + * Visit a parse tree produced by the {@code bestandteil_fraglich} labeled alternative + * in {@link PetroGrammarParser}. + * @param ctx the parse tree + * @return the visitor result + */ + public String visitBestandteil_fraglich(PetroGrammarParser.Bestandteil_fraglichContext ctx) { + return visitChildren(ctx); + } + private String getBodenTerm(String boden) { String bodenTerm = getBmlResultSet(boden); if (!bodenTerm.isEmpty()) diff --git a/src/main/java/org/sep3tools/PetroVisitor.java b/src/main/java/org/sep3tools/PetroVisitor.java index 3837ae7..a530642 100644 --- a/src/main/java/org/sep3tools/PetroVisitor.java +++ b/src/main/java/org/sep3tools/PetroVisitor.java @@ -47,12 +47,22 @@ public String visitSchichtbeschreibung(PetroGrammarParser.SchichtbeschreibungCon } /** - * process single soil takes quantifier into account, if present + * Visit a parse tree produced by the {@code bestandteil_klammer} labeled alternative + * in {@link PetroGrammarParser}. * @param ctx the parse tree - * @return translated string for soil parse tree + * @return the visitor result */ - @Override - public String visitBestandteil(PetroGrammarParser.BestandteilContext ctx) { + public String visitBestandteil_klammer(PetroGrammarParser.Bestandteil_klammerContext ctx) { + return visitBestandteil_simple((PetroGrammarParser.Bestandteil_simpleContext) ctx.bestandteil()); + } + + /** + * Visit a parse tree produced by the {@code bestandteil_simple} labeled alternative + * in {@link PetroGrammarParser}. + * @param ctx the parse tree + * @return the visitor result + */ + public String visitBestandteil_simple(PetroGrammarParser.Bestandteil_simpleContext ctx) { String boden = getBodenTerm(ctx.TEIL().getText()); String attrib; if (isNull(ctx.attribute())) { @@ -70,11 +80,29 @@ else if (attr.trim().startsWith("(")) { attrib = " (" + attr + ")"; } } - // if (ctx.getText().startsWith("(")) - // return "(" + boden + attrib + ")"; return boden + attrib; } + /** + * Visit a parse tree produced by the {@code bestandteil_sicher} labeled alternative + * in {@link PetroGrammarParser}. + * @param ctx the parse tree + * @return the visitor result + */ + public String visitBestandteil_sicher(PetroGrammarParser.Bestandteil_sicherContext ctx) { + return visitChildren(ctx) + " sicher"; + } + + /** + * Visit a parse tree produced by the {@code bestandteil_fraglich} labeled alternative + * in {@link PetroGrammarParser}. + * @param ctx the parse tree + * @return the visitor result + */ + public String visitBestandteil_fraglich(PetroGrammarParser.Bestandteil_fraglichContext ctx) { + return visitChildren(ctx) + " fraglich"; + } + private String getBodenTerm(String boden) { String bodenTerm = getS3ResultSet(boden); if (!bodenTerm.isEmpty()) diff --git a/src/main/resources/petrotest.properties b/src/main/resources/petrotest.properties index bb2cbd8..b4b6417 100644 --- a/src/main/resources/petrotest.properties +++ b/src/main/resources/petrotest.properties @@ -17,3 +17,5 @@ U(ms2,x(+Gr(gro(0.005))))=Schluff (schwach mittelsandig, steinig (Granit (gro "ca"=Kalzit ca=Calamiten (gG-mG-fG)(gs-fs)=(Grobkies [20-63 mm] bis Mittelkies [6,3-20 mm] bis Feinkies [2,0-6,3 mm]) (grobsandig bis feinsandig) +G?=Kies [gerundet] fraglich +G!=Kies [gerundet] sicher From 9a9fe7904bd355a1fda083610f2b3f57309d481d Mon Sep 17 00:00:00 2001 From: Jeronimo Wanhoff <kontakt@jeronimowanhoff.de> Date: Mon, 23 Oct 2023 10:43:48 +0200 Subject: [PATCH 12/12] removed double entry for df variable --- src/main/java/org/sep3tools/JavaConnector.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/sep3tools/JavaConnector.java b/src/main/java/org/sep3tools/JavaConnector.java index d32c2a0..e932446 100644 --- a/src/main/java/org/sep3tools/JavaConnector.java +++ b/src/main/java/org/sep3tools/JavaConnector.java @@ -37,8 +37,6 @@ public final class JavaConnector { private static Connection conn; - private static String df = "PETRO"; - private JavaConnector() { }