org.opencyc.xml
Class ExportHtml

java.lang.Object
  |
  +--org.opencyc.xml.ExportHtml

public class ExportHtml
extends java.lang.Object

HTML ontology export for OpenCyc.

Author:
Stephen L. Reed

Copyright 2001 Cycorp, Inc., license is open source GNU LGPL.

the license

www.opencyc.org

OpenCyc at SourceForge

THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Field Summary
static Guid counterTerrorismConstantGuid
          The #$CounterTerrorismConstant guid.
protected  CycAccess cycAccess
          Manages connection to the cyc server api.
 CycFort cycKbSubsetCollection
          The CycKBSubsetCollection whose elements are exported to HTML.
 Guid cycKbSubsetCollectionGuid
          The CycKBSubsetCollection whose elements are exported to HTML.
protected  CycFort cycKbSubsetFilter
          The CycKBSubsetCollection whose elements are exported to HTML if they also generalizations of cycKbSubsetCollectionGuid collections or predicates above.
 Guid cycKbSubsetFilterGuid
          The guid which identifies the CycKBSubsetCollection whose elements are exported to HTML if they also generalizations of cycKbSubsetCollectionGuid collections or predicates above.
protected  CycConstant cycLConstant
           
static Guid cycLConstantGuid
          The #$CycLConstant guid.
protected static int DEFAULT_VERBOSITY
          The default verbosity of the HTML export output.
static Guid eeldSharedOntologyConstantGuid
          The #$EELDSharedOntologyConstant guid.
static Guid eeldSharedOntologyCoreConstantGuid
          The #$EELDSharedOntologyCoreConstant guid.
static int EXPORT_KB_SUBSET
          Command indicating that the HTML export contains only the marked KB subset terms.
static int EXPORT_KB_SUBSET_BELOW_TERM
          Command indicating that the HTML export contains the collections whose direct or indirect genl is the collection term indentified by rootTermGuid.
static int EXPORT_KB_SUBSET_PLUS_UPWARD_CLOSURE
          Command indicating that the HTML export contains the marked KB subset terms plus all the terms in the upward closure to #$Thing.
protected  int exportCommand
          The command performed by the HTML extract process.
 java.lang.String exportedHierarchyOutputPath
          The HTML exported hierarchy path and file name.
 java.lang.String exportedVocabularyOutputPath
          The HTML exported vocabulary path and file name.
protected  boolean hasComment
          Indicates the presence of a comment for the current term.
protected  org.w3c.dom.Element htmlBodyElement
          the HTML body element
protected  org.w3c.dom.html.HTMLDocument htmlDocument
          the html document
static Guid ikbConstantGuid
          The #$IKBConstant guid.
 boolean includeUpwardClosure
          Indicates whether the upward closure of terms should be exported.
protected  java.util.HashSet previouslyExpandedTerms
          indicates which terms have been previously expanded in the hierarchy page
 CycFort rootTerm
          Used in the export command EXPORT_KB_SUBSET_BELOW_TERM.
 Guid rootTermGuid
          Used in the export command EXPORT_KB_SUBSET_BELOW_TERM.
protected  CycList selectedCycForts
          the selected terms
 int verbosity
          Sets verbosity of the HTML export output.
 
Constructor Summary
ExportHtml()
          Constructs a new ExportHtml object.
 
Method Summary
protected  void createCollectionNode(CycConstant cycConstant, org.w3c.dom.Element parentElement)
          Creates an HTML node for a single Cyc collection.
protected  void createCommentNodes(CycConstant cycConstant, org.w3c.dom.Element parentElement)
          Creates HTML nodes for comment text containing CycConstants which are to be represented as hyperlinks.
protected  void createCycConstantNode(CycConstant cycConstant)
          Creates a HTML node for a single Cyc Constant.
protected  void createCycNartNode(CycNart cycNart)
          Creates a HTML node for a single Cyc Nart.
protected  void createGenlNodes(CycFort cycFort, org.w3c.dom.Element parentElement)
          Creates HTML nodes for genl links.
protected  void createGenlPredsNodes(CycConstant cycConstant, org.w3c.dom.Element parentElement)
          Creates HTML nodes for genlPreds links.
protected  void createGuidNode(CycConstant cycConstant, org.w3c.dom.Element parentElement)
          Creates HTML node for guid.
