From db0fb51ab25d003d01e93529c658630e617b6185 Mon Sep 17 00:00:00 2001 From: git Date: Thu, 31 Oct 2024 23:19:55 -0700 Subject: [PATCH 01/28] [Terry N.] stack arg not req. here --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a31d420b..6b199a0a 100644 --- a/README.md +++ b/README.md @@ -491,7 +491,7 @@ java -Xmx4g -cp $SIGMA_CP com.articulate.sigma.PasswordService -c Then create the administrator account and password ```sh -java -Xmx4g -Xss1m -cp $SIGMA_CP com.articulate.sigma.PasswordService -a +java -Xmx4g -cp $SIGMA_CP com.articulate.sigma.PasswordService -a ``` You can use Sigma without being administrator, but you'll have limited use of its functionality. From 536f8bc3d02fb183248dd5bc9c3f7054e31cfca2 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 10:02:20 -0700 Subject: [PATCH 02/28] [Terry N.] recommended by GitHub dependabot --- .github/workflows/ant.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index aa69a87d..97a4dc80 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -177,12 +177,12 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Download artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.7 with: name: artifact - name: Download artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.7 with: name: sigma-webapp From c9c7e45e89cb2fb36f8fbbfff2d67cae5591101c Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 10:03:09 -0700 Subject: [PATCH 03/28] [Terry N.] remove temp comment --- .github/workflows/ant.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 97a4dc80..12fdc203 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -28,14 +28,12 @@ jobs: uses: actions/checkout@v4 with: repository: 'ontologyportal/TPTP-ANTLR' -# repository: 'terry-norbraten/TPTP-ANTLR' path: TPTP-ANTLR - name: checkout SigmaUtils uses: actions/checkout@v4 with: repository: 'ontologyportal/SigmaUtils' -# repository: 'terry-norbraten/SigmaUtils' path: SigmaUtils - name: checkout sumo From b1bee39a7960be273378ed907118e4a4a59de7fd Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 12:20:48 -0700 Subject: [PATCH 04/28] [Terry N.] incr stack size in CATALINA_OPS --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b199a0a..cb6b0b0c 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,7 @@ sudo apt-get install graphviz echo "export SIGMA_HOME=~/.sigmakee" >> .bashrc echo "export ONTOLOGYPORTAL_GIT=~/workspace" >> .bashrc echo "export SIGMA_SRC=$ONTOLOGYPORTAL_GIT/sigmakee" >> .bashrc -echo "export CATALINA_OPTS=\"-Xmx10g\"" >> .bashrc +echo "export CATALINA_OPTS=\"-Xmx10g -Xss1m\"" >> .bashrc echo "export CATALINA_HOME=~/Programs/apache-tomcat-9.0.96" >> .bashrc echo "export PATH=$CATALINA_HOME/bin:$PATH" >> .bashrc echo "export SIGMA_CP=$SIGMA_SRC/build/sigmakee.jar:$SIGMA_SRC/lib/*" >> .bashrc From 4fcda1b87fa8ab9760c6c8db07ae8668757a7dc3 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 12:20:58 -0700 Subject: [PATCH 05/28] [Terry N.] incr stack size in CATALINA_OPS --- INSTALL.MacOS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.MacOS b/INSTALL.MacOS index 8e17d7df..7cb6d71b 100644 --- a/INSTALL.MacOS +++ b/INSTALL.MacOS @@ -40,7 +40,7 @@ these variables created before the next step, and replace /Users/user with your export SIGMA_HOME=/Users/user/.sigmakee export ONTOLOGYPORTAL_GIT=/Users/user/workspace export SIGMA_SRC=$ONTOLOGYPORTAL_GIT/sigmakee - export CATALINA_OPTS="-Xmx10g" + export CATALINA_OPTS="-Xmx10g -Xss1m" export CATALINA_HOME=/Users/user/Programs/apache-tomcat-9.0.96 export PATH=$CATALINA_HOME/bin:$PATH export SIGMA_CP=$SIGMA_SRC/build/sigmakee.jar:$SIGMA_SRC/lib/* From 19604b6601ab534ee28d78c4b62d3a16d43cf469 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 12:21:13 -0700 Subject: [PATCH 06/28] [Terry N.] incr stack size in CATALINA_OPS --- nbproject/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbproject/build.properties b/nbproject/build.properties index 9078d46a..a1ad4780 100644 --- a/nbproject/build.properties +++ b/nbproject/build.properties @@ -127,7 +127,7 @@ project.license=LICENSE run.args= # Tomcat Manager properties -catalina.ops=-Xmx10g +catalina.ops=-Xmx10g -Xss1m catalina.base=${catalina.home} catalina.logs.dir=${catalina.base}/logs catalina.out=${catalina.logs.dir}/catalina.out From 236f0f7e88341656e67b38692361cfc4135d083e Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 15:12:15 -0700 Subject: [PATCH 07/28] [Terry N.] typo --- CONTRIBUTING.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8832bbe..a503caab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,14 +4,14 @@ By participating in this project, you agree to abide by the [code of conduct](#c ## Issues -One of the easiest ways to contribute is to solve an issue https://github.com/ontologyportal/sigmakee/issues +One of the easiest ways to contribute is to solve an issue https://github.com/ontologyportal/sigmakee/issues ## Additions * We use jUnit for testing. When making any addition of functionality, please add some jUnit tests to show that it works and prevent regressions. * adhere to the Java style guide for Sigma - https://github.com/ontologyportal/sigmakee/blob/master/CodeFormat.pdf -* if the functionality requires a GUI, add a .jsp interface copying and modifying and existing JSP in Sigma +* if the functionality requires a GUI, add a .jsp interface copying and modifying an existing JSP in Sigma * if the functionality can be meaningfully executed on the command line, add to the main() for the class, following the style of an existing class like com.articulate.sigma.KB with its showHelp() method so it functions like a standard Unix command with a man page @@ -36,39 +36,39 @@ in the README https://github.com/ontologyportal/sigmakee/blob/master/README.txt) ## Code of conduct -In order to foster an inclusive, kind, harassment-free, and cooperative community, +In order to foster an inclusive, kind, harassment-free, and cooperative community, we enforce this code of conduct on our open source projects. ### Summary -Harassment in code and discussion or violation of physical boundaries is completely -unacceptable anywhere in our project. Violators will be warned by the core team. -Repeat violations will result in being blocked or banned by the core team at or +Harassment in code and discussion or violation of physical boundaries is completely +unacceptable anywhere in our project. Violators will be warned by the core team. +Repeat violations will result in being blocked or banned by the core team at or before the 3rd violation. ### In detail -Harassment includes offensive verbal comments related to gender identity, -gender expression, sexual orientation, disability, physical appearance, body size, -race, religion, sexual images, deliberate intimidation, stalking, sustained +Harassment includes offensive verbal comments related to gender identity, +gender expression, sexual orientation, disability, physical appearance, body size, +race, religion, sexual images, deliberate intimidation, stalking, sustained disruption, and unwelcome sexual attention. Individuals asked to stop any harassing behavior are expected to comply immediately. Maintainers are also subject to the anti-harassment policy. -If anyone engages in harassing behavior, including maintainers, we may take -appropriate action, up to and including warning the offender, deletion of -comments, removal from the project’s codebase and communication systems, +If anyone engages in harassing behavior, including maintainers, we may take +appropriate action, up to and including warning the offender, deletion of +comments, removal from the project’s codebase and communication systems, and escalation to GitHub support. -If you are being harassed, notice that someone else is being harassed, or +If you are being harassed, notice that someone else is being harassed, or have any other concerns, please contact us immediately We expect everyone to follow these rules anywhere in our project. -Finally, don't forget that it is human to make mistakes! We all do. Let’s -work together to help each other, resolve issues, and learn from the mistakes +Finally, don't forget that it is human to make mistakes! We all do. Let’s +work together to help each other, resolve issues, and learn from the mistakes that we will all inevitably make from time to time. ### Thanks From ec34bc34289ef77e958548a1aa5980f374510a46 Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 15:13:29 -0700 Subject: [PATCH 08/28] [Terry N.] place holder for further purges of KBs *.ser --- build.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.xml b/build.xml index 1de50dea..0ab93782 100644 --- a/build.xml +++ b/build.xml @@ -341,6 +341,9 @@ + From 96dfc67fb5ddffd01333fd96f4762603999bfe0b Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 15:13:48 -0700 Subject: [PATCH 09/28] [Terry N.] place holder for further purges of KBs *.ser --- nbproject/ide-targets.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nbproject/ide-targets.xml b/nbproject/ide-targets.xml index 38f4d8f9..041ba2a1 100644 --- a/nbproject/ide-targets.xml +++ b/nbproject/ide-targets.xml @@ -550,6 +550,9 @@ + + + From 00b36f6c6633cd1c569ac6c5deb62ab17e42e9ba Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 19:39:32 -0700 Subject: [PATCH 10/28] [Terry N.] add javadoc dir --- nbproject/project.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbproject/project.xml b/nbproject/project.xml index 86fa1eb2..68ef7a12 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -356,7 +356,7 @@ auxiliary.show.customizer.message= src/java lib/commons-lang3-3.12.0.jar:lib/cos-09May2002.jar:lib/guava-19.0.jar:lib/h2-2.3.232.jar:lib/java-prolog-parser-2.0.2.jar:lib/json-simple-1.1.1.jar:lib/kryo-5.6.2.jar:lib/mail-1.4.jar:lib/py4j-0.10.6.jar:lib/sigmaUtils.jar:lib/stanford-corenlp-4.5.4.jar:lib/tptp.jar build/WEB-INF/classes - dist/doc/api + doc 11 From f1605b96c7d1fc69f38ae1af3d8f1ef85456117a Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 19:48:53 -0700 Subject: [PATCH 11/28] [Terry N.] don't delete doc.dir --- build.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.xml b/build.xml index 0ab93782..45949602 100644 --- a/build.xml +++ b/build.xml @@ -89,7 +89,7 @@ - + @@ -367,8 +367,6 @@ - - From 4603b766f2da08fc16fdf7d9b60e9bae6ae68e5c Mon Sep 17 00:00:00 2001 From: git Date: Fri, 1 Nov 2024 20:55:20 -0700 Subject: [PATCH 12/28] [Terry N.] remove warning as the PasswordService works again --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index cb6b0b0c..57f96bb4 100644 --- a/README.md +++ b/README.md @@ -479,9 +479,6 @@ than just com.articulate.sigma.KB ## Account Management -> **Warning** -> Please note this is not working as of Apr, 2020. - Create the account database with ```sh From 9b327ad67ea8c6ca4fce6a469465853de25317d8 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 01:22:08 -0700 Subject: [PATCH 13/28] [Terry N.] Fix for Issue #135 --- .../com/articulate/sigma/PasswordService.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/java/com/articulate/sigma/PasswordService.java b/src/java/com/articulate/sigma/PasswordService.java index 38f06475..fc4a37ed 100644 --- a/src/java/com/articulate/sigma/PasswordService.java +++ b/src/java/com/articulate/sigma/PasswordService.java @@ -6,8 +6,6 @@ code. */ package com.articulate.sigma; -//import org.h2.tools.Server; - import com.articulate.sigma.utils.StringUtil; import java.io.UnsupportedEncodingException; @@ -18,17 +16,22 @@ import java.util.*; import java.io.*; +import static java.lang.System.exit; + import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; -import static java.lang.System.exit; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; /** ***************************************************************** * A class that encrypts a string and checks it against another stored * encrypted string, in order to validate a user login. */ -public final class PasswordService { +@WebListener +public final class PasswordService implements ServletContextListener { private static PasswordService instance; @@ -38,16 +41,18 @@ public final class PasswordService { public static final String INITIAL_ADMIN_USER = "sumo"; // <- initial user when creating DB public Connection conn = null; // <- for JSP + private static final String H2_DRIVER = "org.h2.Driver"; + /** ***************************************************************** * Create an instance of PasswordService */ - private PasswordService() { + public PasswordService() { System.out.println("PasswordService()"); try { - Class.forName("org.h2.Driver"); // <- redundant for local invocation, but the JSPs need this + Class.forName(H2_DRIVER); // <- redundant for local invocation, but the JSPs need this conn = DriverManager.getConnection(JDBC_ACCESS_DB, INITIAL_ADMIN_USER, ""); - System.out.println("init(): Opened DB via: " + JDBC_ACCESS_DB); + System.out.println("init(): Opened PASSWD DB via: " + JDBC_ACCESS_DB); } catch (ClassNotFoundException | SQLException e) { System.err.println("Error in PasswordService(): " + e.getMessage()); @@ -55,6 +60,26 @@ private PasswordService() { } } + @Override + public void contextInitialized(ServletContextEvent servletContextEvent) { + System.out.println("Creating Sigma Context..."); + } + + // H2 shutdown guidance from: https://github.com/spring-projects/spring-boot/issues/21221 + // and: https://stackoverflow.com/questions/9972372/what-is-the-proper-way-to-close-h2 + // Fix for issue #35 + @Override + public void contextDestroyed(ServletContextEvent servletContextEvent) { + System.out.println("Destroying Sigma Context..."); + org.h2.Driver.unload(); + System.out.println("Deregistering and shutting down: " + H2_DRIVER); + + try (Statement stmt = conn.createStatement()) { + stmt.execute("SHUTDOWN"); + } + catch (SQLException e) {} + } + /** ***************************************************************** * Encrypts a string with a deterministic algorithm. Thanks to * https://howtodoinjava.com/security/how-to-generate-secure-password-hash-md5-sha-pbkdf2-bcrypt-examples/ @@ -442,7 +467,6 @@ else if (args.length > 1 && args[0].equals("-d")) if (ps != null && ps.conn != null) ps.conn.close(); System.out.println("PasswordService.main(): Closed DB"); - //Server.shutdownTcpServer(JDBCString,"", true, true); } catch(SQLException se){ se.printStackTrace(); From 97b37110c6d83764292d74c58636aa9dced8ac1e Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 01:26:07 -0700 Subject: [PATCH 14/28] [Terry N.] Fix for Issue #135 --- build.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/build.xml b/build.xml index 45949602..429cfd1d 100644 --- a/build.xml +++ b/build.xml @@ -242,6 +242,7 @@ + From 11994f4cda5ccab9f92f1bd7c5776e4c00ac550c Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 01:26:18 -0700 Subject: [PATCH 15/28] [Terry N.] Fix for Issue #135 --- ivy.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ivy.xml b/ivy.xml index 7aa4c2e7..8004b4de 100644 --- a/ivy.xml +++ b/ivy.xml @@ -20,6 +20,8 @@ + + From dbbbf8eb083b775127634903c9082bed63c34697 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 01:26:42 -0700 Subject: [PATCH 16/28] [Terry N.] Fix for Issue #135 --- nbproject/build.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/nbproject/build.properties b/nbproject/build.properties index a1ad4780..693cff9a 100644 --- a/nbproject/build.properties +++ b/nbproject/build.properties @@ -30,6 +30,7 @@ file.reference.integration-java=test/integration/java file.reference.unit-java=test/unit/java includes=** jar.compress=false +lib.dir=lib javac.classpath=\ lib/commons-lang3-3.12.0.jar:\ lib/cos-09May2002.jar:\ From 177ec7b08c00d00dc3a5d36996a8fb8461bd9d78 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 01:27:04 -0700 Subject: [PATCH 17/28] [Terry N.] Fix for Issue #135 --- nbproject/ide-targets.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nbproject/ide-targets.xml b/nbproject/ide-targets.xml index 041ba2a1..03044b97 100644 --- a/nbproject/ide-targets.xml +++ b/nbproject/ide-targets.xml @@ -55,7 +55,12 @@ - + + + + + + From 487665119bd172a6b56a22e8a2624956975a8f51 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 08:08:25 -0700 Subject: [PATCH 18/28] [Terry N.] Fix for Issue #135 --- nbproject/project.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbproject/project.xml b/nbproject/project.xml index 68ef7a12..9eb96c3a 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -354,7 +354,7 @@ auxiliary.show.customizer.message= src/java - lib/commons-lang3-3.12.0.jar:lib/cos-09May2002.jar:lib/guava-19.0.jar:lib/h2-2.3.232.jar:lib/java-prolog-parser-2.0.2.jar:lib/json-simple-1.1.1.jar:lib/kryo-5.6.2.jar:lib/mail-1.4.jar:lib/py4j-0.10.6.jar:lib/sigmaUtils.jar:lib/stanford-corenlp-4.5.4.jar:lib/tptp.jar + lib/commons-lang3-3.12.0.jar:lib/cos-09May2002.jar:lib/guava-19.0.jar:lib/h2-2.3.232.jar:lib/java-prolog-parser-2.0.2.jar:lib/json-simple-1.1.1.jar:lib/kryo-5.6.2.jar:lib/mail-1.4.jar:lib/py4j-0.10.6.jar:lib/sigmaUtils.jar:lib/stanford-corenlp-4.5.4.jar:lib/tomcat-servlet-api-9.0.96.jar:lib/tptp.jar build/WEB-INF/classes doc 11 From 8a43b4664be7d42c51462f478cbc5d245d06dd2a Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 09:04:29 -0700 Subject: [PATCH 19/28] [Terry N.] update jdk path --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57f96bb4..cdcc9e3c 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ handy to add stuff to .bashrc ```sh echo "alias dir='ls --color=auto --format=vertical -la'" >> .bashrc echo "export HISTSIZE=10000 HISTFILESIZE=100000" >> .bashrc -echo "export JAVA_HOME=/home/theuser/Programs/jdk-11.0.2" >> .bashrc +echo "export JAVA_HOME=/home/theuser/Programs/jdk-23" >> .bashrc ``` load the definitions into your environment @@ -366,7 +366,7 @@ Open up CMD prompt mkdir /home/theuser/Programs cd Programs sudo apt-get install openjdk-23-jdk - (This step might not be necessary, I'd try without it first) echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/jre" >> .bashrc + (This step might not be necessary, I'd try without it first) echo "export JAVA_HOME=/usr/lib/jvm/java-23-openjdk-amd64/jre" >> .bashrc ``` Follow Linux install instructions on: From 3fcb59839868951d4754234ba1f1c90b0c005929 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 09:07:07 -0700 Subject: [PATCH 20/28] [Terry N.] update graphviz path --- INSTALL.MacOS | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/INSTALL.MacOS b/INSTALL.MacOS index 7cb6d71b..90e3c246 100644 --- a/INSTALL.MacOS +++ b/INSTALL.MacOS @@ -1,7 +1,7 @@ Running the SigmaKEE docker image on macOS ========================================== -With homebrew: +With Homebrew: brew install --cask docker <- will install the latest Docker Desktop for macOS then: @@ -24,7 +24,7 @@ macOS install notes Homebrew. - java will be installed in /usr/libexec/java_home - get git from the xcode tools with "xcode-select --install” -- instead of .bashrc edit .bash_profile +- instead of ~/.bash_profile edit ~/.zshrc - install Homebrew from http://brew.sh and the packages: brew install make @@ -33,8 +33,9 @@ brew install git brew install graphviz brew install ant -Add the following lines in your .profile and make sure to have all -these variables created before the next step, and replace /Users/user with your home directory: +Add the following lines in your ~/.zshrc and make sure to have all +these variables created before the next step, and replace +/Users/user with your home directory: ## SUMO/SIGMAKEE export SIGMA_HOME=/Users/user/.sigmakee @@ -56,11 +57,11 @@ You will need at least Java 11+ to compile SigmaKee and to run Apache Tomcat. /usr/libexec/java_home --verbose -# Find your JDK (arm64) path and copy it (choose the one with the /JavaVirtualMachines/ instead of /Internet Plug-Ins/) +# Find your JDK (arm64 or x64) path and copy it (choose the one with the /JavaVirtualMachines/ instead of /Internet Plug-Ins/) export JAVA_HOME= 'path from before', then make sure "bin" is on our PATH - export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home + export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATH cd ~ @@ -110,6 +111,9 @@ May have to precede the last command with "sudo" cp ~/workspace/sigmakee/config.xml ~/.sigmakee/KBs (SOS) edit the config.xml changing all `wrong paths` to the value of `$HOME` and adapting all variables) +For Homebrew installations of GraphViz, change the path in config.xml for +graphVizDir to: /usr/local/bin + cd ~/workspace/sigmakee source ~/.zshrc or ~/.bash_profile ant From b33546c14020a9e51969699dc910ac202257e91e Mon Sep 17 00:00:00 2001 From: Adam Pease Date: Sat, 2 Nov 2024 09:05:04 -0700 Subject: [PATCH 21/28] Update README.md Add notice about recent changes that requires updating existing installations --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cdcc9e3c..1d52653e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# Notice + +2024 November 2 - We're making some improvements to clean up the configuration and code of Sigma and its associated projects. For existing installations, some changes are needed to stay in sync. OpenJDK is now supported, eliminating the dependency on Oracle JDK. Tomcat 9 is now required. A new environment variable SIGMA_CP is now required in your .bashrc (or similar for non-Linux). Please let us know if you have any issues! + # Introduction Sigma is an integrated development environment for logical theories that @@ -17,9 +21,7 @@ differ, then you may need to edit your config.xml manually. If you are running tomcat on vagrant or another VM, you may need to change the port value from 8080. If you are running on a server, rather than your localhost you'll need to set the hostname parameter in your config.xml file. E will only work if your $TMPDIR -is set correctly. No particular version of tomcat is required as long as it is -under version 10 (preferably lastest Tomcat V9). If you load a different -version of tomcat, be sure to change `$CATALINA_HOME` and your paths to +is set correctly. Tomcat V9 or later is required. Be sure to change `$CATALINA_HOME` and your paths to conform to the version. If you use a different mirror or version you'll need to change the wget commend below. Change "theuser" below to your user name. From 7e2cdc55138ffa8919b1d76759b3112c2ecf1e64 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 16:15:56 -0700 Subject: [PATCH 22/28] [Terry N.] update note about not using Tomcat 10, only 9 at this time --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1d52653e..d04cd208 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,10 @@ differ, then you may need to edit your config.xml manually. If you are running tomcat on vagrant or another VM, you may need to change the port value from 8080. If you are running on a server, rather than your localhost you'll need to set the hostname parameter in your config.xml file. E will only work if your $TMPDIR -is set correctly. Tomcat V9 or later is required. Be sure to change `$CATALINA_HOME` and your paths to -conform to the version. If you use a different mirror or version you'll need to -change the wget commend below. Change "theuser" below to your user name. +is set correctly. Tomcat V9 is required. Later versions of Tomcat are not yet +supported. Be sure to change `$CATALINA_HOME` and your paths to conform to the +version. If you use a different mirror or version you'll need to change the wget +commend below. Change "theuser" below to your user name. If your installation isn't working and you're getting funny "null"s in your paths try opening permissions on your `$SIGMA_HOME`, `$CATALINA_HOME` and `$SIGMA_SRC` directories. From 7e986a7de969dc3dc3d0ea607b6ea9e5575a1e18 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 19:05:21 -0700 Subject: [PATCH 23/28] [Terry N.] Fix for Issue #134 --- .../com/articulate/sigma/HTMLformatter.java | 406 ++++++++++-------- 1 file changed, 216 insertions(+), 190 deletions(-) diff --git a/src/java/com/articulate/sigma/HTMLformatter.java b/src/java/com/articulate/sigma/HTMLformatter.java index 3896560c..14ccce99 100644 --- a/src/java/com/articulate/sigma/HTMLformatter.java +++ b/src/java/com/articulate/sigma/HTMLformatter.java @@ -48,8 +48,8 @@ public class HTMLformatter { // set by BrowseBody.jsp or SimpleBrowseBody.jsp public static String language = "EnglishLanguage"; - public static ArrayList availableFormalLanguages = - new ArrayList(Arrays.asList("SUO-KIF", "TPTP", "traditionalLogic", "OWL")); + public static List availableFormalLanguages = + new ArrayList<>(Arrays.asList("SUO-KIF", "TPTP", "traditionalLogic", "OWL")); public static boolean debug = false; @@ -166,16 +166,16 @@ public static String proofTextFormat(String query, ProofStep step, String kbName result.append("QED"); } else - result.append(f.textFormat(f.getFormula())); + result.append(Formula.textFormat(f.getFormula())); if (step.inferenceType != null && step.inferenceType.equals("assume_negation")) { result.append("[Negated Query]"); } else { for (int i = 0; i < step.premises.size(); i++) { - Integer stepNum = (Integer) step.premises.get(i); - result.append(stepNum.toString() + " "); + Integer stepNum = step.premises.get(i); + result.append(stepNum.toString()).append(" "); } - if (step.premises.size() == 0) { + if (step.premises.isEmpty()) { if (step.formulaType != null && step.formulaType.equals("conjecture")) result.append("[Query]"); else if (step.formulaRole != null) @@ -207,7 +207,7 @@ public static String proofTableFormat(String query, TPTPFormula step, String kbN result.append("" + "QED" + ""); } else - result.append("" + f.htmlFormat(kbHref) + ""); + result.append("").append(f.htmlFormat(kbHref)).append(""); result.append(""); if (debug) System.out.println("Info in HTMLformatter.proofTableFormat(): premises : " + step.supports); @@ -217,18 +217,18 @@ public static String proofTableFormat(String query, TPTPFormula step, String kbN else { for (int i = 0; i < step.supports.size(); i++) { //String stepName = step.supports.get(i); - result.append(step.intsupports.get(i) + " "); + result.append(step.intsupports.get(i)).append(" "); } - if (step.intsupports.size() == 0) { + if (step.intsupports.isEmpty()) { if (step.type != null && step.type.equals("conjecture")) result.append("[Query]"); else if (!StringUtil.emptyString(step.infRule) && !step.infRule.equals("input") && !step.infRule.startsWith("kb_")) { if (KBmanager.getMgr().prover == KBmanager.Prover.VAMPIRE) - result.append("[" + step.infRule + "]"); + result.append("[").append(step.infRule).append("]"); else - result.append("[" + step.infRule + "]"); + result.append("[").append(step.infRule).append("]"); } else if (f.getFormula().contains("ans0")) result.append("answer literal introduction"); @@ -237,12 +237,12 @@ else if (f.getFormula().contains("ans0")) String key = step.infRule; Formula originalF = SUMOKBtoTPTPKB.axiomKey.get(key); if (originalF != null) - result.append(originalF.startLine + ":" + FileUtil.noPath(originalF.getSourceFile())); + result.append(originalF.startLine).append(":").append(FileUtil.noPath(originalF.getSourceFile())); result.append("]"); } } else if (!StringUtil.emptyString(step.infRule)) - result.append("[" + step.infRule + "]"); + result.append("[").append(step.infRule).append("]"); } result.append(""); if (StringUtil.isNonEmptyString(language)) { @@ -294,9 +294,10 @@ public static String processNaturalLanguage(String lang, KB kb) { public static String termList(ArrayList terms, String kbHref) { StringBuilder show = new StringBuilder(); + String term; for (int i = 0; i < terms.size(); i++) { - String term = terms.get(i); - show.append("" + term + ""); + term = terms.get(i); + show.append("").append(term).append(""); if (i < terms.size() - 1) show.append(", "); } @@ -319,30 +320,30 @@ public static String showStatistics(KB kb) { StringBuilder show = new StringBuilder(); show.append("Knowledge base statistics: as of "); - show.append(getDate() + "
"); + show.append(getDate()).append("
"); show.append("\n"); - show.append("
Total TermsTotal AxiomsTotal Rules
" + kb.getCountTerms()); - show.append(" " + kb.getCountAxioms()); - show.append(" " + kb.getCountRules()); + show.append(" ").append(kb.getCountTerms()); + show.append(" ").append(kb.getCountAxioms()); + show.append(" ").append(kb.getCountRules()); show.append("

