Class KButilities

java.lang.Object
com.articulate.sigma.KButilities
All Implemented Interfaces:
EventListener, javax.servlet.ServletContextListener

@WebListener public class KButilities extends Object implements javax.servlet.ServletContextListener
Contains utility methods for KBs
  • Field Details

    • EXECUTOR_SERVICE

      public static final ExecutorService EXECUTOR_SERVICE
    • kryoLocal

      public static final ThreadLocal<com.esotericsoftware.kryo.Kryo> kryoLocal
      A thread local pool for the Kryo serializer
    • SIGMA_HOME

      public static final String SIGMA_HOME
    • ONE_K

      public static final int ONE_K
      See Also:
    • debug

      public static boolean debug
    • errors

      public static Set<String> errors
      Errors found during processing formulas
    • insideWebContext

      public static boolean insideWebContext
      Warnings found during processing formulas
  • Constructor Details

    • KButilities

      public KButilities()
  • Method Details

    • getExecutorService

      public static ExecutorService getExecutorService()
    • getInstance

      public static KButilities getInstance()
    • contextInitialized

      public void contextInitialized(javax.servlet.ServletContextEvent servletContextEvent)
      Specified by:
      contextInitialized in interface javax.servlet.ServletContextListener
    • contextDestroyed

      public void contextDestroyed(javax.servlet.ServletContextEvent servletContextEvent)
      Specified by:
      contextDestroyed in interface javax.servlet.ServletContextListener
    • refreshExecutorService

      public static void refreshExecutorService()
      Force a refresh of the ExecutorService - useful when switching contexts
    • isRelation

      public static boolean isRelation(KB kb, String term)
    • isFunction

      public static boolean isFunction(KB kb, String term)
    • isAttribute

      public static boolean isAttribute(KB kb, String term)
    • clearErrors

      public static void clearErrors()
    • hasCorrectTypes

      public static boolean hasCorrectTypes(KB kb, Formula f)
      Checks for consistent typing in the given formula
      Parameters:
      kb - the knowledge base to check typing against
      f - the formula to check
    • isValidFormula

      public static boolean isValidFormula(KB kb, String form)
      Checks for overall validity of the given formula
      Parameters:
      kb - the knowledge base to check typing against
      form - the formula to check
    • isClass

      public static boolean isClass(KB kb, String term)
    • isInstance

      public static boolean isInstance(KB kb, String term)
    • isVariableArity

      public static boolean isVariableArity(KB kb, String term)
    • getDocumentation

      public static String getDocumentation(KB kb, String term)
    • getCountTermFormats

      public static int getCountTermFormats(KB kb, String lang)
      Get count of all the termFormat strings for the given language
    • getCountUniqueTermFormats

      public static int getCountUniqueTermFormats(KB kb, String lang)
      Get count of all the termFormat strings for unique SUMO terms for the given language. So if a term has more than one termFormat, only count one
    • countFormulaTypes

      public static Map<String,Integer> countFormulaTypes(KB kb)
      Get count of all the different kinds of formulas as to their logical expressivity
    • genSynLinks

      public static void genSynLinks(String fname)
      Generate default synonymousExternalConcept statements for a .tsv
    • eqNum2Text

      public static String eqNum2Text(int val)
      convert the numerical result of compare() to text
    • termIntersection

      public static List<Formula> termIntersection(KB kb, String term1, String term2)
      Get all formulas that contain both terms.
    • countRelations

      public static void countRelations(KB kb)
    • isCacheFile

      public static boolean isCacheFile(String filename)
    • countProcesses

      public static void countProcesses(KB kb)
    • checkURLs

      public static void checkURLs(KB kb)
    • validatePictureList

      public static void validatePictureList()
    • semnetAsJSON3

      public String semnetAsJSON3(KB kb, boolean cached, boolean strings)
    • generateSemNetNeighbors

      public Set<KButilities.GraphArc> generateSemNetNeighbors(KB kb, boolean cached, boolean strings, boolean links, String term, int count)
    • generateAllNL

      public static String generateAllNL(KB kb)
      Generate line pairs of formula and NL paraphrase of formula
    • instanceOfInstanceP

      public static boolean instanceOfInstanceP(KB kb)
      Find all cases of where (instance A B) (instance B C) as well as all cases of where (instance A B) (instance B C) (instance C D). Report true if any such cases are found, false otherwise.
    • writeDisplayText

      public static void writeDisplayText(KB kb, String displayFormatPredicate, String displayTermPredicate, String language, String fname) throws IOException
      Throws:
      IOException
    • generateTPTPTestAssertions

      public static void generateTPTPTestAssertions()
    • generateRelationList

      public static void generateRelationList()
      Note this simply assumes that initial lower case terms are relations.
    • getCountNonLinguisticAxioms

      public static int getCountNonLinguisticAxioms(KB kb)
    • countStringWords

      public static void countStringWords(KB kb)
      Count the number of words in all the strings in a knowledge base
    • getAllFormulasOfTerm

      public static Set<Formula> getAllFormulasOfTerm(KB kb, String term)
      Find all formulas in which the SUMO term is involved.
    • generateFormulasAndDoc

      public static String generateFormulasAndDoc(KB kb)
      Find all formulas in which the SUMO term is involved.
    • termFormatIndex

      public static String termFormatIndex(KB kb)
      List all the terms and their termFormat expressions.
    • genAllDoc

      public static void genAllDoc(KB kb, String fname)
      Generate a textual list of all documentation strings and write to a file.
    • genDoc

      public static void genDoc(KB kb, String fname)
      Generate a textual list of terms and their documentation strings from a file.
    • getLabelsForTerm

      public static List<String> getLabelsForTerm(KB kb, String term, String lang)
      Generate a HTML list of labels from termFormats TODO: Does this work? Only returning an empty List
    • genAllAlphaHTMLDoc

      public static void genAllAlphaHTMLDoc(KB kb)
      Generate a HTML list of terms and their documentation strings from a file as upper and lowercase individual files so that each file isn't gigantic
    • genAllHTMLDoc

      public static void genAllHTMLDoc(KB kb)
      Generate a HTML list of terms and their documentation strings from a file.
    • getLinkedTermsInDoc

      public static List<String> getLinkedTermsInDoc(KB kb, String term)
    • genSpecificTermDoc

      public static void genSpecificTermDoc(KB kb, String file, String lang)
      Generate a HTML list of terms and their documentation strings from a file.
    • mergeToMap

      public static Map<String,Set<String>> mergeToMap(Map<String,Set<String>> map1, Map<String,Set<String>> map2, KB kb)
      utility method to merge two HashMaps of String keys and a values of an HashSet of Strings. Note that parent classes in the set of classes will be removed
    • shutDownExecutorService

      public static void shutDownExecutorService()
      Must be called whenever a *.tptp, *.tff or *.fof file is written to allow for clean shutdown of the JVM. Call this at the bottom of any main class where the executor is invoked.
    • showHelp

      public static void showHelp()
    • main

      public static void main(String[] args)