protected  void createHierarchyNodes(CycFort cycFort, int indent)
          Recursively creates hierarchy nodes for the given term and its spec collection terms.
protected  void createHierarchyPage(CycFort rootTerm)
          Creates hierarchy HTML page.
protected  void createIndividualNode(CycConstant cycConstant, org.w3c.dom.Element parentElement)
          Creates an HTML individual node for a single Cyc individual.
protected  void createIsaNodes(CycFort cycFort, org.w3c.dom.Element parentElement)
          Creates HTML nodes for isa links.
protected  void createPredicateNode(CycConstant cycConstant, org.w3c.dom.Element parentElement)
          Creates an HTML node for a single Cyc predicate.
protected  void createVocabularyPage()
          Creates vocabulary HTML page.
 void export(int exportCommand)
          Exports the desired KB content into HTML.
protected  CycList filterSelectedConstants(CycList constants)
          Removes unselected terms from the given list.
protected  CycFort findSelectedGenls(CycFort collection)
          Returns the first indirect genls above the given term which is a member of the selected terms.
protected  CycList gatherUpwardClosure(CycList selectedCycForts)
          Gather the updward closure of the selected CycForts with regard to isas and genls for collection terms, and with regard to isas and genlPreds for predicate terms.
protected  void horizontalRule()
          Creates a horizontal rule in the HTML document.
protected  org.w3c.dom.Element italics(org.w3c.dom.Element parentElement)
          Creates an italics element in the HTML document.
protected  void lineBreak(org.w3c.dom.Element parentElement)
          Creates a line break in the HTML document.
static void main(java.lang.String[] args)
          Runs the ExportHtml application.
protected  void paragraphBreak()
          Creates a paragraph break in the HTML document.
protected  void serialize(org.w3c.dom.html.HTMLDocument htmlDocument, java.lang.String outputPath)
          Serializes the given HTML document to the given path.
protected  void setup()
          Sets up the HTML export process.
protected  CycList specificCollections(CycList collections)
          Given a set of collection terms, returns a set which does not contain any collections are more genl than the remaining collections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPORT_KB_SUBSET

public static final int EXPORT_KB_SUBSET
Command indicating that the HTML export contains only the marked KB subset terms. cycKbSubsetCollectionGuid contains the KB subset collection's guid. cycKbSubsetFilterGuid contains the guid for the KB subset term that filters membership in the upward closure.

EXPORT_KB_SUBSET_PLUS_UPWARD_CLOSURE

public static final int EXPORT_KB_SUBSET_PLUS_UPWARD_CLOSURE
Command indicating that the HTML export contains the marked KB subset terms plus all the terms in the upward closure to #$Thing. cycKbSubsetCollectionGuid contains the KB subset collection's guid.

EXPORT_KB_SUBSET_BELOW_TERM

public static final int EXPORT_KB_SUBSET_BELOW_TERM
Command indicating that the HTML export contains the collections whose direct or indirect genl is the collection term indentified by rootTermGuid. cycKbSubsetFilterGuid contains the guid for the KB subset term that filters membership in the export set.

exportCommand

protected int exportCommand
The command performed by the HTML extract process.

DEFAULT_VERBOSITY

protected static final int DEFAULT_VERBOSITY
The default verbosity of the HTML export output. 0 --> quiet ... 9 -> maximum diagnostic input.

verbosity

public int verbosity
Sets verbosity of the HTML export output. 0 --> quiet ... 9 -> maximum diagnostic input.

includeUpwardClosure

public boolean includeUpwardClosure
Indicates whether the upward closure of terms should be exported. If so, the upward closure terms are filtered by cycKbSubsetFilterGuid below.

cycKbSubsetCollection

public CycFort cycKbSubsetCollection
The CycKBSubsetCollection whose elements are exported to HTML.

eeldSharedOntologyConstantGuid

public static final Guid eeldSharedOntologyConstantGuid
The #$EELDSharedOntologyConstant guid.

eeldSharedOntologyCoreConstantGuid

public static final Guid eeldSharedOntologyCoreConstantGuid
The #$EELDSharedOntologyCoreConstant guid.

counterTerrorismConstantGuid

public static final Guid counterTerrorismConstantGuid
The #$CounterTerrorismConstant guid.

ikbConstantGuid

public static final Guid ikbConstantGuid
The #$IKBConstant guid.

