org.opencyc.api
Class CycObjectFactory

java.lang.Object
  |
  +--org.opencyc.api.CycObjectFactory

public class CycObjectFactory
extends java.lang.Object

Provides the way to create cyc objects and reuse previously cached instances.
All methods are static.

Collaborates with the CycConnection class which manages the api connections.

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
protected static org.apache.oro.util.Cache assertionCache
          Least Recently Used Cache of CycAssertions, so that a reference to an existing CycAssertion is returned instead of constructing a duplicate.
static CycSymbol backquote
           
static CycSymbol cons
           
protected static org.apache.oro.util.Cache cycConstantCacheByGuid
          Least Recently Used Cache of CycConstants, so that a reference to an existing CycConstant is returned instead of constructing a duplicate.
protected static org.apache.oro.util.Cache cycConstantCacheById
          Least Recently Used Cache of CycConstants, so that a reference to an existing CycConstant is returned instead of constructing a duplicate.
protected static org.apache.oro.util.Cache cycConstantCacheByName
          Least Recently Used Cache of CycConstants, so that a reference to an existing CycConstant is returned instead of constructing a duplicate.
protected static org.apache.oro.util.Cache cycNartCache
          Least Recently Used Cache of CycNarts, so that a reference to an existing CycNart is returned instead of constructing a duplicate.
protected static org.apache.oro.util.Cache cycSymbolCache
          Least Recently Used Cache of CycSymbols, so that a reference to an existing CycSymbol is returned instead of constructing a duplicate.
protected static org.apache.oro.util.Cache cycVariableCache
          Least Recently Used Cache of CycVariables, so that a reference to an existing CycVariable is returned instead of constructing a duplicate.
static CycSymbol dot
           
static CycList END_CYC_CONNECTION
          The api command which is intercepted by the CycProxy agent to close the CycAccess object associated with the connection between this agent and the particular cyc image.
protected static org.apache.oro.util.Cache guidCache
          Least Recently Used Cache of guids, so that a reference to an existing Guid is returned instead of constructing a duplicate.
static CycSymbol nil
           
static CycSymbol quote
           
protected static int suffix
          A variable name suffix used to make unique names.
static CycSymbol t
          Built in CycSymbols.
 
Constructor Summary
CycObjectFactory()
           
 
Method Summary
static void addAssertionCache(CycAssertion cycAssertion)
          Adds the CycAssertion to the cache.
static void addCycConstantCacheByGuid(CycConstant cycConstant)
          Adds the CycConstant to the cache by guid.
static void addCycConstantCacheById(CycConstant cycConstant)
          Adds the CycConstant to the cyc contstant cache by id.
static void addCycConstantCacheByName(CycConstant cycConstant)
          Adds the CycConstant to the cache by name.
static void addCycNartCache(CycNart cycNart)
          Adds the CycNart to the cache.
static void addCycVariableCache(CycVariable cycVariable)
          Adds the CycVariable to the cache.
static void addGuidCache(Guid guid)
          Adds the Guid to the cache.
static CycAssertion getAssertionCache(java.lang.Integer id)
          Retrieves the CycAssertion with id, returning null if not found in the cache.
static int getAssertionCacheSize()
          Returns the size of the CycAssertion object cache.
static CycConstant getCycConstantCacheByGuid(Guid guid)
          Retrieves the CycConstant with guid, returning null if not found in the cache.
static CycConstant getCycConstantCacheById(java.lang.Integer id)
          Retrieves the CycConstant with id, returning null if not found in the cache.
static int getCycConstantCacheByIdSize()
          Returns the size of the CycConstant object cache by id.
static CycConstant getCycConstantCacheByName(java.lang.String name)
          Retrieves the CycConstant with name, returning null if not found in the cache.
static int getCycConstantCacheByNameSize()
          Returns the size of the CycConstant object cache by id.
static CycNart getCycNartCache(java.lang.Integer id)
          Retrieves the CycNart with name, returning null if not found in the cache.
static int getCycNartCacheSize()
          Returns the size of the CycNart object cache.
static CycSymbol getCycSymbolCache(java.lang.String symbolName)
          Retrieves the CycSymbol with symbolName, returning null if not found in the cache.
static int getCycSymbolCacheSize()
          Returns the size of the Guid object cache.
static CycVariable getCycVariableCache(java.lang.String name)
          Retrieves the CycVariable with name, returning null if not found in the cache.
static int getCycVariableCacheSize()
          Returns the size of the CycVariable object cache.
static Guid getGuidCache(java.lang.String guidName)
          Retrieves the Guid with guidName, returning null if not found in the cache.
static int getGuidCacheSize()
          Returns the size of the Guid object cache.
static CycSymbol makeCycSymbol(java.lang.String symbolNameAnyCase)
          Constructs a new CycSymbol object.