\n"); - show.append("\n"); - show.append("\n"); + show.append("
Relations: " + kb.getCountRelations() + "
non-linguistic axioms: " + KButilities.getCountNonLinguisticAxioms(kb) + "
\n"); + show.append("\n"); show.append("
Relations: ").append(kb.getCountRelations()).append("
non-linguistic axioms: ").append(KButilities.getCountNonLinguisticAxioms(kb)).append("
\n"); HashMap stats = (HashMap) KButilities.countFormulaTypes(kb); - show.append("

\n"); - show.append("\n"); - show.append("\n"); + show.append("

Ground tuples: " + stats.get("ground") + "
  of which are binary: " + stats.get("binary") + "
  of which arity more than binary: " + stats.get("higher-arity") + "
\n"); + show.append("\n"); + show.append("\n"); show.append("
Ground tuples: ").append(stats.get("ground")).append("
  of which are binary: ").append(stats.get("binary")).append("
  of which arity more than binary: ").append(stats.get("higher-arity")).append("
\n"); - show.append("

\n"); - show.append("\n"); - show.append("\n"); - show.append("\n"); - show.append("\n"); - show.append("\n"); - show.append("\n"); + show.append("

Rules: " + kb.getCountRules() + "
  of which are horn: " + stats.get("horn") + "