cycLConstantGuid

public static final Guid cycLConstantGuid
The #$CycLConstant guid.

cycLConstant

protected CycConstant cycLConstant

cycKbSubsetCollectionGuid

public Guid cycKbSubsetCollectionGuid
The CycKBSubsetCollection whose elements are exported to HTML.

cycKbSubsetFilterGuid

public Guid cycKbSubsetFilterGuid
The guid which identifies the CycKBSubsetCollection whose elements are exported to HTML if they also generalizations of cycKbSubsetCollectionGuid collections or predicates above. #$IKBConstant (not in OpenCyc)

cycKbSubsetFilter

protected CycFort cycKbSubsetFilter
The CycKBSubsetCollection whose elements are exported to HTML if they also generalizations of cycKbSubsetCollectionGuid collections or predicates above. #$IKBConstant (not in OpenCyc)

rootTermGuid

public Guid rootTermGuid
Used in the export command EXPORT_KB_SUBSET_BELOW_TERM. The HTML export contains the collections whose direct or indirect genl is the collection term indentified by this value.

rootTerm

public CycFort rootTerm
Used in the export command EXPORT_KB_SUBSET_BELOW_TERM. The HTML export contains the collections whose direct or indirect genl is this collection term.

exportedVocabularyOutputPath

public java.lang.String exportedVocabularyOutputPath
The HTML exported vocabulary path and file name.

exportedHierarchyOutputPath

public java.lang.String exportedHierarchyOutputPath
The HTML exported hierarchy path and file name.

htmlDocument

protected org.w3c.dom.html.HTMLDocument htmlDocument
the html document

cycAccess

protected CycAccess cycAccess
Manages connection to the cyc server api.

htmlBodyElement

protected org.w3c.dom.Element htmlBodyElement
the HTML body element

selectedCycForts

protected CycList selectedCycForts
the selected terms

hasComment

protected boolean hasComment
Indicates the presence of a comment for the current term.

previouslyExpandedTerms

protected java.util.HashSet previouslyExpandedTerms
indicates which terms have been previously expanded in the hierarchy page
Constructor Detail

ExportHtml

public ExportHtml()
Constructs a new ExportHtml object.
Method Detail

main

public static void main(java.lang.String[] args)
Runs the ExportHtml application.
Parameters:
args - the command line arguments.

export

public void export(int exportCommand)
            throws java.net.UnknownHostException,
                   java.io.IOException,
                   CycApiException
Exports the desired KB content into HTML.

setup

protected void setup()
              throws java.net.UnknownHostException,
                     java.io.IOException,
                     CycApiException
Sets up the HTML export process.

createVocabularyPage

protected void createVocabularyPage()
                             throws java.net.UnknownHostException,
                                    java.io.IOException,
                                    CycApiException
Creates vocabulary HTML page.

createCycNartNode

protected void createCycNartNode(CycNart cycNart)
                          throws java.net.UnknownHostException,
                                 java.io.IOException,
                                 CycApiException
Creates a HTML node for a single Cyc Nart.

createCycConstantNode

protected void createCycConstantNode(CycConstant cycConstant)
                              throws java.net.UnknownHostException,
                                     java.io.IOException,
                                     CycApiException
Creates a HTML node for a single Cyc Constant.

paragraphBreak

protected void paragraphBreak()
Creates a paragraph break in the HTML document.

italics

protected org.w3c.dom.Element italics(org.w3c.dom.Element parentElement)
Creates an italics element in the HTML document.
Parameters:
parentElement - the parent HTML DOM element
Returns:
the italics element

lineBreak

protected void lineBreak(org.w3c.dom.Element parentElement)
Creates a line break in the HTML document.
Parameters:
parentElement - the parent HTML DOM element

horizontalRule

protected void horizontalRule()
Creates a horizontal rule in the HTML document.

createCommentNodes

protected void createCommentNodes(CycConstant cycConstant,
                                  org.w3c.dom.Element parentElement)
                           throws java.io.IOException,
                                  CycApiException
Creates HTML nodes for comment text containing CycConstants which are to be represented as hyperlinks.
Parameters:
cycConstant - the CycConstant for which isa links are to be created
parentElement - the parent HTML DOM element

createGuidNode

protected void createGuidNode(CycConstant cycConstant,
                              org.w3c.dom.Element parentElement)
                       throws java.io.IOException,
                              CycApiException