static CycVariable makeCycVariable(java.lang.String name)
          Constructs a new CycVariable object using the variable name.
static Guid makeGuid(java.lang.String guidString)
          Returns a cached Guid object or construct a new Guid object from a guid string if the guid is not found in the cache.
static CycVariable makeUniqueCycVariable(CycVariable modelCycVariable)
          Constructs a new CycVariable object by suffixing the given variable.
static void removeAssertionCache(java.lang.Integer id)
          Removes the CycAssertion from the cache if it is contained within.
static void removeCaches(CycConstant cycConstant)
          Removes the CycConstant from the caches if it is contained within.
static void removeCycNartCache(CycNart cycNart)
          Removes the CycNart from the cache if it is contained within.
static void removeCycSymbolCache(CycSymbol cycSymbol)
          Removes the CycSymbol from the cache if it is contained within.
static void removeCycVariableCache(CycVariable cycVariable)
          Removes the CycVariable from the cache if it is contained within.
static void removeGuidCache(Guid guid)
          Removes the Guid from the cache if it is contained within.
static void resetAssertionCache()
          Resets the Cyc assertion cache.
static void resetCycConstantCaches()
          Resets the Cyc constant caches.
static void resetCycNartCache()
          Resets the CycNart cache.
static void resetCycSymbolCache()
          Resets the CycSymbol cache.
static void resetCycVariableCache()
          Resets the CycVariable cache.
static void resetGuidCache()
          Resets the Guid cache.
static java.lang.Object unmarshall(java.lang.String xmlString)
          Unmarshalls a cyc object from an XML representation.
protected static ByteArray unmarshallByteArray(org.jdom.Element byteArrayElement, org.jdom.Document document)
          Unmarshalls a ByteArray from the given element in an XML Document object.
protected static CycAssertion unmarshallCycAssertion(org.jdom.Element cycAssertionElement)
          Unmarshalls a CycAssertion from the given element in an XML Document object.
protected static CycConstant unmarshallCycConstant(org.jdom.Element cycConstantElement, org.jdom.Document document)
          Unmarshalls a CycConstant from the given element in an XML Document object.
protected static CycList unmarshallCycList(org.jdom.Element cycListElement, org.jdom.Document document)
          Unmarshalls a CycList from the given element in an XML Document object.
protected static CycNart unmarshallCycNart(org.jdom.Element cycNartElement, org.jdom.Document document)
          Unmarshalls a CycNart from the given element in an XML Document object.
protected static CycSymbol unmarshallCycSymbol(org.jdom.Element cycSymbolElement)
          Unmarshalls a CycSymbol from the given element in an XML Document object.
protected static CycVariable unmarshallCycVariable(org.jdom.Element cycVariableElement)
          Unmarshalls a CycVariable from the given element in an XML Document object.
protected static java.lang.Object unmarshallElement(org.jdom.Element element, org.jdom.Document document)
          Unmarshalls a cyc object from the given element in an XML Document object.
protected static Guid unmarshallGuid(org.jdom.Element guidElement)
          Unmarshalls a Guid from the given element in an XML Document object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cycSymbolCache

protected static org.apache.oro.util.Cache cycSymbolCache
Least Recently Used Cache of CycSymbols, so that a reference to an existing CycSymbol is returned instead of constructing a duplicate.

t

public static CycSymbol t
Built in CycSymbols.

nil

public static CycSymbol nil

quote

public static CycSymbol quote

backquote

public static CycSymbol backquote

cons

public static CycSymbol cons

dot

public static CycSymbol dot

END_CYC_CONNECTION

public static final CycList END_CYC_CONNECTION
The api command which is intercepted by the CycProxy agent to close the CycAccess object associated with the connection between this agent and the particular cyc image.

cycConstantCacheByName

protected static org.apache.oro.util.Cache cycConstantCacheByName
Least Recently Used Cache of CycConstants, so that a reference to an existing CycConstant is returned instead of constructing a duplicate. Indexed via the name, so is optimised for the ascii api.

cycConstantCacheById

protected static org.apache.oro.util.Cache cycConstantCacheById
Least Recently Used Cache of CycConstants, so that a reference to an existing CycConstant is returned instead of constructing a duplicate. Indexed via the id, so is optimised for the binary api.

cycConstantCacheByGuid

protected static org.apache.oro.util.Cache cycConstantCacheByGuid
Least Recently Used Cache of CycConstants, so that a reference to an existing CycConstant is returned instead of constructing a duplicate. Indexed via the guid.

cycNartCache

protected static org.apache.oro.util.Cache cycNartCache
Least Recently Used Cache of CycNarts, so that a reference to an existing CycNart is returned instead of constructing a duplicate.

assertionCache