first-order: " + stats.get("first-order") + "
temporal: " + stats.get("temporal") + "
modal: " + stats.get("modal") + "
epistemic: " + stats.get("epistemic") + "
other higher-order: " + stats.get("otherHOL") + "
\n"); + show.append("\n"); + show.append("\n"); + show.append("\n"); + show.append("\n"); + show.append("\n"); + show.append("\n"); show.append("
Rules: ").append(kb.getCountRules()).append("
  of which are horn: ").append(stats.get("horn")).append("
first-order: ").append(stats.get("first-order")).append("
temporal: ").append(stats.get("temporal")).append("
modal: ").append(stats.get("modal")).append("
epistemic: ").append(stats.get("epistemic")).append("
other higher-order: ").append(stats.get("otherHOL")).append("

\n"); return show.toString(); } @@ -353,8 +354,8 @@ public static String showStatistics(KB kb) { public static String showLanguageStats(KB kb, String lang) { StringBuilder show = new StringBuilder(); - show.append("termFormats: " + KButilities.getCountTermFormats(kb, lang) + "\n"); - show.append("unique terms in termFormats: " + KButilities.getCountUniqueTermFormats(kb, lang) + "\n"); + show.append("termFormats: ").append(KButilities.getCountTermFormats(kb, lang)).append("\n"); + show.append("unique terms in termFormats: ").append(KButilities.getCountUniqueTermFormats(kb, lang)).append("\n"); show.append("