Creates HTML node for guid.
Parameters:
cycConstant - the CycConstant for which isa links are to be created
parentElement - the parent HTML DOM element

createIsaNodes

protected void createIsaNodes(CycFort cycFort,
                              org.w3c.dom.Element parentElement)
                       throws java.io.IOException,
                              CycApiException
Creates HTML nodes for isa links.
Parameters:
cycConstant - the CycConstant for which isa links are to be created
parentElement - the parent HTML DOM element

findSelectedGenls

protected CycFort findSelectedGenls(CycFort collection)
                             throws java.io.IOException,
                                    CycApiException
Returns the first indirect genls above the given term which is a member of the selected terms.
Parameters:
collection - the cyc collection which is not a member of the selected terms.
Returns:
the first indirect genls above the given term which is a member of the selected terms

createGenlNodes

protected void createGenlNodes(CycFort cycFort,
                               org.w3c.dom.Element parentElement)
                        throws java.io.IOException,
                               CycApiException
Creates HTML nodes for genl links.
Parameters:
cycConstant - the CycConstant for which genl links are to be created
parentElement - the parent HTML DOM element

specificCollections

protected CycList specificCollections(CycList collections)
                               throws java.io.IOException,
                                      CycApiException
Given a set of collection terms, returns a set which does not contain any collections are more genl than the remaining collections.
Parameters:
collections - the given set of collection terms
Returns:
a set of collection terms which does not contain any collections are more genl than the remaining collections.

createGenlPredsNodes

protected void createGenlPredsNodes(CycConstant cycConstant,
                                    org.w3c.dom.Element parentElement)
                             throws java.io.IOException,
                                    CycApiException
Creates HTML nodes for genlPreds links.
Parameters:
cycConstant - the CycConstant for which genlPreds links are to be created
parentElement - the parent HTML DOM element

createIndividualNode

protected void createIndividualNode(CycConstant cycConstant,
                                    org.w3c.dom.Element parentElement)
                             throws java.net.UnknownHostException,
                                    java.io.IOException,
                                    CycApiException
Creates an HTML individual node for a single Cyc individual.
Parameters:
parentElement - the parent HTML DOM element

createCollectionNode

protected void createCollectionNode(CycConstant cycConstant,
                                    org.w3c.dom.Element parentElement)
                             throws java.net.UnknownHostException,
                                    java.io.IOException,
                                    CycApiException
Creates an HTML node for a single Cyc collection.
Parameters:
parentElement - the parent HTML DOM element

createPredicateNode

protected void createPredicateNode(CycConstant cycConstant,
                                   org.w3c.dom.Element parentElement)
                            throws java.net.UnknownHostException,
                                   java.io.IOException,
                                   CycApiException
Creates an HTML node for a single Cyc predicate.
Parameters:
parentElement - the parent HTML DOM element

createHierarchyPage

protected void createHierarchyPage(CycFort rootTerm)
                            throws java.net.UnknownHostException,
                                   java.io.IOException,
                                   CycApiException
Creates hierarchy HTML page.
Parameters:
rootTerm - the root term of the hierarchy tree

createHierarchyNodes

protected void createHierarchyNodes(CycFort cycFort,
                                    int indent)
                             throws java.io.IOException,
                                    CycApiException
Recursively creates hierarchy nodes for the given term and its spec collection terms.
Parameters:
cycFort - the given term for which hierarchy nodes will be created
indent - the current indent level

serialize

protected void serialize(org.w3c.dom.html.HTMLDocument htmlDocument,
                         java.lang.String outputPath)
                  throws java.io.IOException
Serializes the given HTML document to the given path.
Parameters:
htmlDocument - the HTML document model for serialization
outputPath - the file name of the serialized HTML document

filterSelectedConstants

protected CycList filterSelectedConstants(CycList constants)
Removes unselected terms from the given list.
Returns:
the filtered list

gatherUpwardClosure

protected CycList gatherUpwardClosure(CycList selectedCycForts)
                               throws java.net.UnknownHostException,
                                      java.io.IOException,
                                      CycApiException
Gather the updward closure of the selected CycForts with regard to isas and genls for collection terms, and with regard to isas and genlPreds for predicate terms.
Returns:
the updward closure of the selected CycForts with regard to genls for collection terms, and with regard to genlPreds for predicate terms