Class DocGen

java.lang.Object
com.articulate.sigma.DocGen

public class DocGen extends Object
A class to generate simplified HTML-based documentation for SUO-KIF terms.
  • Field Details

    • F_SI

      protected static final String F_SI
      This String token denotes Sigma's "simple" HTML layout, and is used as a flag in the HTML generation code to switch between full and simple modes.
      See Also:
    • F_CONTROL_TOKENS

      protected static List<String> F_CONTROL_TOKENS
    • SP2

      protected static final String SP2
      See Also:
    • INDEX_FILE_NAME

      protected static String INDEX_FILE_NAME
      The default base plus file suffix name for the main index file for a set of HTML output files.
    • localCounter

      protected int localCounter
    • DEFAULT_KEY

      protected static final String DEFAULT_KEY
      See Also:
    • DOC_GEN_INSTANCES

      protected static Map DOC_GEN_INSTANCES
    • lineSeparator

      protected String lineSeparator
    • docGenControlBits

      protected int docGenControlBits
      A int value representing the bit values that control the file generation process.
    • defaultNamespace

      protected String defaultNamespace
      The default namespace associated with this DocGen object
    • defaultPredicateNamespace

      protected String defaultPredicateNamespace
      The default namespace for predicates in the ontology associated with this DocGen object
    • ontology

      protected String ontology
      The ontology associated with this DocGen object, and for which the DocGen object is used to generate files.
    • kb

      protected KB kb
      The KB associated with this DocGen object.
    • codedIdentifiers

      protected Set<String> codedIdentifiers
      A Set of Strings.
    • titleText

      protected String titleText
      The document title text to be used for HTML generation
    • footerText

      protected String footerText
      The document footer text to be used for HTML generation
    • styleSheet

      protected String styleSheet
      The style sheet (CSS filename) to be referenced in HTML generation
    • defaultImageFile

      protected String defaultImageFile
      The default image file (such as an organization's logo) to be used in HTML generation
    • defaultImageFileMarkup

      protected String defaultImageFileMarkup
      The default image file (such as an organization's logo) to be used in HTML generation, wrapped in any necessary additional markup required for proper display.
    • outputDirectoryPath

      protected String outputDirectoryPath
      The canonical pathname of the current directory in which output files will be (are being) saved.
    • stringReplacementMap

      protected Map<String,String> stringReplacementMap
      A Map containing String replacement pairs. This is to provide adequate ASCII translations for HTML character entities, in circumstances where occurrences of the entities might cause parsing or rendering problems (e.g., apparently, in XSD files).
    • inhibitDisplayRelations

      protected Set inhibitDisplayRelations
      A set of the predicates that should not be displayed to the user.
    • tocHeader

      protected String tocHeader
      The header to be used for the the table of contents (or index list) section during HTML generation.
    • docGenKey

      protected String docGenKey
      A default key to identify this particular DocGen object
    • simplified

      protected boolean simplified
      If true, a termFormat value obtained for term will be displayed rather than the term name itself.
    • relationsByKB

      protected Map<KB,List<String>> relationsByKB
      A Map in which each key is a KB name and the corresponding value is a List of the Predicates defined in the KB.
    • outputParentDir

      protected File outputParentDir
      The parent directory for target subdirectories of HTML, XSD, and other types of files generated by this DocGen object.
    • displayFilter

      protected DocGen.DisplayFilter displayFilter
      The DisplayFilter which, if present, determines if a given SUO-KIF object may be displayed or output by this DocGen object.
    • alphaList

      protected final Map<String,Map<String,List<String>>> alphaList
      A TreeMap of TreeMaps of ArrayLists where the keys are uppercase single characters (of term formats or headwords) and the values are TreeMaps with a key of the term formats or headwords and ArrayList values of the actual term names. Note that if "simplified" is false actual term names will be used instead of term formats or headwords and the interior map will have keys that are the same as their values. Pictorially: letter-> formattedTerm1->term11,term12...term1N formattedTerm2->term21,term22...term2N
    • namespacePrefixes

      protected List<String> namespacePrefixes
      A List of currently known namespace prefixes.
    • namespaces

      protected List<String> namespaces
      A List of currently known namespaces.
    • isInstanceOfCache

      protected static Map isInstanceOfCache
      Supports memoization for isInstanceOf(kb, c1, c2).
  • Constructor Details

    • DocGen

      protected DocGen()
      To obtain an instance of DocGen, use the static factory method getInstance().
  • Method Details

    • getControlTokens

      public static List<String> getControlTokens()
    • getControlBitValue

      public static int getControlBitValue(String token)
    • getInstance

      public static DocGen getInstance()
    • getInstance

      public static DocGen getInstance(String compositeKey)
    • getInstance

      public static DocGen getInstance(KB kb, String ontology)
    • getLineSeparator

      public String getLineSeparator()
    • setLineSeparator

      public void setLineSeparator(String ls)
    • getDocGenControlBits

      public int getDocGenControlBits()
      Returns the int value that represents the bit values used to guide aspects of the document generation process for this DocGen instance.
      Returns:
      An int value representing bit values
    • clearDocGenControlBits

      public void clearDocGenControlBits()
      Sets to 0 the int value that represents the bit values used to guide aspects of the document generation process for this DocGen instance.
    • addDocGenControlBits

      public int addDocGenControlBits(int val)
      Adds val via bitwise OR to the int value that represents the bit values used to control the document generation process for this DocGen instance.
      Parameters:
      val - An integer representing bit values
      Returns:
      An int value representing the result of the bitwise OR operation.
    • addDocGenControlBits

      public int addDocGenControlBits(String token)
      Adds via bitwise OR the bit value corresponding to token to the int value that represents the bit values used to control the document generation process for this DocGen instance.
      Parameters:
      token - A String representing bit values
      Returns:
      An int value representing the result of the bitwise OR operation.
    • testDocGenControlBits

      public boolean testDocGenControlBits(int valToTest)
      Returns true if the bit values represented by valToTest are among the control bits represented for this DocGen instance.
      Parameters:
      valToTest - An integer representing bit values to be tested
      Returns:
      true or false
    • testDocGenControlBits

      public boolean testDocGenControlBits(String token)
      Returns true if the bit values corresponding to token are among the control bits represented for this DocGen instance.
      Parameters:
      token - A String token corresponding to a bit value
      Returns:
      true or false
    • getOutputFormatTokens

      public static List<String> getOutputFormatTokens(KB kb, String ontology)
      Returns a List of String tokens that determine how the output should be formatted. The List could be empty.
      Parameters:
      kb - The KB in which to look for docGenOutputFormat statements
      ontology - A SUO-KIF term denoting an Ontology
      Returns:
      a List of Strings, which could be empty
    • getFirstHtmlFormatToken

      public static String getFirstHtmlFormatToken(KB kb, String ontology)
      Returns the first String token retrieved from ontology in kb that denotes an HTML output format. Such tokens may be the third element in statements for which the predicate is docGenOutputFormat.
      Parameters:
      kb - The KB in which to look for docGenOutputFormat statements
      ontology - A SUO-KIF term denoting an Ontology
      Returns:
      a String token, or null.
    • getDefaultNamespace

      public String getDefaultNamespace()
      Returns the String denoting the default namespace associated with this DocGen object.
    • setDefaultNamespace

      public void setDefaultNamespace(String namespace)
      Sets the default namespace for this DocGen object.
    • getDefaultPredicateNamespace

      public String getDefaultPredicateNamespace()
      Returns the String denoting the default namespace for predicates in the ontology associated with this DocGen object.
    • setDefaultPredicateNamespace

      public void setDefaultPredicateNamespace(String namespace)
      Sets the default namespace for predicates in the ontology associated with this DB object.
    • setOntology

      public void setOntology(String term)
    • getOntology

      public String getOntology()
      Returns a term denoting the default Ontology for this DocGen object if an Ontology has been set, and tries very hard to find a relevant Ontology if one has not been set.
    • getOntology

      public String getOntology(KB kb)
      Returns a term denoting the default Ontology for this DocGen object if an Ontology has been set, and tries very hard to find a relevant Ontology if one has not been set.
    • setKB

      public void setKB(KB kb)
    • getKB

      public KB getKB()
    • getCodedIdentifiers

      protected Set<String> getCodedIdentifiers(KB kb)
      Collects and returns the Set containing all known coded identifiers in kb, including ISO code values stated to be such.
      Parameters:
      kb - The KB in which to gather terms defined as coded identifiers
      Returns:
      A Set of all the terms that denote ISO code values and other coded identifiers
    • setTitleText

      public void setTitleText(String titlestr)
      Sets the title text to be used during HTML document generation.
      Parameters:
      titlestr - A String that will be used as the HTML document title
    • getTitleText

      public String getTitleText()
      Returns the String that will be used as the title text for HTML document generation, else returns an empty String if no title text value has been set.
    • setFooterText

      public void setFooterText(String str)
      Sets the footer text String to be used during HTML document generation.
      Parameters:
      str - A String that will be used as the HTML document footer text
    • getFooterText

      public String getFooterText()
      Returns the String that will be used as the footer text for HTML document generation, else returns an empty String if no footer text value has been set.
    • setStyleSheet

      public void setStyleSheet(String filename)
      Sets the base name plus suffix filename of the Cascading Style Sheet file to be referenced during HTML document generation.
      Parameters:
      filename - A String that is a base filename plus a filename suffix
    • getStyleSheet

      public String getStyleSheet()
      Returns the base filename plus filename suffix form of the Cascading Style Sheet file to be referenced during HTML document generation, else returns an empty String if no value has been set.
    • setDefaultImageFile

      public void setDefaultImageFile(String filename)
      Sets the base name plus suffix filename of the logo image file to be referenced during HTML document generation.
      Parameters:
      filename - A String that is a base filename plus a filename suffix
    • getDefaultImageFile

      public String getDefaultImageFile()
      Returns the base filename plus filename suffix form of the logo image file to be referenced during HTML document generation, else returns an empty String if no value has been set.
    • setDefaultImageFileMarkup

      public void setDefaultImageFileMarkup(String markup)
      Sets the base name plus suffix filename of the logo image file to be referenced during HTML document generation.
      Parameters:
      markup - A String that includes the image file pathname plus any additional markup required for proper display of the image
    • getDefaultImageFileMarkup

      public String getDefaultImageFileMarkup()
      Returns the base filename plus filename suffix form of the logo image file, wrapped in any additional markup required for the intended rendering of the image.
    • setOutputDirectoryPath

      public void setOutputDirectoryPath(String pathname)
      Sets the canonical pathname String of the current directory in which output files will be (are being) saved.
      Parameters:
      pathname - A canonical pathname String
    • getOutputDirectoryPath

      public String getOutputDirectoryPath()
      Returns the canonical pathname String of the current directory in which output files will be (are being) saved.
    • setStringReplacementMap

      public void setStringReplacementMap(Map<String,String> keyValPairs)
      Sets the Map to be used for HTML character entity to ASCII replacements.
    • getStringReplacementMap

      public Map<String,String> getStringReplacementMap()
      Returns the Map to be used for HTML character entity to ASCII replacements, attempting to build it from docGenCodeMapTranslation statements found in the KB if the Map does not already exist.
    • getStringReplacement

      public String getStringReplacement(String fromString)
      Returns the String replacement for fromString, if one can be located, else just returns fromString.
      Parameters:
      fromString - A String for which a replacement is sought
      Returns:
      A replacement String
    • setInhibitDisplayRelations

      public void setInhibitDisplayRelations(Set relations)
      Sets the predicates for which display should be suppressed to those contained in relations.
      Parameters:
      relations - A Set of predicate names
    • getInhibitDisplayRelations

      public Set getInhibitDisplayRelations()
      Returns a Set containing the names of those predicates for which display should be suppressed, and tries to create the Set from docGenInhibitDisplayRelations statements found in the current KB if the Set does not already exist.
      Returns:
      a Set of predicate names
    • setTocHeader

      public void setTocHeader(String header)
      Sets the String header to be used in generated HTML files to header.
    • getTocHeader

      public String getTocHeader()
      Returns the String header to be used in generated HTML files.
    • getDocGenKey

      public String getDocGenKey()
      Returns the String key that is the index for this particular DocGen object.
    • setDocGenKey

      public void setDocGenKey(String key)
      Sets the String key that is the index for this particular DocGen object.
    • getKifNamespaceDelimiter

      public static String getKifNamespaceDelimiter()
    • getW3cNamespaceDelimiter

      public static String getW3cNamespaceDelimiter()
    • getSafeNamespaceDelimiter

      public static String getSafeNamespaceDelimiter()
    • getSimplified

      public boolean getSimplified()
      Returns true if a termFormat value obtained for term will be displayed during HTML rendering rather than the term name itself.
    • setSimplified

      public void setSimplified(boolean val)
      Sets this.simplified to val. If this.simplified is true, the statements in Sigma's KB will be rendered in a simple frame-like HTML format rather than as SUO-KIF Formulas.
    • getRelationsByKB

      public Map<KB,List<String>> getRelationsByKB()
    • indentChars

      public static String indentChars(String str, int indent)
      Returns a String consisting of str concatenated indent times.
      Parameters:
      str - The String to be concatenated with itself
      indent - An int indicating the number of times str should be concatenated
      Returns:
      A String
    • setOutputParentDir

      public void setOutputParentDir(File obj)
      Sets the parent directory in which subdirectories for different types of output files will be created to the File obj, and tries to create the directory pathname if it does not already exist.
      Parameters:
      obj - A File object representing a directory
    • setOutputParentDir

      public void setOutputParentDir(String pathname)
      Sets to pathname the parent directory in which subdirectories for different types of output files will be created, and tries to create the directory pathname if it does not already exist.
      Parameters:
      pathname - A String representing a directory pathname
    • setOutputParentDir

      public void setOutputParentDir(List pathnameComponents)
      Sets the parent directory in which subdirectories for different types of output files will be created to the File obj, and tries to create the directory pathname if it does not already exist.
      Parameters:
      pathnameComponents - A String representing a directory pathname
    • setOutputParentDir

      public void setOutputParentDir(KB kb, String ontology)
      Sets the parent directory in which subdirectories for different types of output files will be created to the abstract pathname represented by a statement in kb formed with the predicate docGenOutputParentDirectory and the argument ontology. Tries to create the directory pathname if it does not already exist.
      Parameters:
      kb - The KB containing a statement formed with the predicate docGenOutputParentDirectory and ontology
      ontology - The ontology referred to in a statement formed with the predicate docGenOutputParentDirectory in kb
    • getOutputParentDir

      public File getOutputParentDir()
      Returns a File object representing the directory in which the subdirectories for the various types of output files will be located.
    • setDisplayFilter

      public void setDisplayFilter(DocGen.DisplayFilter filterObj)
      Sets the DisplayFilter associated with this DocGen object to filterObj.
      Parameters:
      filterObj - An instance of DisplayFilter
    • getDisplayFilter

      public DocGen.DisplayFilter getDisplayFilter()
      Returns the DisplayFilter object associated with this DocGen object, or null if no DisplayFilter has been set.
    • resortKbTerms

      public Set<String> resortKbTerms(KB kb)
      Rebuilds the TreeSet containing all terms in kb, and forces the new TreeSet to sort according to each term's presentation name.
    • getAlphaList

      public Map<String,Map<String,List<String>>> getAlphaList(KB kb)
      Returns:
      a TreeMap of TreeMaps of ArrayLists where the keys are uppercase single characters (of term formats or headwords) and the values are TreeMaps with a key of the term formats or headwords and ArrayList values of the actual term names. Note that if "simplified" is false actual term names will be used instead of term formats or headwords and the interior map will have keys that are the same as their values. Pictorially: letter-> formattedTerm1->term11,term12...term1N formattedTerm2->term21,term22...term2N
    • clearAlphaList

      public void clearAlphaList()
      Clears the alphaList for this DocGen object.
    • createAlphaList

      protected Map<String,Map<String,List<String>>> createAlphaList(KB kb)
      Returns:
      a TreeMap of TreeMaps of ArrayLists where the keys are uppercase single characters (of term formats or headwords) and the values are TreeMaps with a key of the term formats or headwords and ArrayList values of the actual term names. Note that if "simplified" is false actual term names will be used instead of term formats or headwords and the interior map will have keys that are the same as their values. Pictorially: letter-> formattedTerm1->term11,term12...term1N formattedTerm2->term21,term22...term2N
    • isComposite

      public static boolean isComposite(KB kb, String term)
      Returns true if term is an instance or subclass of CompositeContentBearingObject in kb, else returns false.
      Parameters:
      kb - The KB in which to check the definition of term
      term - A SUO-KIF term
      Returns:
      true or false
    • getRangeValueList

      public static List<String> getRangeValueList(KB kb, String predicate)
      Returns an ArrayList of Strings extracted from the range argument (arg2) of the first retrieved statement formed with predicate. If no statement can be retrieved, the ArrayList will be empty.
      Parameters:
      kb - The KB from which to retrieve a statement with predicate
      predicate -
      Returns:
      An ArrayList of Strings, which could be empty.
    • setMetaDataFromKB

      public void setMetaDataFromKB(KB kb, String ontology)
      Tries to use the values obtained from kb and ontology to set some of the parameter values used for HTML generation.
      Parameters:
      kb - The KB from which to gather stated parameter values
      ontology - The ontology from which to gather stated parameter values
    • getClientOntologyNames

      protected static List<String> getClientOntologyNames()
      Returns a List of the names of all client ontologies currently represented in any loaded KB.
    • createCompositePage

      public String createCompositePage(KB kb, String kbHref, String term, Map<String,Map<String,List<String>>> alphaList, int limit, String language, String formatToken)
      Create an HTML page that lists information about a particular composite term, which is a representation of an XML structure.
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists. @see createAlphaList()
    • createPage

      public String createPage(KB kb, String kbHref, String term, Map<String,Map<String,List<String>>> alphaList, int limit, String language, String formatToken)
      Create an HTML page that lists information about a particular term, with a limit on how many statements of each type should be displayed.
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists.
    • getAllNamespaceDelimiters

      public List<String> getAllNamespaceDelimiters()
      Returns an ArrayList of namespace delimiter Strings gathered from all loaded KBs, obtained by collecting statements formed with the predicate docGenNamespaceDelimiter.
      Returns:
      An ArrayList of namespace delimiter tokens, which could be empty
    • generateHtmlDocStart

      public String generateHtmlDocStart(String title)
      Returns a String of HTML markup for the start of a document, using title as the document title String.
      Parameters:
      title - A String to be used as the document title
      Returns:
      A String of HTML markup encoding the start of an HTML document
    • generateHtmlFooter

      protected String generateHtmlFooter(String footerText)
      Returns a String of HTML markup encoding the footer section of an HTML document, and using footerText as the text to be displayed at the bottom of the page.
      Parameters:
      footerText - The text String to be displayed at the bottom of an HTML document
      Returns:
      A String of HTML markup
    • isLegalForDisplay

      protected boolean isLegalForDisplay(String term)
      Returns true if statements that include term and occur in the kb and ontology associated with this DocGen object may be displayed or output (at all, in any form).
      Returns:
      true or false
    • getOntologyNamespaces

      protected List<String> getOntologyNamespaces(KB kb, String ontology)
      Returns a List of all SUO-KIF terms denoting those namespaces containing terms that are defined in, or occur in, statements in ontology. An association (correspondence) between a namespace and an ontology is represented by a statement formed with the SUO-KIF predicate ontologyNamespace.
      Parameters:
      kb - The KB in which ontologyNamespace statements will be sought
      ontology - The name of the ontology that will be checked
      Returns:
      An ArrayList of SUO-KIF terms that denote namespaces and occur in statements formed with the predicate ontologyNamespace
    • getNamespaceDelimiters

      protected List<String> getNamespaceDelimiters(KB kb, String ontology)
      Returns a List of all Strings used as namespace delimiters in terms defined or referred to in ontology, as specified by statements formed with the SUO-KIF predicate docGenNamespaceDelimiter.
      Parameters:
      kb - The KB that will be checked to find statements formed with docGenNamespaceDelimiter
      ontology - The name of the ontology that will be checked
      Returns:
      An ArrayList of tokens (Strings) that are used as delimiters between a qualified term name and the namespace prefix that qualifies the term
    • getNamespacePrefixes

      public List<String> getNamespacePrefixes()
      Returns an ArrayList of all known namespace prefixes sorted by length, from longest to shortest.
      Returns:
      A List of all known namespace prefixes
    • getNamespaces

      public List<String> getNamespaces()
      Returns a List of all SUO-KIF terms that denote namespaces in any loaded KB, obtained by gathering statements formed with the predicates inNamespace and ontologyNamespace as well as explicit instance statements.
      Returns:
      A List of all known SUO-KIF terms that denote namespaces
    • getNamespaces

      protected List<String> getNamespaces(KB kb, String ontology, boolean force)
      Returns a List of all SUO-KIF terms denoting namespaces in kb or in ontology, using the predicates inNamespace and ontologyNamespace.
      Parameters:
      kb - The KB in which statements will be checked
      ontology - The name of the ontology that will be checked
      force - If true, this parameter will force the List of namespaces to be recomputed
      Returns:
      A List of all the SUO-KIF terms that denote namespaces and occur in statements formed with inNamespace or ontologyNamespace
    • getNamespacePrefix

      protected String getNamespacePrefix(KB kb, String term)
      Returns the namespace prefix of term based on the namespaces known in kb, else returns the empty String if term appears to have no namespace prefix.
    • stripNamespacePrefix

      protected String stripNamespacePrefix(KB kb, String term)
      Returns term without its namespace prefix if it appears to have one in kb, else just returns term.
    • toKifNamespace

      protected String toKifNamespace(KB kb, String term)
      Returns a SUO-KIF term denoting a namespace.
      Parameters:
      kb - The KB in which to determine if term is an namespace
      term - A String denoting a namespace, perhaps in W3C format
      Returns:
      String A term denoting a namespace in SUO-KIF format, else just returns the input term if no syntactic transformation is warranted
    • removeLinkableNamespacePrefixes

      protected String removeLinkableNamespacePrefixes(KB kb, String text)
      Removes namespace prefixes from all SUO-KIF terms to be hyperlinked in text.
      Parameters:
      kb - The KB is use when checking for valid namespace prefixes
      text - The String in which all linkable SUO-KIF terms are to be transformed
      Returns:
      A String with all linkable SUO-KIF terms have had their namespace prefixes removed
    • getPredicates

      protected List<String> getPredicates(KB kb, boolean requireNamespace)
      Collects and returns a List of all Predicates in kb.
      Parameters:
      kb - The KB from which to gather all terms that are instances of BinaryPredicate
      Returns:
      A List of BinaryPredicates (Strings)
    • hasSubComponents

      protected boolean hasSubComponents(KB kb, String term)
      Returns true if term has syntactic subcomponents such as XML elements or XML attributes in kb, else returns false.
      Parameters:
      kb - The KB in which term is defined
      term - A String denoting a SUO-KIF constant name
      Returns:
      true or false
    • getSubComponents

      protected List<String> getSubComponents(KB kb, String term)
      Returns a List containing those terms that are immediate syntactic subordinates of term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that is a SUO-KIF constant
      Returns:
      A List of Strings that denote SUO-KIF constants, or an empty List
    • getSuperComponents

      protected List<String> getSuperComponents(KB kb, String term)
      Returns a List containing those terms that are immediate syntactic superiors or "containers" of term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String, a SUO-KIF constant
      Returns:
      A List of Strings that denote SUO-KIF constants, or an empty List
    • getFirstTermFormat

      protected String getFirstTermFormat(KB kb, String term, List contexts)
      Returns a String that is the first termFormat value obtained for term in kb, else returns null if no termFormat value exists.
      Parameters:
      kb - The KB in which term is defined
      term - A String that is a SUO-KIF constant
      contexts - A List of namespaces or other terms that index context-specific termFormat statements
      Returns:
      A List of Strings that denote SUO-KIF constants, or an empty List
    • getContextualDocumentation

      protected String getContextualDocumentation(KB kb, String term, List contexts)
      Returns the first documentation String obtained for term in kb, using the List of namespaces or other contextualizing terms in contexts.
      Parameters:
      kb - The KB in which term is defined
      term - A String that is a SUO-KIF constant
      contexts - A List of namespaces or other terms that index context-specific documentation or comment statements
      Returns:
      A documentation String, or an empty String if no documentation String can be found
    • getNearestContainingClass

      protected String getNearestContainingClass(KB kb, String term)
      Returns the first containing Class that can be found for term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that is a SUO-KIF constant
      Returns:
      A SUO-KIF term denoting a Class, or null if no Class can be found
    • getFirstSubsumingTerm

      protected String getFirstSubsumingTerm(KB kb, String term)
      Returns the first purely "subsuming" entity that can be found for term in kb, assuming that term denotes a Class or a Relation.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF Class or Relation
      Returns:
      A SUO-KIF term, or null if no subsuming term can be found
    • getFirstGeneralTerm

      protected String getFirstGeneralTerm(KB kb, String term)
      Returns the first containing, subsuming, or superordinate entity that can be found for term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that is a SUO-KIF constant
      Returns:
      A SUO-KIF term, or null if no more general term can be found
    • getFirstGeneralTerms

      protected List<String> getFirstGeneralTerms(KB kb, String term)
      Returns a List of the first containing, subsuming, or superordinate entities found for term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      A List of SUO-KIF terms, or an empty List if no generalizations of term can be found
    • getFirstSpecificTerms

      protected List<String> getFirstSpecificTerms(KB kb, String term)
      Returns a List of the first instances or syntactic subordinate entities that can be found for term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      A List of SUO-KIF terms, or an empty List
    • getSyntacticSubordinateTerms

      protected List<String> getSyntacticSubordinateTerms(KB kb, String term)
      Returns a List of the entities that are immediate syntactic subordinates of term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      A List of SUO-KIF terms, or an empty List
    • getFirstInstances

      protected List<String> getFirstInstances(KB kb, String term)
      Returns a List of the entities that are immediate instances of term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF Class
      Returns:
      A List of SUO-KIF terms, or an empty List
    • getFirstContainingClass

      protected String getFirstContainingClass(KB kb, String term)
      Returns a SUO-KIF constant that denotes the first containing Class of term obtained in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      A String that denotes a SUO-KIF Class, or null
    • getFirstSubClasses

      protected List<String> getFirstSubClasses(KB kb, String term)
      Returns a List containing the immediate SUO-KIF subclasses of term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      A List of SUO-KIF Classes, or an empty List
    • createDocs

      protected String createDocs(KB kb, String kbHref, String term, String language)
      Returns a String consisting of HTML markup for a documentation String for term obtained from kb and indexed by language.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes documentation Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createComments

      protected String createComments(KB kb, String kbHref, String term, String language)
      Returns a String containing the HTML markup for the Comment field in a page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes comment Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createSynonyms

      protected String createSynonyms(KB kb, String kbHref, String term, String formatToken)
      Returns a String containing HTML markup for the synonym field of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createDisplayNames

      protected String createDisplayNames(KB kb, String kbHref, String term, String formatToken)
      Returns a String containing HTML markup for the Display Labels field of an HTML page displaying statements about term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      formatToken - A String token that partly determines the format of the output
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createHasSameComponents

      protected String createHasSameComponents(KB kb, String kbHref, String term, String language)
      Returns a String containing HTML markup for the Has Same Components As field of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createUsingSameComponents

      protected String createUsingSameComponents(KB kb, String kbHref, String term, String language)
      Returns a String containing HTML markup for the Composites Using Same Components field of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createParents

      protected String createParents(KB kb, String kbHref, String term, String language, Set parentsSet)
      Returns a String containing HTML markup for the Parents field of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      parentsSet - A Set for accumulating the parent terms of term
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createChildren

      protected String createChildren(KB kb, String kbHref, String term, String language)
      Returns a String containing HTML markup for the Children field of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createInstances

      protected String createInstances(KB kb, String kbHref, String term, String language, List excluded)
      Returns a String containing HTML markup for the Instances section of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      excluded - A List of terms to be excluded from the display
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • createFormula

      protected String createFormula(KB kb, String kbHref, String indentSeq, int level, String previousTerm, String currentTerm, String context)
      Returns a String containing HTML markup for a SUO-KIF Formula.
      Parameters:
      kb - The KB in which formula occurs
      kbHref - A String containing the constant parts of the href link for the constants in formula, or an empty String
      indentSeq - A character sequence that will be used as the indentation quantum for formula
      level - The current indentation level
      previousTerm - A String, the term that occurs sequentially before currentTerm in the same level of nesting. The value of previousTerm aids in determining how a given Formula should be formatted, and could be null.
      currentTerm - A String denoting a SUO-KIF Formula or part of a Formula
      context - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if formula cannot be processed
    • createRelations

      protected String createRelations(KB kb, String kbHref, String term, String language, String formatToken)
      Returns a String containing HTML markup for the Relations section of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • showCardinalityCell

      protected String showCardinalityCell(KB kb, String kbHref, String term, String context)
      Returns a String containing HTML markup for the Cardinality field of an HTML page displaying the definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      context - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb -- this parameter is currently ignored, since LocalInstance terms are already highly specific
      Returns:
      A String containing HTML markup, or an empty String if no markup can be generated
    • createCompositeComponentLine

      protected String createCompositeComponentLine(KB kb, String kbHref, String term, int indent, String language)
      Returns a String containing HTML markup for a single table row in the Composite Component section of an HTML page displaying the partial definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      indent - A int value that determines the depth to which term will be indented when displayed
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if term is supposed to be suppressed for display
    • showTermName

      public String showTermName(KB kb, String term, String language)
      Returns the termFormat entry for term in kb and language, otherwise returns the termFormat entry for term in English, otherwise just returns the term name.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or another type of entity that contextualizes or indexes termFormat Strings in kb
      Returns:
      A String providing a context-specific name for term, possibly including HTML markup, or just term if no context-specific form can be found or produced
    • formatCompositeHierarchy

      protected String formatCompositeHierarchy(KB kb, String kbHref, List hier, String language)
      Returns a String containing HTML markup for a hierarchy or tree display of terms that denote nested composite components.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      hier - A List containing term names and representing one sub-branch in a tree
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if no markup can be generated
    • createCompositeRecurse

      protected List createCompositeRecurse(KB kb, String term, boolean isAttribute, int indent)
      Recursively computes and then returns a List that constitutes the graph containing those XML elements and attributes syntactically subordinate to term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      isAttribute - If true, this parameter indicates that term denotes an XML attribute
      indent - An integer indicating the depth or level to which term should be indented when displayed
      Returns:
      A List containing two Lists, the first of which is a List of terms that denote XML attributes, and the second of which is a list of terms that denote XML elements
    • isXmlAttribute

      protected boolean isXmlAttribute(KB kb, String term)
      Returns a List that constitutes the graph containing those XML elements and attributes syntactically subordinate to term in kb.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      A String containing HTML markup, or an empty String if no markup can be generated
    • createContainingCompositeComponentLine

      protected String createContainingCompositeComponentLine(KB kb, String kbHref, String containingComp, String instance, int indent, String language)
      Returns a String containing HTML markup for a row displaying a contained component in an HTML page displaying the partial definition of instance in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      containingComp - A String that denotes the term that contains, or is syntactically superordinate to, instance
      instance - A String that denotes a SUO-KIF term
      indent - An int value that determines the depth to which instance will be indented when displayed
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if no markup can be generated
    • formatContainingComposites

      protected String formatContainingComposites(KB kb, String kbHref, List containing, String composite, String language)
      Given the SUO-KIF statements: (hasXmlElement PartyDescriptor LocalInstance_2_459) (datatype LocalInstance_2_459 PartyId) (documentation LocalInstance_2_459 PartyDescriptor "A Composite containing details...") show PartyDescriptor as one of the "containing composites" of PartyId, and show the documentation for the instance node next to the parent composite.
    • isSkipNode

      protected static boolean isSkipNode(KB kb, String term)
      Returns true if term should be skipped over during printing, else returns false.
    • getContainingComposites

      protected List getContainingComposites(KB kb, String term)
      Travels up the HasXmlElement and HasXmlAttribute relation hierarchies to collect all parents, and returns them in an ArrayList.
      Returns:
      An ArrayList of terms, which could be empty
    • createBelongsToClass

      protected String createBelongsToClass(KB kb, String kbHref, String term, String language, Set<String> parents)
      Returns a String containing HTML markup for the Belongs to Class section of an HTML page displaying the partial definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      parents - A Set containing the terms displayed in the Parent field for term, to avoid duplication between the Parents field and the Belongs to Class field
      Returns:
      A String containing HTML markup, or an empty String if no markup can be generated
    • createBelongsToClass

      protected String createBelongsToClass(KB kb, String kbHref, String term, String language)
      Returns a String containing HTML markup for the Belongs to Class section of an HTML page displaying the partial definition of term in kb.
      Parameters:
      kb - The KB in which term is defined
      kbHref - A String containing the constant parts of the href link for term, or an empty String
      term - A String that denotes a SUO-KIF term
      language - A String denoting a SUO-KIF namespace, a natural language, or other type of entity that indexes termFormat Strings in kb
      Returns:
      A String containing HTML markup, or an empty String if no markup can be generated
    • findContainingComposites

      protected List findContainingComposites(KB kb, String term)
      Returns an ArrayList holding the composite entities (Elements) that contain term, or returns an empty ArrayList.
      Parameters:
      kb - The KB in which term is defined
      term - A String that denotes a SUO-KIF term
      Returns:
      An ArrayList containing the names of the Elements that contain term.
    • createAllStatements

      public String createAllStatements(KB kb, String kbHref, String term, int limit)
      Create an HTML page that lists information about a particular term, with a limit on how many statements of each type should be displayed.
    • generateDynamicTOCHeader

      public String generateDynamicTOCHeader(String kbHref)
      Generate an alphabetic HTML list that points to the individual index pages (which collect all terms starting with a particular letter.
    • generateTocHeader

      protected String generateTocHeader(KB kb, Map<String,Map<String,List<String>>> alphaList, String allname)
      Generate an alphabetic HTML list that points to the individual index pages (which collect all terms or term formats) starting with a particular letter.
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists. @see createAlphaList()
    • generateTOCPage

      protected String generateTOCPage(KB kb, String firstLetter, Map<String,Map<String,List<String>>> alphaList, String language)
      Generate an HTML page that lists term name and its documentation
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists. @see createAlphaList()
    • saveIndexPages

      protected void saveIndexPages(KB kb, Map<String,Map<String,List<String>>> alphaList, String dir, String language)
      Generate and save all the index pages that link to the individual term pages.
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists. @see createAlphaList()
      dir - is the directory in which to save the pages
    • printHTMLPages

      protected void printHTMLPages(Map<String,String> pageList, String dirpath)
      Save pages below the KBs directory in a directory called HTML. If that already exists, use HTML1, HTML2 etc.
    • makeOutputDir

      protected File makeOutputDir(String token)
      Creates a subdirectory of SIGMA_HOME/files/, in which output files of the type specified by token are saved. token is also used, along with the value returned by this.getKB() and the current date, to create the directory name. Returns a File object representing the canonical pathname of the directory.
      Parameters:
      token - A token that indicates a type of output file
      Returns:
      A File representing a directory
    • generateHTMLPages

      protected Map<String,String> generateHTMLPages(KB kb, Map<String,Map<String,List<String>>> alphaList, String language, String formatToken)
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists. @see createAlphaList()
    • generateHTML

      public void generateHTML(KB kb, String language, boolean simplified, String formatToken)
      Generate simplified HTML pages for all terms. Output is a set of HTML files sent to the directory specified in makeOutputDir()
      Parameters:
      simplified - Indicates whether to present a "simplified" view of terms, meaning using a termFormat or headword, rather than the term name itself
    • generateSingleHTML

      public void generateSingleHTML(KB kb, String dir, Map<String,Map<String,List<String>>> alphaList, String language, boolean simplified)
      Generate a single HTML page showing all terms.
      Parameters:
      alphaList - a TreeMap of TreeMaps of ArrayLists. letter-> formattedTerm1->term11,term12...term1N formattedTerm2->term21,term22...term2N
      simplified - Indicates whether to present a "simplified" view of terms, meaning using a termFormat or headword, rather than the term name itself
    • generateSingleHTML

      public void generateSingleHTML(KB kb, String language, boolean simplified) throws IOException
      Throws:
      IOException
    • getSubordinateAttributes

      protected List getSubordinateAttributes(KB kb, String kifTerm)
      Returns a List containing the subordinate XmlAttributes of kifTerm, else return an empty List.
    • getSubordinateElements

      protected List getSubordinateElements(KB kb, String kifTerm)
      Returns a List containing the subordinate XmlElements of kifTerm, else return an empty List.
    • getSyntacticExtensionTerms

      protected List getSyntacticExtensionTerms(KB kb, String term, int targetArgnum, boolean computeClosure)
    • getSyntacticUnionTerms

      protected List getSyntacticUnionTerms(KB kb, String term, int targetArgnum)
    • getSyntacticCompositeTerms

      protected List getSyntacticCompositeTerms(KB kb, String term, int targetArgnum)
    • getClosestXmlDataType

      protected String getClosestXmlDataType(KB kb, String term)
    • isInstanceOf

      protected static boolean isInstanceOf(KB kb, String i, String c)
      Returns true if i is an instance of c, else returns false.
      Parameters:
      kb - A KB object
      i - A String denoting an instance
      c - A String denoting a Class
      Returns:
      true or false
    • getFirstDatatype

      protected String getFirstDatatype(KB kb, String term)
    • getDatatypeTerms

      protected List getDatatypeTerms(KB kb, String term, int targetArgnum)
    • isDataType

      protected boolean isDataType(KB kb, String term)
    • getTermPresentationName

      public String getTermPresentationName(KB kb, String term)
    • getTermPresentationName

      public String getTermPresentationName(KB kb, String namespace, String term)
    • getTermPresentationName

      public String getTermPresentationName(KB kb, String namespace, String term, boolean withSpanTags)
    • sortByPresentationName

      public void sortByPresentationName(KB kb, String namespaceTerm, List<String> stringList)
      Sorts stringList in place by the presentation name of each its terms, which could be very different from the raw term name.
      Parameters:
      kb - The KB from which to obtain the presentation names
      namespaceTerm - A KIF term denoting a namespace
      stringList - The List of Strings to be sorted
    • sortByTermLength

      protected void sortByTermLength(List<String> terms)
      Sorts the List terms by the length of the Strings it contains, from longest to shortest.
    • getTermNamespace

      public String getTermNamespace(KB kb, String term)
    • processDocString

      protected String processDocString(KB kb, String kbHref, String namespace, String docString, boolean isXmlDoc, boolean addHrefs)
      Parameters:
      isXmlDoc - If true, HTML character entities will be replaced with their ASCII equivalents, when possible
      addHrefs - If true, HTML anchor markup will be added for recognized terms
    • writeToStream

      public static void writeToStream(List<String> data, OutputStream stream)
      Writes a List of Strings to an OutputStream.
      Parameters:
      data - A List of String objects
      stream - An OutputSteam object
    • emptyString

      public static boolean emptyString(String s)
    • isNonEmptyString

      public static boolean isNonEmptyString(String s)
    • readSpreadsheetFile

      public List<List<String>> readSpreadsheetFile(String inpath, char delimiter)
    • readSpreadsheetFile

      public List<List<String>> readSpreadsheetFile(String inpath, char delimiter, int delimitersPerRow, List<String> rowFlags)
      Parses a file of delimited fields into an ArrayList of ArrayLists. If rowFlags contains any Strings, the method concatenates sequential lines that do not start with one of the Strings, else rowFlags is ignored.
      Parameters:
      delimiter - A char that delimits each field in a row
      delimitersPerRow - An int that indicates the number of expected delimiter chars per row
      rowFlags - A List of the tokens (Strings) that indicate the start of a new row
      Returns:
      An ArrayList of ArrayLists
    • convertRowStringsToLists

      protected List<List<String>> convertRowStringsToLists(List<String> rows, char delimiter)
      Converts a List of char-delimited Strings to a List of Lists (i.e., an array) representing a spreadsheet.
      Parameters:
      rows - A List of char-delimited Strings. The list is processed in place, and will contain only Lists when processing is finished.
      delimiter - A char that delimits each field in line.
      Returns:
      void
    • countDelimiters

      protected int countDelimiters(String line, char delimiter)
      Counts the number of field delimiters in line and returns the count, ignoring delimiters that are inside Strings.
      Parameters:
      line - A line of data fields that are separated by occurrences of a delimiter char.
      delimiter - A char that delimits each field in line.
      Returns:
      An int indicating the number of delimiters in line.
    • main

      public static void main(String[] args)