\n"); return show.toString(); } @@ -368,7 +369,7 @@ public static String showMap(KB kb, String term) { ArrayList lons = kb.askWithRestriction(0, "longitude", 1, term); String result = ""; int zoom = 12; - if (lats != null && lats.size() > 0 && lons != null && lons.size() > 0) { + if (lats != null && !lats.isEmpty() && lons != null && !lons.isEmpty()) { Formula f = lats.get(0); String lat = f.getStringArgument(2); f = lons.get(0); @@ -402,7 +403,7 @@ public static String showNumberPictures(KB kb, String term, int count) { StringBuilder show = new StringBuilder(); ArrayList pictures = kb.askWithRestriction(0, "externalImage", 1, term); // Handle picture display - if (pictures != null && pictures.size() > 0) { + if (pictures != null && !pictures.isEmpty()) { show.append("
"); int numPictures = pictures.size(); boolean more = false; @@ -410,26 +411,29 @@ public static String showNumberPictures(KB kb, String term, int count) { numPictures = count; more = true; } + + Formula f; + String url; + String imageFile, domain; for (int i = 0; i < numPictures; i++) { - Formula f = pictures.get(i); - String url = f.getStringArgument(2); + f = pictures.get(i); + url = f.getStringArgument(2); if (url.startsWith("\"https://upload.wikimedia.org")) { - String imageFile = url.substring(url.lastIndexOf("/") + 1, url.length() - 1); + imageFile = url.substring(url.lastIndexOf("/") + 1, url.length() - 1); if (imageFile.matches("\\d+px-.*")) imageFile = imageFile.substring(imageFile.indexOf("px-") + 3); - String domain = "https://simple.wikipedia.org/"; - if (url.indexOf("/en/") > -1) + domain = "https://simple.wikipedia.org/"; + if (url.contains("/en/")) domain = "https://en.wikipedia.org/"; - if (url.indexOf("/commons/") > -1) + if (url.contains("/commons/")) domain = "https://commons.wikimedia.org/"; - show.append("\n"); + show.append("\n"); } else - show.append("\n"); + show.append("\n"); } if (more) - show.append("more pictures..."); + show.append("more pictures..."); } return show.toString(); } @@ -454,28 +458,29 @@ public static String showNeighborTerms(KB kb, String nonRelTerm, String relTerm) String uppercaseTerm = Character.toUpperCase(relTerm.charAt(0)) + relTerm.substring(1); show.append(""); @@ -491,7 +496,7 @@ public static String showNeighborTerms(KB kb, String nonRelTerm, String relTerm) */ public static ArrayList getAllRelTerms(KB kb, ArrayList matchesList) { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); for (int i = 0; i < matchesList.size(); i++) if (kb.kbCache.relations.contains(matchesList.get(i))) result.add(matchesList.get(i)); @@ -502,7 +507,7 @@ public static ArrayList getAllRelTerms(KB kb, ArrayList matchesL */ public static ArrayList getAllNonRelTerms(KB kb, ArrayList matchesList) { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); for (int i = 0; i < matchesList.size(); i++) if (!kb.kbCache.relations.contains(matchesList.get(i))) result.add(matchesList.get(i)); @@ -530,34 +535,35 @@ public static String showREMatches(KB kb, String relREmatch, String nonRelREmatc } show.append("
"); show.append(""); - show.append(""); - show.append("\n

"); + show.append(""); + show.append("\n

"); + + String relation, relationName, nonRelation, nonRelationName; for (int i = 0; i < 30; i++) { - String relation = (String) relations.get(i); - String relationName = DocGen.getInstance(kb.name).showTermName(kb, relation, language); - String nonRelation = (String) nonRelations.get(i); - String nonRelationName = DocGen.getInstance(kb.name).showTermName(kb, nonRelation, language); + relation = (String) relations.get(i); + relationName = DocGen.getInstance(kb.name).showTermName(kb, relation, language); + nonRelation = (String) nonRelations.get(i); + nonRelationName = DocGen.getInstance(kb.name).showTermName(kb, nonRelation, language); if (!relation.isEmpty() || !nonRelation.isEmpty()) { if (i == 0) - show.append("\n"); + show.append("\n"); show.append("\n"); - show.append(" "); - show.append(" "); + show.append(" "); + show.append(" "); show.append("\n"); if (i == 14) - show.append("" + - ""); + show.append(""); if (i == 29) - show.append("\n"); + show.append("\n"); } } show.append("
" + relTerm + " " + nonRelTerm + "
").append(relTerm).append(" ").append(nonRelTerm).append("
previous " + 25 + "" + "
previous ").append(25).append("
" + nonRelation + " (" + nonRelationName + ")" + "" + relation + " (" + relationName + ")" + "").append(nonRelation).append(" (").append(nonRelationName).append(")").append(relation).append(" (").append(relationName).append(")
" + uppercaseTerm + " " + lowcaseTerm + "
").append(uppercaseTerm).append(" ").append(lowcaseTerm).append("
next " + 25 + "" + "
next ").append(25).append("
"); @@ -580,21 +586,23 @@ public static String termMappingsList(String terms, String kbHref) { StringBuilder result = new StringBuilder(); String[] sumoList = terms.split("\\s+"); result.append("

  • \tSUMO Mappings: "); - for (int j = 0; j < sumoList.length; j++) { - String sumoEquivalent = sumoList[j]; + Pattern p; + Matcher m; + char symbol; + for (String sumoEquivalent : sumoList) { sumoEquivalent = sumoEquivalent.trim(); - Pattern p = Pattern.compile("\\&\\%"); - Matcher m = p.matcher(sumoEquivalent); + p = Pattern.compile("\\&\\%"); + m = p.matcher(sumoEquivalent); sumoEquivalent = m.replaceFirst(""); p = Pattern.compile("[\\=\\|\\+\\@]"); m = p.matcher(sumoEquivalent); - char symbol = sumoEquivalent.charAt(sumoEquivalent.length() - 1); + symbol = sumoEquivalent.charAt(sumoEquivalent.length() - 1); sumoEquivalent = m.replaceFirst(""); result.append(kbHref); - result.append(sumoEquivalent + "\">" + sumoEquivalent + " "); + result.append(sumoEquivalent).append("\">").append(sumoEquivalent).append(" "); String mapping = WordNetUtilities.mappingCharToName(symbol); - result.append(" (" + mapping + " mapping) "); + result.append(" (").append(mapping).append(" mapping) "); } result.append("\n\n
"); return result.toString(); @@ -609,7 +617,7 @@ public static String synsetList(ArrayList synsets, String kbHref) { for (int i = 0; i < synsets.size(); i++) { String synset = (String) synsets.get(i); if (Character.isDigit(synset.charAt(0))) - show.append("" + synset + ""); + show.append("").append(synset).append(""); else show.append(synset); if (i < synsets.size() - 1) @@ -624,7 +632,7 @@ public static String synsetList(ArrayList synsets, String kbHref) { * Create the HTML for a section of the Sigma term browser page. * Needs a
"); show.append(""); - show.append(""); + show.append(""); show.append("\n

"); + int matchIndex, listLength, finalIndex; for (String t : largerList) { if (t.equals((largerList == relTermsList ? relREmatch : nonRelREmatch))) { //keeps track of which term is at the top - int matchIndex = largerList.indexOf(t); //matchIndex is the index of an REmatch in the larger list - int listLength = largerList.size(); //listLength is the the larger count of either relMatches or nonRelMatches - int finalIndex = (listLength > (matchIndex + 29) ? (matchIndex + 30) : listLength); //finalIndex is 1 + the index of the final match that will be displayed + matchIndex = largerList.indexOf(t); //matchIndex is the index of an REmatch in the larger list + listLength = largerList.size(); //listLength is the the larger count of either relMatches or nonRelMatches + finalIndex = (listLength > (matchIndex + 29) ? (matchIndex + 30) : listLength); //finalIndex is 1 + the index of the final match that will be displayed //If there are at least 30 more matches after REmatch, then finalIndex=matchIndex+30, otherwise finalIndex = listLength for (int i = matchIndex; i < finalIndex; i++) { if (i == matchIndex && i != 0) //if there are other matches before REmatch, previous 30 should be linked at the top of the page - show.append("\n"); + show.append("\n"); show.append("\n"); - if (nonRelTermsList.get(i) == "") + if ("".equals(nonRelTermsList.get(i))) show.append(" "); else { - show.append(" "); + show.append(" "); } - if (relTermsList.get(i) == "") + if ("".equals(relTermsList.get(i))) show.append(" "); else { - show.append(" "); + show.append(" "); } show.append("\n"); if (i == (finalIndex - 1) && listLength > (matchIndex + 30)) { int nextCount = (listLength > finalIndex + 29) ? 30 : (listLength - finalIndex + 1); - show.append("\n"); + show.append("\n"); } } show.append("
" + term + "
").append(term).append("
previous " + 30 + "" + "
previous ").append(30).append("
" + " " + "" + nonRelTermsList.get(i) + "" + "").append(nonRelTermsList.get(i)).append(" " + " " + "" + relTermsList.get(i) + "" + "").append(relTermsList.get(i)).append("
next " + nextCount + "" + "
next ").append(nextCount).append("
...
enclosure to format HTML properly. */ - public static String formatFormulaList(ArrayList forms, String header, KB kb, + public static String formatFormulaList(List forms, String header, KB kb, String language, String flang, int start, int localLimit, String limitString) { HashSet printedForms = new HashSet<>(); @@ -635,14 +643,18 @@ public static String formatFormulaList(ArrayList forms, String header, boolean isArabic = (language.matches(".*(?i)arabic.*") || language.equalsIgnoreCase("ar")); if (forms.size() < localLimit || localLimit == 0) localLimit = forms.size(); + + String strForm, arg0, formattedFormula, sourceFilename, jeditcmd, pph = null; + Formula f; + File srcfile; for (int i = start; i < localLimit; i++) { //System.out.println("formatFormulaList(): " + forms.get(i).getClass().getName()); - String strForm = forms.get(i).getFormula(); + strForm = forms.get(i).getFormula(); if (printedForms.contains(strForm)) continue; printedForms.add(strForm); //System.out.println("INFO in HTMLformatter.formatFormulaList(): formula: " + strForm); - Formula f = (Formula) kb.formulaMap.get(strForm); + f = (Formula) kb.formulaMap.get(strForm); if (f == null) { System.out.println("Error in HTMLformatter.formatFormulaList(): null formula object for " + strForm); @@ -651,9 +663,8 @@ public static String formatFormulaList(ArrayList forms, String header, //System.out.println("INFO in HTMLformatter.formatFormulaList(): structured formula: " + f); if (KBmanager.getMgr().getPref("showcached").equalsIgnoreCase("yes") || !KButilities.isCacheFile(f.sourceFile)) { - String arg0 = f.getStringArgument(0); + arg0 = f.getStringArgument(0); show.append(""); - String formattedFormula = null; if (flang.equals("TPTP") || flang.equals("traditionalLogic")) formattedFormula = TPTPutil.htmlTPTPFormat(f, kbHref, traditionalLogic) + "\n"; else @@ -662,22 +673,20 @@ public static String formatFormulaList(ArrayList forms, String header, show.append(kb.formatDocumentation(kbHref, formattedFormula, language)); else show.append(formattedFormula); - File srcfile = new File(f.sourceFile); - String sourceFilename = srcfile.getName(); + srcfile = new File(f.sourceFile); + sourceFilename = srcfile.getName(); if (StringUtil.isNonEmptyString(sourceFilename)) { - String jeditcmd = KBmanager.getMgr().getPref("jedit"); + jeditcmd = KBmanager.getMgr().getPref("jedit"); if (!StringUtil.emptyString(jeditcmd)) { - show.append(""); + show.append(""); } show.append(sourceFilename); - show.append(" " + f.startLine + "-" + f.endLine); + show.append(" ").append(f.startLine).append("-").append(f.endLine); if (!StringUtil.emptyString(jeditcmd)) show.append(""); } show.append(""); show.append("\n"); - String pph = null; if (!Formula.DOC_PREDICATES.contains(arg0)) pph = NLGUtils.htmlParaphrase(kbHref, f.getFormula(), kb.getFormatMap(language), @@ -689,7 +698,7 @@ else if (isArabic) pph = ("" + pph + ""); else pph = NLGUtils.upcaseFirstVisibleChar(pph, true, language); - show.append(pph + "\n"); + show.append(pph).append("\n"); } } show.append(limitString); @@ -728,7 +737,7 @@ public static void launchEditor(String file, int line) { Process _jedit = _builder.start(); } catch (IOException ioe) { - System.out.println("launchEditor(): " + ioe.getMessage()); + System.err.println("launchEditor(): " + ioe.getMessage()); ioe.printStackTrace(); } } @@ -836,7 +845,7 @@ public static String createNumberedMenu(String menuName, String selectedOption, StringBuilder result = new StringBuilder(); String menuNameProcessed = encodeForURL(menuName); - result.append("\n "); + String menuItemProcessed; for (String menuItem : menuOptions) { result.append("

\n"); } - if (tpp.bindingMap != null && tpp.bindingMap.keySet().size() > 0) { // if an answer predicate appears in the proof, use it + + String term, kbHref; + if (tpp.bindingMap != null && !tpp.bindingMap.keySet().isEmpty()) { // if an answer predicate appears in the proof, use it for (String s : tpp.bindingMap.keySet()) { html.append("Answer " + "\n"); - html.append(s + " = "); - String term = TPTP2SUMO.transformTerm(tpp.bindingMap.get(s)); - String kbHref = HTMLformatter.createKBHref(kbName, language); - html.append("" + term + ""); + html.append(s).append(" = "); + term = TPTP2SUMO.transformTerm(tpp.bindingMap.get(s)); + kbHref = HTMLformatter.createKBHref(kbName, language); + html.append("").append(term).append(""); html.append("
\n"); } } @@ -1009,15 +1023,17 @@ public static String formatTPTP3ProofResult(TPTP3ProofProcessor tpp, String stmt html.append("Answer " + "\n"); html.append(i + 1); html.append(". "); - String term = TPTP2SUMO.transformTerm(tpp.bindings.get(i)); - String kbHref = HTMLformatter.createKBHref(kbName, language); - html.append("" + term + ""); + term = TPTP2SUMO.transformTerm(tpp.bindings.get(i)); + kbHref = HTMLformatter.createKBHref(kbName, language); + html.append("").append(term).append(""); html.append("
\n"); } } html.append("

" + "\n"); + + TPTPFormula ps; for (int l = 0; l < tpp.proof.size(); l++) { - TPTPFormula ps = tpp.proof.get(l); + ps = tpp.proof.get(l); //System.out.println("HTMLformatter.formatTPTP3ProofResult(): role: " + ps.role); if (ps.role.equals("type")) continue; // ignore type definitions in tff proof output @@ -1026,9 +1042,9 @@ public static String formatTPTP3ProofResult(TPTP3ProofProcessor tpp, String stmt else html.append("" + "\n"); html.append("\n"); - html.append(HTMLformatter.proofTableFormat(stmt, tpp.proof.get(l), kbName, language) + "\n"); + html.append(HTMLformatter.proofTableFormat(stmt, tpp.proof.get(l), kbName, language)).append("\n"); html.append("\n\n"); } html.append("
\n"); - html.append(ps.id + "."); + html.append(ps.id).append("."); html.append("
\n"); @@ -1053,75 +1069,85 @@ public static String formatConsistencyCheck(String msg, String ccheckResult, ArrayList elements = res.elements; ArrayList subElements = ((BasicXMLelement) elements.get(0)).subelements; + BasicXMLelement item, entryItem; + ArrayList entries, entry; + String pagelink, query = null, type = null, sourceFile = null, processedQ, proof = null; for (int i = 0; i < subElements.size(); i++) { - BasicXMLelement item = (BasicXMLelement) subElements.get(i); + item = (BasicXMLelement) subElements.get(i); if (item.tagname.equals("kb")) kbName = item.contents; else if (item.tagname.equals("entries")) { - ArrayList entries = ((BasicXMLelement) subElements.get(i)).subelements; + entries = ((BasicXMLelement) subElements.get(i)).subelements; html.append("
Consistency Check Results:
"); if (page == 0) { - String pagelink = "CCheck.jsp?kb=" + kbName + "&lang=" + language + "&page="; + pagelink = "CCheck.jsp?kb=" + kbName + "&lang=" + language + "&page="; html.append("
"); html.append(""); html.append(""); for (int j = 0; j < entries.size(); j++) { - ArrayList entry = ((BasicXMLelement) entries.get(j)).subelements; - String query = null; - String type = null; - String sourceFile = null; + entry = ((BasicXMLelement) entries.get(j)).subelements; for (int k = 0; k < entry.size(); k++) { - BasicXMLelement entryItem = (BasicXMLelement) entry.get(k); - if (entryItem.tagname.equals("query")) - query = entryItem.contents; - else if (entryItem.tagname.equals("type")) - type = entryItem.contents; - else if (entryItem.tagname.equals("sourceFile")) - sourceFile = entryItem.contents; + entryItem = (BasicXMLelement) entry.get(k); + switch (entryItem.tagname) { + case "query": + query = entryItem.contents; + break; + case "type": + type = entryItem.contents; + break; + case "sourceFile": + sourceFile = entryItem.contents; + break; + default: + break; + } } int pageNum = j + 1; - html.append(""); + html.append(""); } html.append("
QueryResult TypeSource File
" + query + "" + type + "" + sourceFile + "
").append(query).append("").append(type).append("").append(sourceFile).append("
"); - if (entries.size() > 0) - html.append("

Individual Results >>

"); + if (!entries.isEmpty()) + html.append("

Individual Results >>

"); } else if (page >= 1 && page <= entries.size()) { int j = page - 1; - ArrayList entry = ((BasicXMLelement) entries.get(j)).subelements; - String query = null; - String type = null; - String processedQ = null; - String proof = null; - String sourceFile = null; + entry = ((BasicXMLelement) entries.get(j)).subelements; for (int k = 0; k < entry.size(); k++) { - BasicXMLelement entryItem = (BasicXMLelement) entry.get(k); - if (entryItem.tagname.equals("query")) - query = entryItem.contents; - else if (entryItem.tagname.equals("type")) - type = entryItem.contents; - else if (entryItem.tagname.equals("processedStatement")) - processedQ = entryItem.contents; - else if (entryItem.tagname.equals("sourceFile")) - sourceFile = entryItem.contents; - else if (entryItem.tagname.equals("proof")) { - if (type.indexOf("Error") == -1) - //if (entryItem.attributes.get("src") != null && entryItem.attributes.get("src").equals("EProver")) - // TODO update to TPTP3 ANTLR proof = formatTPTP3ProofResult(entryItem.subelements, query, kbName, language, 0); - ; - else { - proof = entryItem.contents; - proof = proof.replaceAll("%3C", "<"); - proof = proof.replaceAll("%3E", ">"); - } - // else proof = entryItem.contents; + entryItem = (BasicXMLelement) entry.get(k); + switch (entryItem.tagname) { + case "query": + query = entryItem.contents; + break; + case "type": + type = entryItem.contents; + break; + case "processedStatement": + processedQ = entryItem.contents; + break; + case "sourceFile": + sourceFile = entryItem.contents; + break; + case "proof": + if (!type.contains("Error")) + //if (entryItem.attributes.get("src") != null && entryItem.attributes.get("src").equals("EProver")) + // TODO update to TPTP3 ANTLR proof = formatTPTP3ProofResult(entryItem.subelements, query, kbName, language, 0); + ; + else { + proof = entryItem.contents; + proof = proof.replaceAll("%3C", "<"); + proof = proof.replaceAll("%3E", ">"); + } + // else proof = entryItem.contents; + break; + default: + break; } } - html.append("
Query: " + query + "
"); - html.append("Type: " + type + "
"); - html.append("Source File: " + sourceFile + "

"); + html.append("
Query: ").append(query).append("
"); + html.append("Type: ").append(type).append("
"); + html.append("Source File: ").append(sourceFile).append("

"); html.append(proof); html.append(lineHtml); @@ -1130,13 +1156,13 @@ else if (entryItem.tagname.equals("proof")) { int before = page - 1; int after = page + 1; if (page == 1) - html.append("<< Summary Result"); + html.append("<< Summary Result"); else if (page > 1) { - html.append("<< Prev"); - html.append("<< Summary Results >>"); + html.append("<< Prev"); + html.append("<< Summary Results >>"); } if (after <= entries.size() && page >= 1) - html.append("Next >>"); + html.append("Next >>"); html.append(""); } } @@ -1144,7 +1170,7 @@ else if (page > 1) { } } catch (Exception ex) { - System.out.println(ex.getMessage()); + System.err.println(ex.getMessage()); } } return html.toString(); @@ -1155,9 +1181,9 @@ else if (page > 1) { public static void showHelp() { System.out.println("HTMLformatter class"); - System.out.println(" options (with a leading '-'):"); - System.out.println(" h - show this help screen"); - System.out.println(" t - run tests"); + System.out.println(" options:"); + System.out.println(" -h - show this help screen"); + System.out.println(" -t - run tests"); } /** ************************************************************** @@ -1175,10 +1201,10 @@ public static void main(String[] args) throws IOException { KB kb = KBmanager.getMgr().getKB(kbName); if (args != null) System.out.println("KB.main(): args[0]: " + args[0]); - if (args != null && args.length > 0 && args[0].contains("t")) { + if (args != null && args.length > 0 && args[0].equals("-t")) { System.out.println("INFO in HTMLformatter.main()"); System.out.println("INFO in HTMLformatter.main(): " + showStatistics(kb)); - ArrayList forms = KButilities.termIntersection(kb, "ShapeChange", "ShapeAttribute"); + List forms = KButilities.termIntersection(kb, "ShapeChange", "ShapeAttribute"); /* should get from Merge.kif 15034-15041 * (=> (and From a5088d198bcd1e092e2b7eca4a44abcbcbd79270 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 21:25:46 -0700 Subject: [PATCH 24/28] [Terry N.] Fix for Issue #134 --- web/jsp/Graph.jsp | 67 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/web/jsp/Graph.jsp b/web/jsp/Graph.jsp index ffacdc64..fcdb71b9 100644 --- a/web/jsp/Graph.jsp +++ b/web/jsp/Graph.jsp @@ -43,8 +43,8 @@ function setWidth(id) { // If the request parameter can appear more than once in the query string, get all values String[] values = request.getParameterValues("columns"); //if (values != null) { - // for (int i = 0; i < values.length; i++) - // System.out.println(" value[" + i + "] == " + values[i]); + // for (int i = 0; i < values.length; i++) + // System.out.println(" value[" + i + "] == " + values[i]); //} Graph g = new Graph(); @@ -70,12 +70,12 @@ function setWidth(id) { String up = request.getParameter("up"); if (up == null) up = "1"; int upint = Integer.parseInt(up); - if (upint > 10) + if (upint > 10) upint = 1; String down = request.getParameter("down"); if (down == null) down = "1"; int downint = Integer.parseInt(down); - if (downint > 10) + if (downint > 10) downint = 1; int limitInt = 100; String limit = request.getParameter("limit"); @@ -83,7 +83,7 @@ function setWidth(id) { limitInt = Integer.parseInt(limit); if (limitInt > 100 || limitInt < 10) limitInt = 100; - } + } catch (NumberFormatException nfe) { limit = ""; } @@ -97,7 +97,7 @@ function setWidth(id) { for (int i = 0; i < items.length; i++) g.columnList.put(items[i],"yes"); } - + %>
@@ -115,7 +115,7 @@ function setWidth(id) { <% /* Present the text layout (graph layout is in the else) */ if (view.equals("text")) { - LinkedHashSet result = null; + Set result = null; boolean instBool = false; if (!StringUtil.emptyString(inst) && inst.equals("inst")) instBool = true; @@ -124,11 +124,11 @@ function setWidth(id) { else result = g.createGraph(kb,term,relation,Integer.parseInt(up), Integer.parseInt(down),limitInt,instBool,language); - out.println("\n"); + out.println("

\n"); for (String element : result) { out.println(element); } - out.println("

\n"); + out.println("

\n"); } else { // it is a graph int width = 500; @@ -139,30 +139,31 @@ function setWidth(id) { if (!StringUtil.emptyString(scrWidth)) width = Integer.parseInt(scrWidth); String edges = ""; - String fname = null; - boolean graphAvailable = false; - - if (term != null && relation != null && kb != null && role.equalsIgnoreCase("admin")) { - fname = "GRAPH_" + kbName + "-" + term + "-" + relation; - try { - if (!StringUtil.emptyString(all)) - relation = "all"; - System.out.println("Graph.jsp: creating graph with limitInt=" + limitInt + - " and fileRestrict=" + fileRestrict); - graphAvailable = g.createDotGraph(kb,term,relation,Integer.parseInt(up), - Integer.parseInt(down),limitInt,fname,fileRestrict); - } - catch (Exception ex) { - graphAvailable = false; - } - } - if (graphAvailable) { - out.println("

"); - } - else { - out.println("

Error producing graph.

"); - out.println(HTMLformatter.formatErrorsWarnings(g.errors,kb)); - } + String fname = null; + boolean graphAvailable = false; + + if (term != null && relation != null && kb != null && role.equalsIgnoreCase("admin")) { + fname = "GRAPH_" + kbName + "-" + term + "-" + relation; + try { + if (!StringUtil.emptyString(all)) + relation = "all"; + System.out.println("Graph.jsp: creating graph with limitInt=" + limitInt + + " and fileRestrict=" + fileRestrict); + graphAvailable = g.createDotGraph(kb,term,relation,Integer.parseInt(up), + Integer.parseInt(down),limitInt,fname,fileRestrict); + Thread.sleep(500); // give some time for the image to write to disc + } + catch (Exception ex) { + graphAvailable = false; + } + } + if (graphAvailable) { + out.println(""); + } + else { + out.println("

Error producing graph.

"); + out.println(HTMLformatter.formatErrorsWarnings(g.errors,kb)); + } } %> From b79c8e9207e45f9c4d518a0ee9929afccfcc4e6a Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 21:26:01 -0700 Subject: [PATCH 25/28] [Terry N.] Fix for Issue #134 --- src/java/com/articulate/sigma/Graph.java | 343 ++++++++++++----------- 1 file changed, 175 insertions(+), 168 deletions(-) diff --git a/src/java/com/articulate/sigma/Graph.java b/src/java/com/articulate/sigma/Graph.java index 76eaa79e..2e5c54ae 100644 --- a/src/java/com/articulate/sigma/Graph.java +++ b/src/java/com/articulate/sigma/Graph.java @@ -4,49 +4,46 @@ copyright Teknowledge (c) 2003 and reused under the terms of the GNU license. This software is released under the GNU Public License . Users of this code also consent, by use of this code, to credit Articulate Software -and Teknowledge in any writings, briefings, publications, presentations, or -other representations of any software which incorporates, builds on, or uses this +and Teknowledge in any writings, briefings, publications, presentations, or +other representations of any software which incorporates, builds on, or uses this code. Please cite the following article in any publication with references: -Pease, A., (2003). The Sigma Ontology Development Environment, +Pease, A., (2003). The Sigma Ontology Development Environment, in Working Notes of the IJCAI-2003 Workshop on Ontology and Distributed Systems, August 9, Acapulco, Mexico. */ -import java.awt.image.RenderedImage; -import java.io.BufferedInputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.lang.ProcessBuilder.Redirect; import java.util.*; -import javax.imageio.ImageIO; - import com.articulate.sigma.utils.FileUtil; import com.articulate.sigma.utils.StringUtil; /** Handle operations for creating a graphical representation of partial * ordering relations. Supports Graph.jsp. */ public class Graph { - - // a limit counter to prevent pathologically large graphs - private int graphsize = 0; - - // A map of the fields to display in the graph in addition to the - // indented term name with option names as keys and "yes", "no" as values. - public TreeMap columnList = new TreeMap(); + + // a limit counter to prevent pathologically large graphs + private int graphsize = 0; + + // A map of the fields to display in the graph in addition to the + // indented term name with option names as keys and "yes", "no" as values. + public Map columnList = new TreeMap<>(); public static String indent = "    "; - public TreeSet errors = new TreeSet<>(); + public Set errors = new TreeSet<>(); public static boolean debug = false; /** ************************************************************* */ public Graph() { - + columnList.put("documentation","yes"); columnList.put("direct-children","yes"); columnList.put("graph","yes"); @@ -59,20 +56,21 @@ public Graph() { private String generateChildrenColumn(KB kb, String term) { // probably should find all instances of PartialOrderingRelation - ArrayList relations = new ArrayList(); + List relations = new ArrayList<>(); relations.add("instance"); relations.add("subclass"); relations.add("subrelation"); relations.add("subAttribute"); int count = 0; + List children; for (int i = 0; i < relations.size(); i++) { - ArrayList children = kb.askWithRestriction(0,relations.get(i),2,term); - if (children != null) + children = kb.askWithRestriction(0,relations.get(i),2,term); + if (children != null) count = count + children.size(); } if (count > 0) - return Integer.toString(count); + return Integer.toString(count); else return "."; } @@ -89,18 +87,19 @@ private String generateGraphLink(KB kb, String term, String href) { } /** ************************************************************* - * @return an HTML-formatted String consisting of the first 100 + * @return an HTML-formatted String consisting of the first 100 * characters of the documentation string for the term parameter */ private String generateDocumentationColumn(KB kb, String term, String href, String language) { - String docString = ""; - ArrayList docStmts = kb.askWithTwoRestrictions(0,"documentation",1,term,2,language); - if (docStmts.size() > 0) { - Formula doc = (Formula) docStmts.get(0); + String docString; + List docStmts = kb.askWithTwoRestrictions(0,"documentation",1,term,2,language); + Formula doc; + if (!docStmts.isEmpty()) { + doc = (Formula) docStmts.get(0); docString = doc.getStringArgument(3); if (!DB.emptyString(docString)) { - if (docString.length() > 100) + if (docString.length() > 100) docString = docString.substring(1,100) + "..."; else docString = docString.substring(1,docString.length()-1); @@ -117,11 +116,10 @@ private String generateDocumentationColumn(KB kb, String term, String href, Stri public int columnCount() { int counter = 0; - Iterator it = columnList.keySet().iterator(); - while (it.hasNext()) { - String col = it.next(); - String val = columnList.get(col); - if (val.equals("yes")) + String val; + for (String col : columnList.keySet()) { + val = columnList.get(col); + if (val.equals("yes")) counter++; } return counter; @@ -133,14 +131,13 @@ public int columnCount() { */ private String createColumnHeader() { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); result.append(""); // a blank column for the indented terms - Iterator it = columnList.keySet().iterator(); - while (it.hasNext()) { - String col = it.next(); - String val = columnList.get(col); - if (val.equals("yes")) - result.append("" + col + ""); + String val; + for (String col : columnList.keySet()) { + val = columnList.get(col); + if (val.equals("yes")) + result.append("").append(col).append(""); } result.append(""); return result.toString(); @@ -158,21 +155,20 @@ private String createGraphEntry(KB kb, String prefix, String kbHref, String term ital = ""; italEnd = ""; } - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); result.append(""); String formattedTerm = "" + term + ""; - result.append("" + prefix + ital + formattedTerm + italEnd + ""); - Iterator it = columnList.keySet().iterator(); - while (it.hasNext()) { - String col = it.next(); - String val = columnList.get(col); + result.append("").append(prefix).append(ital).append(formattedTerm).append(italEnd).append(""); + String val; + for (String col : columnList.keySet()) { + val = columnList.get(col); if (val.equals("yes")) { - if (col.equals("documentation")) - result.append("" + generateDocumentationColumn(kb,term,kbHref,language) + ""); - if (col.equals("direct-children")) - result.append("" + generateChildrenColumn(kb,term) + ""); - if (col.equals("graph")) - result.append("" + generateGraphLink(kb,term,kbHref) + ""); + if (col.equals("documentation")) + result.append("").append(generateDocumentationColumn(kb,term,kbHref,language)).append(""); + if (col.equals("direct-children")) + result.append("").append(generateChildrenColumn(kb,term)).append(""); + if (col.equals("graph")) + result.append("").append(generateGraphLink(kb,term,kbHref)).append(""); } } result.append(""); @@ -182,22 +178,23 @@ private String createGraphEntry(KB kb, String prefix, String kbHref, String term /** ************************************************************* * Create a graph of a bounded size by incrementing the number of * levels above and below until the limit is reached or there are - * no more levels in the knowledge base from the given term and + * no more levels in the knowledge base from the given term and * relation. creatGraphBody() does most of the work. */ - public LinkedHashSet createBoundedSizeGraph(KB kb, String term, String relation, + public Set createBoundedSizeGraph(KB kb, String term, String relation, int size, boolean instances, String language) { - LinkedHashSet result = new LinkedHashSet(); - LinkedHashSet oldresult = new LinkedHashSet(); + Set result = new LinkedHashSet<>(); + Set oldresult = new LinkedHashSet<>(); int above = 1; int below = 1; int oldlimit = -1; + Set checkAbove, checkBelow; while ((result.size() < size) && (result.size() != oldlimit)) { oldlimit = result.size(); oldresult = result; - HashSet checkAbove = new HashSet(); - HashSet checkBelow = new HashSet(); + checkAbove = new HashSet<>(); + checkBelow = new HashSet<>(); result = createGraphBody(kb,checkAbove,term,relation,above,0,above,true,instances,language); result.addAll(createGraphBody(kb,checkBelow,term,relation,0,below,above,false,instances,language)); above++; @@ -219,13 +216,13 @@ public LinkedHashSet createBoundedSizeGraph(KB kb, String term, String r * @param below the number of levels below the given term in the graph * @param instances whether to display instances below subclass relations */ - public LinkedHashSet createGraph(KB kb, String term, String relation, + public Set createGraph(KB kb, String term, String relation, int above, int below, int termLimit, boolean instances, String language) { graphsize = 0; - LinkedHashSet result = new LinkedHashSet(); // a list of Strings - HashSet checkAbove = new HashSet(); - HashSet checkBelow = new HashSet(); + Set result = new LinkedHashSet<>(); // a list of Strings + Set checkAbove = new HashSet<>(); + Set checkBelow = new HashSet<>(); result.add(createColumnHeader()); result.addAll(createGraphBody(kb,checkAbove,term,relation,above,0,above,true,instances,language)); result.addAll(createGraphBody(kb,checkBelow,term,relation,0,below,above,false,instances,language)); @@ -240,29 +237,32 @@ public LinkedHashSet createGraph(KB kb, String term, String relation, * @param check collects all the terms added to the graph so * far, which is used to prevent cycles */ - private LinkedHashSet createGraphBody(KB kb, Set check, String term, String relation, + private Set createGraphBody(KB kb, Set check, String term, String relation, int above, int below, int level, boolean show, boolean instances, String language) { - LinkedHashSet result = new LinkedHashSet(); - int graphMax = Integer.valueOf(KBmanager.getMgr().getPref("adminBrowserLimit")).intValue(); + Set result = new LinkedHashSet<>(); + int graphMax = Integer.parseInt(KBmanager.getMgr().getPref("adminBrowserLimit")); if (!check.contains(term) && graphsize < graphMax) { if (above > 0) { - ArrayList stmtAbove = new ArrayList(); + List stmtAbove; if (!DB.emptyString(relation) && relation.equals("all")) stmtAbove = kb.ask("arg",1,term); - else + else stmtAbove = kb.askWithRestriction(0,relation,1,term); + + Formula f; + String newTerm; for (int i = 0; i < stmtAbove.size(); i++) { - Formula f = stmtAbove.get(i); - String newTerm = f.getStringArgument(2); + f = stmtAbove.get(i); + newTerm = f.getStringArgument(2); if (!newTerm.equals(term) && !KButilities.isCacheFile(f.sourceFile)) result.addAll(createGraphBody(kb,check,newTerm,relation,above-1,0,level-1,true,instances,language)); check.add(term); } } - StringBuffer prefix = new StringBuffer(); + StringBuilder prefix = new StringBuilder(); for (int i = 0; i < level; i++) prefix = prefix.append(indent); @@ -280,7 +280,7 @@ private LinkedHashSet createGraphBody(KB kb, Set check, String t String kbHref = https + "://" + hostname + ":" + port + "/sigma/Browse.jsp?lang=" + kb.language + "&kb=" + kb.name; if (show) { graphsize++; - if (graphsize < 100) + if (graphsize < 100) result.add(createGraphEntry(kb,prefix.toString(),kbHref,term,language)); else { String endStr = "Truncating graph at 100 terms

\n"; @@ -290,19 +290,21 @@ private LinkedHashSet createGraphBody(KB kb, Set check, String t } } if (below > 0) { - ArrayList stmtBelow = kb.askWithRestriction(0,relation,2,term); + List stmtBelow = kb.askWithRestriction(0,relation,2,term); + Formula f; + String newTerm; for (int i = 0; i < stmtBelow.size(); i++) { - Formula f = stmtBelow.get(i); - String newTerm = f.getStringArgument(1); + f = stmtBelow.get(i); + newTerm = f.getStringArgument(1); if (!newTerm.equals(term) && !KButilities.isCacheFile(f.sourceFile)) result.addAll(createGraphBody(kb,check,newTerm,relation,0,below-1,level+1,true,instances,language)); check.add(term); } - if (instances && (stmtBelow == null || stmtBelow.size() == 0) && relation.equals("subclass")) { + if (instances && stmtBelow.isEmpty() && relation.equals("subclass")) { stmtBelow = kb.askWithRestriction(0,"instance",2,term); for (int i = 0; i < stmtBelow.size(); i++) { - Formula f = stmtBelow.get(i); - String newTerm = f.getStringArgument(1); + f = stmtBelow.get(i); + newTerm = f.getStringArgument(1); if (!newTerm.equals(term) && !KButilities.isCacheFile(f.sourceFile)) result.addAll(createGraphBody(kb,check,newTerm,relation,0,below-1,level+1,true,instances,language)); check.add(term); @@ -328,24 +330,21 @@ private LinkedHashSet createGraphBody(KB kb, Set check, String t public boolean createDotGraph(KB kb, String term, String relation, int above, int below, int limitInt, String fname, String fileRestrict) throws IOException { - FileWriter fw = null; - PrintWriter pw = null; String sep = File.separator; String dir = System.getenv("CATALINA_HOME") + sep + "webapps" + sep + "sigma" + sep + "graph"; String filename = System.getenv("CATALINA_HOME") + sep + "webapps" + sep + "sigma" + sep + "graph" + sep + fname; String graphVizDir = KBmanager.getMgr().getPref("graphVizDir"); - try { - File dirfile = new File(dir); - if (!dirfile.exists()) - dirfile.mkdir(); - fw = new FileWriter(filename + ".dot"); + File dirfile = new File(dir); + if (!dirfile.exists()) + dirfile.mkdir(); + try (FileWriter fw = new FileWriter(filename + ".dot"); + PrintWriter pw = new PrintWriter(fw)) { if (debug) System.out.println("Graph.createGraphBody(): creating file at " + filename); - pw = new PrintWriter(fw); - HashSet result = new HashSet(); - HashSet start = new HashSet(); - HashSet checked = new HashSet(); + Set result; + Set start = new HashSet<>(); + Set checked = new HashSet<>(); start.add(term); if (relation.equals("all")) result = createDotGraphNetBody(kb, start, checked, limitInt, fileRestrict); @@ -355,35 +354,39 @@ public boolean createDotGraph(KB kb, String term, String relation, int above, in result.addAll(createDotGraphBody(kb, start, checked, relation, above, below, false)); } pw.println("digraph G {"); - pw.println(" rankdir=LR"); - Iterator it = result.iterator(); - while (it.hasNext()) { - String s = it.next(); + pw.println(" node [color=black, fontcolor=black];"); // Black text and borders + pw.println(" edge [color=black];"); // Black edges + pw.println(" rankdir=LR;"); + for (String s : result) { pw.println(s); } pw.println("}"); - pw.close(); - fw.close(); - - String command = graphVizDir + File.separator + "dot " + filename + ".dot -Tgif"; - Process proc = Runtime.getRuntime().exec(command); - System.out.println("Graph.createDotGraph(): exec command: " + command); - BufferedInputStream img = new BufferedInputStream(proc.getInputStream()); - RenderedImage image = ImageIO.read(img); - File file = new File(filename + ".gif"); - ImageIO.write(image, "gif", file); - System.out.println("Graph.createDotGraph(): write image file: " + file); - return true; + pw.flush(); + + // Build a ${graph}.png from an input file + // From: https://graphviz.org/doc/info/command.html#-O + ProcessBuilder pb = new ProcessBuilder( + graphVizDir + File.separator + "dot", + "-Tpng", + "-O", + filename + ".dot" + ); + + File file = new File(filename + ".dot.png"); + System.out.println("Graph.createDotGraph(): exec command: " + pb.command()); + pb.directory(file.getParentFile()); + File log = new File(file.getParentFile(),"log"); + pb.redirectErrorStream(true); + pb.redirectOutput(Redirect.appendTo(log)); // <- in case of any errors + pb.start(); } - catch (java.io.IOException e) { - String err = "Error writing file " + filename + ".dot\n" + e.getMessage(); + catch (Exception e) { + String err = "Error writing file " + filename + ".dot.png\n" + e.getMessage(); errors.add(err); throw new IOException(err); } - finally { - if (pw != null) pw.close(); - if (fw != null) fw.close(); - } + System.out.println("Graph.createDotGraph(): write image file: " + filename + ".dot.png"); + return true; } /** ************************************************************* @@ -393,19 +396,17 @@ private boolean rejectedTerm(String s) { if (StringUtil.emptyString(s)) return true; - if (Formula.isLogicalOperator(s) || Formula.isMathFunction(s) || Formula.isVariable(s) || + return Formula.isLogicalOperator(s) || Formula.isMathFunction(s) || Formula.isVariable(s) || Formula.isComparisonOperator(s) || Formula.DOC_PREDICATES.contains(s) || StringUtil.isNumeric(s) || Formula.DEFN_PREDICATES.contains(s) || - StringUtil.isQuotedString(s)) - return true; - return false; + StringUtil.isQuotedString(s); } /** ************************************************************* * The main body for createDotGraph() when no relation is specified. * Don't graph math, logical operators or documentation relations */ - private HashSet createDotGraphNetBody(KB kb, HashSet startSet, HashSet checkedSet, + private Set createDotGraphNetBody(KB kb, Set startSet, Set checkedSet, int size, String fileRestrict) { if (!StringUtil.emptyString(fileRestrict) && !kb.containsFile(fileRestrict)) { @@ -413,13 +414,18 @@ private HashSet createDotGraphNetBody(KB kb, HashSet startSet, H return null; } System.out.println("createDotGraphNetBody(): start set: " + startSet); - HashSet result = new HashSet(); - HashSet newStartSet = new HashSet(); - while (startSet.size() > 0) { - Iterator it = startSet.iterator(); - String term = it.next(); + Set result = new HashSet<>(); + Set newStartSet = new HashSet<>(); + Iterator it; + String term, parent, rel, link, arrow, s, str; + boolean removed; + List stmts, cons; + Formula f; + while (!startSet.isEmpty()) { + it = startSet.iterator(); + term = it.next(); System.out.println("createDotGraphNetBody(): checking term: " + term); - boolean removed = startSet.remove(term); + removed = startSet.remove(term); if (!removed) { String err = "Error in Graph.createDotGraphNetBody(): " + term + " not removed"; errors.add(err); @@ -427,25 +433,24 @@ private HashSet createDotGraphNetBody(KB kb, HashSet startSet, H } if (StringUtil.isQuotedString(term) || Formula.isLogicalOperator(term)) continue; - ArrayList stmts; stmts = kb.ask("arg",1, term); for (int i = 0; i < stmts.size(); i++) { - Formula f = stmts.get(i); + f = stmts.get(i); if (f.isCached()) continue; else { - String parent = f.getStringArgument(2); + parent = f.getStringArgument(2); if (rejectedTerm(parent)) continue; if (!StringUtil.emptyString(fileRestrict) && !FileUtil.noPath(f.getSourceFile()).equals(fileRestrict)) continue; - String rel = f.getStringArgument(0); + rel = f.getStringArgument(0); if (Formula.DOC_PREDICATES.contains(rel)) continue; - String link = "[ label = \"" + rel + "\" ]"; - String arrow = " -> "; - String s = " \"" + parent + "\"" + arrow + "\"" + term + "\" " + link + ";"; + link = "[ label = \"" + rel + "\" ]"; + arrow = " -> "; + s = " \"" + parent + "\"" + arrow + "\"" + term + "\" " + link + ";"; System.out.println("createDotGraphNetBody(): result in adding parents: " + s); graphsize++; if (graphsize < size) @@ -460,21 +465,21 @@ private HashSet createDotGraphNetBody(KB kb, HashSet startSet, H stmts = kb.ask("arg",2, term); for (int i = 0; i < stmts.size(); i++) { - Formula f = stmts.get(i); + f = stmts.get(i); if (f.isCached()) continue; else { - String parent = f.getStringArgument(1); + parent = f.getStringArgument(1); if (rejectedTerm(parent)) continue; if (!StringUtil.emptyString(fileRestrict) && !FileUtil.noPath(f.getSourceFile()).equals(fileRestrict)) continue; - String rel = f.getStringArgument(0); + rel = f.getStringArgument(0); if (Formula.DOC_PREDICATES.contains(rel)) continue; - String link = "[ label = \"" + rel + "\" ]"; - String arrow = " -> "; - String s = " \"" + term + "\"" + arrow + "\"" + parent + "\" " + link + ";"; + link = "[ label = \"" + rel + "\" ]"; + arrow = " -> "; + s = " \"" + term + "\"" + arrow + "\"" + parent + "\" " + link + ";"; System.out.println("createDotGraphNetBody(): result in adding children: " + s); graphsize++; if (graphsize < size) @@ -488,32 +493,32 @@ private HashSet createDotGraphNetBody(KB kb, HashSet startSet, H } stmts = kb.ask("ant",0,term); - ArrayList cons = kb.ask("ant",0,term); + cons = kb.ask("ant",0,term); if (cons != null) stmts.addAll(cons); for (int i = 0; i < stmts.size(); i++) { - Formula f = stmts.get(i); + f = stmts.get(i); if (f.isCached()) continue; else { Set terms = f.collectTerms(); - for (String s : terms) { - if (rejectedTerm(s) || term.equals(s)) + for (String trm : terms) { + if (rejectedTerm(trm) || trm.equals(trm)) continue; if (!StringUtil.emptyString(fileRestrict) && !FileUtil.noPath(f.getSourceFile()).equals(fileRestrict)) continue; - String rel = "link"; - String link = "[ dir=none, label = \"" + rel + "\" ]"; - String arrow = " -> "; - String str = " \"" + term + "\"" + arrow + "\"" + s + "\" " + link + ";"; + rel = "link"; + link = "[ dir=none, label = \"" + rel + "\" ]"; + arrow = " -> "; + str = " \"" + trm + "\"" + arrow + "\"" + trm + "\" " + link + ";"; graphsize++; if (graphsize < size) result.add(str); else return result; - checkedSet.add(term); - if (!checkedSet.contains(s)) - newStartSet.add(s); + checkedSet.add(trm); + if (!checkedSet.contains(trm)) + newStartSet.add(trm); } } } @@ -525,14 +530,14 @@ private HashSet createDotGraphNetBody(KB kb, HashSet startSet, H /** ************************************************************* * The main body for createDotGraph(). */ - private HashSet createDotGraphBody(KB kb, HashSet startSet, HashSet checkedSet, + private Set createDotGraphBody(KB kb, Set startSet, Set checkedSet, String relation, int above, int below, boolean upSearch) { System.out.println("createDotGraph(): start set: " + startSet); - HashSet result = new HashSet(); - HashSet newStartSet = new HashSet(); + Set result = new HashSet<>(); + Set newStartSet = new HashSet<>(); newStartSet.addAll(startSet); - + if (upSearch) { above--; if (above < 0) return result; @@ -541,11 +546,17 @@ private HashSet createDotGraphBody(KB kb, HashSet startSet, Hash below--; if (below < 0) return result; } - while (startSet.size() > 0) { - Iterator it = startSet.iterator(); - String term = (String) it.next(); + + Iterator it; + String term, child, parent, link, arrow, rel, s; + boolean removed; + List stmts; + Formula f; + while (!startSet.isEmpty()) { + it = startSet.iterator(); + term = (String) it.next(); System.out.println("createDotGraph(): checking term: " + term); - boolean removed = startSet.remove(term); + removed = startSet.remove(term); if (!removed) { String err = "Error in Graph.createDotGraphBody(): " + term + " not removed"; errors.add(err); @@ -553,7 +564,6 @@ private HashSet createDotGraphBody(KB kb, HashSet startSet, Hash } if (StringUtil.isQuotedString(term)) continue; - ArrayList stmts; if (upSearch) { stmts = kb.askWithRestriction(0, relation, 1, term); } @@ -562,20 +572,20 @@ private HashSet createDotGraphBody(KB kb, HashSet startSet, Hash } for (int i = 0; i < stmts.size(); i++) { - Formula f = stmts.get(i); + f = stmts.get(i); if (f.isCached()) continue; else { - String child = f.getStringArgument(1); - String parent = f.getStringArgument(2); - String link = ""; - String arrow = "->"; - String rel = f.getStringArgument(0); + child = f.getStringArgument(1); + parent = f.getStringArgument(2); + link = ""; + arrow = "->"; + rel = f.getStringArgument(0); if (relation.equals("all")) { link = "[ label = \"" + rel + "\" ]"; arrow = "--"; } - String s = " \"" + parent + "\"" + arrow + "\"" + child + "\" " + link + ";"; + s = " \"" + parent + "\"" + arrow + "\"" + child + "\" " + link + ";"; graphsize++; if (graphsize < 100) result.add(s); @@ -590,7 +600,7 @@ private HashSet createDotGraphBody(KB kb, HashSet startSet, Hash } } result.addAll(createDotGraphBody(kb,newStartSet,checkedSet,relation,above,below,upSearch)); - } + } } return result; } @@ -614,21 +624,18 @@ public static void main(String[] args) { if (args != null && args.length > 1 && args[0].equals("-h")) { showHelp(); } - KBmanager.getMgr().initializeOnce(); if (args != null && args.length > 2 && args[0].equals("-g")) { + KBmanager.getMgr().initializeOnce(); KB kb = KBmanager.getMgr().getKB(KBmanager.getMgr().getPref("sumokbname")); Graph g = new Graph(); - String start = args[1]; + String term = args[1]; String relation = args[2]; - HashSet checked = new HashSet(); - HashSet startSet = new HashSet(); String fileRestrict = ""; - startSet.add(start); try { - g.createDotGraph(kb, start, relation, 2, 2, 100, "graph.txt", fileRestrict); + g.createDotGraph(kb, term, relation, 2, 2, 100, "graph.txt", fileRestrict); } - catch (Exception e) { - System.out.println(e.getMessage()); + catch (IOException e) { + System.err.println(e.getMessage()); e.getStackTrace(); } } From 981dd9db0d0bfeab9cf01409c0e57c70423457c2 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 21:26:40 -0700 Subject: [PATCH 26/28] [Terry N.] Fix for Issue #134 --- web/jsp/MiscUtilities.jsp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/web/jsp/MiscUtilities.jsp b/web/jsp/MiscUtilities.jsp index 1c4d51ef..62dd5c73 100644 --- a/web/jsp/MiscUtilities.jsp +++ b/web/jsp/MiscUtilities.jsp @@ -34,19 +34,17 @@ String status = ""; if (role == null || !role.equalsIgnoreCase("admin")) { - response.sendRedirect("KBs.jsp"); + response.sendRedirect("KBs.jsp"); } else { namespace = request.getParameter("namespace"); - if (namespace == null) + if (namespace == null) namespace = ""; if (StringUtil.emptyString(kbName) || (KBmanager.getMgr().getKB(kbName) == null)) { System.out.println(" no such knowledge base " + kbName); - Set names = KBmanager.getMgr().getKBnames(); - if (names != null && names.size() > 0) { - Iterator it = names.iterator(); - if (it.hasNext()) { - kbName = (String) it.next(); + Set names = KBmanager.getMgr().getKBnames(); + if (names != null && !names.isEmpty()) { + for (String kbName : names) { System.out.println("kbName == " + kbName); } } @@ -59,16 +57,16 @@ filename = request.getParameter("filename"); action = request.getParameter("action"); String writeOWL = request.getParameter("writeOWL"); - - if (StringUtil.emptyString(action) || action.equalsIgnoreCase("null")) + + if (StringUtil.emptyString(action) || action.equalsIgnoreCase("null")) action = ""; - if (writeOWL != null) + if (writeOWL != null) OMWordnet.generateOMWOWLformat(kb); if (StringUtil.isNonEmptyString(action)) { if (kb != null) { if (action.equals("dotGraph")) { Graph g = new Graph(); - g.createDotGraph(kb, term, relation, 2,2,filename); + g.createDotGraph(kb, term, relation, 2, 2, 100, filename, ""); } } @@ -87,13 +85,13 @@

<% - if (action.equalsIgnoreCase("generateDocs") + if (action.equalsIgnoreCase("generateDocs") || action.equalsIgnoreCase("generateSingle")) { if (StringUtil.isNonEmptyString(status)) { - if (!status.trim().startsWith("Error")) - out.println("HTML files have been written to " + status); - else - out.println(status); + if (!status.trim().startsWith("Error")) + out.println("HTML files have been written to " + status); + else + out.println(status); out.println("

"); } } @@ -108,9 +106,9 @@

- + Write OMW in OWL: - +

From 54fce2b970a72117acbf33879182249cd14c422c Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 21:29:30 -0700 Subject: [PATCH 27/28] [Terry N.] Fix for Issue #134 --- nbproject/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbproject/build.properties b/nbproject/build.properties index 693cff9a..59bc6d10 100644 --- a/nbproject/build.properties +++ b/nbproject/build.properties @@ -125,7 +125,7 @@ kbs_home=../sumo project.license=LICENSE # Various runtime arguments here -run.args= +run.args=-g Transitway subclass # Tomcat Manager properties catalina.ops=-Xmx10g -Xss1m From 957640c8296dc5c471520732a12180cd55bbe17e Mon Sep 17 00:00:00 2001 From: git Date: Sat, 2 Nov 2024 22:23:40 -0700 Subject: [PATCH 28/28] [Terry N.] merge commit to catch up w/ master --- build.xml | 7 ++----- src/java/com/articulate/sigma/KButilities.java | 5 +++-- src/java/com/articulate/sigma/trans/SUMOtoTFAform.java | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/build.xml b/build.xml index 429cfd1d..1e974c13 100644 --- a/build.xml +++ b/build.xml @@ -337,15 +337,12 @@ - + - + diff --git a/src/java/com/articulate/sigma/KButilities.java b/src/java/com/articulate/sigma/KButilities.java index 7c83ac2d..371c1b66 100755 --- a/src/java/com/articulate/sigma/KButilities.java +++ b/src/java/com/articulate/sigma/KButilities.java @@ -104,8 +104,8 @@ public static boolean isValidFormula(KB kb, String form) { SUMOtoTFAform.initOnce(); String result = ""; + KIF kif = new KIF(); try { - KIF kif = new KIF(); result = kif.parseStatement(form); } catch (Exception e) { @@ -113,7 +113,8 @@ public static boolean isValidFormula(KB kb, String form) { result = ""; } if (!StringUtil.emptyString(result)) { - System.out.println("isValidFormula(): Error: " + result); + errors.addAll(kif.errorSet); + if (debug) System.out.println("isValidFormula(): Error: " + result); return false; } Formula f = new Formula(form); diff --git a/src/java/com/articulate/sigma/trans/SUMOtoTFAform.java b/src/java/com/articulate/sigma/trans/SUMOtoTFAform.java index ea4dbcff..3b699fa3 100644 --- a/src/java/com/articulate/sigma/trans/SUMOtoTFAform.java +++ b/src/java/com/articulate/sigma/trans/SUMOtoTFAform.java @@ -2124,7 +2124,7 @@ public static boolean inconsistentVarTypes() { if (kb.kbCache.checkDisjoint(kb, c1, c2)) { String msg = "SUMOtoTFAform.inconsistentVarTypes(): rejected inconsistent variable types: " + c1 + ", " + c2 + " for var " + s; - System.out.println(msg); + if (debug) System.out.println(msg); errors.add(msg); return true; }