protected static org.apache.oro.util.Cache assertionCache
Least Recently Used Cache of CycAssertions, so that a reference to an existing CycAssertion is returned instead of constructing a duplicate.

cycVariableCache

protected static org.apache.oro.util.Cache cycVariableCache
Least Recently Used Cache of CycVariables, so that a reference to an existing CycVariable is returned instead of constructing a duplicate.

suffix

protected static int suffix
A variable name suffix used to make unique names.

guidCache

protected static org.apache.oro.util.Cache guidCache
Least Recently Used Cache of guids, so that a reference to an existing Guid is returned instead of constructing a duplicate.
Constructor Detail

CycObjectFactory

public CycObjectFactory()
Method Detail

makeCycSymbol

public static CycSymbol makeCycSymbol(java.lang.String symbolNameAnyCase)
Constructs a new CycSymbol object.
Parameters:
symbolName - a String name.

resetCycSymbolCache

public static void resetCycSymbolCache()
Resets the CycSymbol cache.

getCycSymbolCache

public static CycSymbol getCycSymbolCache(java.lang.String symbolName)
Retrieves the CycSymbol with symbolName, returning null if not found in the cache.
Returns:
a CycSymbol if found in the cache, otherwise null

removeCycSymbolCache

public static void removeCycSymbolCache(CycSymbol cycSymbol)
Removes the CycSymbol from the cache if it is contained within.

getCycSymbolCacheSize

public static int getCycSymbolCacheSize()
Returns the size of the Guid object cache.
Returns:
an int indicating the number of CycSymbol objects in the cache

resetCycConstantCaches

public static void resetCycConstantCaches()
Resets the Cyc constant caches.

addCycConstantCacheById

public static void addCycConstantCacheById(CycConstant cycConstant)
Adds the CycConstant to the cyc contstant cache by id.

addCycConstantCacheByName

public static void addCycConstantCacheByName(CycConstant cycConstant)
Adds the CycConstant to the cache by name.

addCycConstantCacheByGuid

public static void addCycConstantCacheByGuid(CycConstant cycConstant)
Adds the CycConstant to the cache by guid.

getCycConstantCacheById

public static CycConstant getCycConstantCacheById(java.lang.Integer id)
Retrieves the CycConstant with id, returning null if not found in the cache.

getCycConstantCacheByName

public static CycConstant getCycConstantCacheByName(java.lang.String name)
Retrieves the CycConstant with name, returning null if not found in the cache.

getCycConstantCacheByGuid

public static CycConstant getCycConstantCacheByGuid(Guid guid)
Retrieves the CycConstant with guid, returning null if not found in the cache.

removeCaches

public static void removeCaches(CycConstant cycConstant)
Removes the CycConstant from the caches if it is contained within.

getCycConstantCacheByIdSize

public static int getCycConstantCacheByIdSize()
Returns the size of the CycConstant object cache by id.
Returns:
an int indicating the number of CycConstant objects in the cache by id

getCycConstantCacheByNameSize

public static int getCycConstantCacheByNameSize()
Returns the size of the CycConstant object cache by id.
Returns:
an int indicating the number of CycConstant objects in the cache by id

resetCycNartCache

public static void resetCycNartCache()
Resets the CycNart cache.

addCycNartCache

public static void addCycNartCache(CycNart cycNart)
Adds the CycNart to the cache.

getCycNartCache

public static CycNart getCycNartCache(java.lang.Integer id)
Retrieves the CycNart with name, returning null if not found in the cache.

removeCycNartCache

public static void removeCycNartCache(CycNart cycNart)
Removes the CycNart from the cache if it is contained within.

getCycNartCacheSize

public static int getCycNartCacheSize()
Returns the size of the CycNart object cache.
Returns:
an int indicating the number of CycNart objects in the cache

resetAssertionCache

public static void resetAssertionCache()
Resets the Cyc assertion cache.

addAssertionCache

public static void addAssertionCache(CycAssertion cycAssertion)
Adds the CycAssertion to the cache.

getAssertionCache

public static CycAssertion getAssertionCache(java.lang.Integer id)
Retrieves the CycAssertion with id, returning null if not found in the cache.

removeAssertionCache

public static void removeAssertionCache(java.lang.Integer id)
Removes the CycAssertion from the cache if it is contained within.

getAssertionCacheSize

public static int getAssertionCacheSize()
Returns the size of the CycAssertion object cache.
Returns:
an int indicating the number of CycAssertion objects in the cache

makeCycVariable

public static CycVariable makeCycVariable(java.lang.String name)
Constructs a new CycVariable object using the variable name.
Parameters:
name - a String name.

makeUniqueCycVariable

public static CycVariable makeUniqueCycVariable(CycVariable modelCycVariable)
Constructs a new CycVariable object by suffixing the given variable.
Parameters:
modelCycVariable - a CycVariable to suffix

resetCycVariableCache

public static void resetCycVariableCache()
Resets the CycVariable cache.

addCycVariableCache

public static void addCycVariableCache(CycVariable cycVariable)
Adds the CycVariable to the cache.

getCycVariableCache

public static CycVariable getCycVariableCache(java.lang.String name)
Retrieves the CycVariable with name, returning null if not found in the cache.
Returns:
a CycVariable if found in the cache, otherwise null

removeCycVariableCache

public static void removeCycVariableCache(CycVariable cycVariable)
Removes the CycVariable from the cache if it is contained within.

getCycVariableCacheSize

public static int getCycVariableCacheSize()
Returns the size of the CycVariable object cache.
Returns:
an int indicating the number of CycVariable objects in the cache

makeGuid

public static Guid makeGuid(java.lang.String guidString)
Returns a cached Guid object or construct a new Guid object from a guid string if the guid is not found in the cache.
Parameters:
guid - a String form of a GUID.

addGuidCache

public static void addGuidCache(Guid guid)
Adds the Guid to the cache.

resetGuidCache

public static void resetGuidCache()
Resets the Guid cache.

getGuidCache

public static Guid getGuidCache(java.lang.String guidName)
Retrieves the Guid with guidName, returning null if not found in the cache.
Returns:
the Guid if it is found in the cache, otherwise null

removeGuidCache

public static void removeGuidCache(Guid guid)
Removes the Guid from the cache if it is contained within.

getGuidCacheSize

public static int getGuidCacheSize()
Returns the size of the Guid object cache.
Returns:
an int indicating the number of Guid objects in the cache

unmarshall

public static java.lang.Object unmarshall(java.lang.String xmlString)
                                   throws org.jdom.JDOMException,
                                          java.io.IOException
Unmarshalls a cyc object from an XML representation.
Parameters:
xmlString - the XML representation of the cyc object
Returns:
the cyc object

unmarshallElement

protected static java.lang.Object unmarshallElement(org.jdom.Element element,
                                                    org.jdom.Document document)
                                             throws java.io.IOException
Unmarshalls a cyc object from the given element in an XML Document object.
Parameters:
element - the element representing the cyc object
document - the XML document containing the element
Returns:
the cyc object

unmarshallGuid

protected static Guid unmarshallGuid(org.jdom.Element guidElement)
Unmarshalls a Guid from the given element in an XML Document object.
Parameters:
guidElement - the guid xml element
Returns:
the guid or cached reference to an existing guid object

unmarshallCycSymbol

protected static CycSymbol unmarshallCycSymbol(org.jdom.Element cycSymbolElement)
Unmarshalls a CycSymbol from the given element in an XML Document object.
Parameters:
cycSymbolElement - the CycSymbol xml element
Returns:
the CycSymbol or cached reference to an existing CycSymbol object

unmarshallCycAssertion

protected static CycAssertion unmarshallCycAssertion(org.jdom.Element cycAssertionElement)
Unmarshalls a CycAssertion from the given element in an XML Document object.
Parameters:
cycAssertionElement - the CycAssertion xml element
Returns:
the CycAssertion object

unmarshallCycVariable

protected static CycVariable unmarshallCycVariable(org.jdom.Element cycVariableElement)
Unmarshalls a CycVariable from the given element in an XML Document object.
Parameters:
cycVariableElement - the CycVariable xml element
Returns:
the CycVariable or cached reference to an existing CycVariable object

unmarshallCycConstant

protected static CycConstant unmarshallCycConstant(org.jdom.Element cycConstantElement,
                                                   org.jdom.Document document)
Unmarshalls a CycConstant from the given element in an XML Document object.
Parameters:
cycConstantElement - the element representing the CycConstant
document - the XML document containing the element
Returns:
the CycConstant

unmarshallCycNart

protected static CycNart unmarshallCycNart(org.jdom.Element cycNartElement,
                                           org.jdom.Document document)
                                    throws java.io.IOException
Unmarshalls a CycNart from the given element in an XML Document object.
Parameters:
cycNartElement - the element representing the CycNart
document - the XML document containing the element
Returns:
the CycNart

unmarshallCycList

protected static CycList unmarshallCycList(org.jdom.Element cycListElement,
                                           org.jdom.Document document)
                                    throws java.io.IOException
Unmarshalls a CycList from the given element in an XML Document object.
Parameters:
cycListElement - the element representing the CycList
document - the XML document containing the element
Returns:
the CycList

unmarshallByteArray

protected static ByteArray unmarshallByteArray(org.jdom.Element byteArrayElement,
                                               org.jdom.Document document)
                                        throws java.io.IOException
Unmarshalls a ByteArray from the given element in an XML Document object.
Parameters:
byteArrayElement - the element representing the CycList
document - the XML document containing the element
Returns:
the ByteArray