de.dfki.lt.hog.database
Class XMLDBAnnotationDatabase

java.lang.Object
  extended by de.dfki.lt.hog.database.AnnotationDatabase
      extended by de.dfki.lt.hog.database.XMLDBAnnotationDatabase

public class XMLDBAnnotationDatabase
extends AnnotationDatabase

The XML:DB-based database interface for the Deepthought annotation. This class uses concepts like session and document (identified via Strings and implemented as collections in the database) that are used to structure the Deepthought annotation database. In the Deepthought annotation database, a session comprises a collection of documents. A document itself is a collection (!) of XML annotations that are produced from different modules and can be accessed via annotation layer names.

For performance reasons, it is highly recommended to make use of the addIndex() method for every collection that is added.


Constructor Summary
XMLDBAnnotationDatabase()
          The method openDatabase() should be called after this empty constructor.
XMLDBAnnotationDatabase(java.lang.String databaseLocation)
           
 
Method Summary
 boolean addAnnotation(java.lang.String sessionID, java.lang.String docName, java.lang.String layerName, org.w3c.dom.Node domTree)
          Adds XML annotation (as DOM tree) for specified document.
 boolean addAnnotation(java.lang.String sessionID, java.lang.String docName, java.lang.String layerName, java.lang.String annotation)
          Adds XML annotation (as String) for the specified document.
 boolean addDocument(java.lang.String sessionID, java.lang.String docName)
          Adds a new, empty annotation collection for a document.
 boolean addIndex(java.lang.String sessionID, java.lang.String indexID, java.lang.String indexPattern)
          Adds an index to the annotation database.
 boolean addSession(java.lang.String sessionID)
          Adds a new session to the annotation database.
 boolean addSession(java.lang.String sessionID, org.w3c.dom.Node metaInfo)
          Adds a new session to the annotation database.
 boolean addSession(java.lang.String sessionID, java.lang.String metaInfo)
          Adds a new session to the annotation database.
 void closeDatabase()
          Closes the annotation database .
 boolean deleteDocument(java.lang.String sessionID, java.lang.String docName)
          delete an annotation collection for a document
 boolean deleteSession(java.lang.String sessionID)
          Deletes a session from the annotation database.
 org.w3c.dom.Node getAnnotationAsDOM(java.lang.String sessionID, java.lang.String docName, java.lang.String layerName)
          Returns the annotation for the specified document and layer as DOM tree.
 java.lang.String getAnnotationAsString(java.lang.String sessionID, java.lang.String docName, java.lang.String layerName)
          Returns the annotation for the specified document and layer as String.
 boolean openDatabase(java.lang.String connectString)
          Opens the annotation database.
 java.lang.String readFileFromDisk(java.io.File file, java.lang.String charset)
          Auxiliary method that reads an XML file into a String object.
 long XUpdateQuery(java.lang.String sessionID, java.lang.String query)
          Executes an XUpdate `query'.
 
Methods inherited from class de.dfki.lt.hog.database.AnnotationDatabase
getDatabaseLocation, setDatabaseLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLDBAnnotationDatabase

public XMLDBAnnotationDatabase()
The method openDatabase() should be called after this empty constructor.


XMLDBAnnotationDatabase

public XMLDBAnnotationDatabase(java.lang.String databaseLocation)
Parameters:
databaseLocation - an XML:DB URI like "xmldb:xindice://localhost:8080/db"
Method Detail

openDatabase

public boolean openDatabase(java.lang.String connectString)
Description copied from class: AnnotationDatabase
Opens the annotation database.

Specified by:
openDatabase in class AnnotationDatabase
Parameters:
connectString - optional connection String for the underlying database
Returns:
true iff successful

closeDatabase

public void closeDatabase()
Description copied from class: AnnotationDatabase
Closes the annotation database .

Specified by:
closeDatabase in class AnnotationDatabase

addSession

public boolean addSession(java.lang.String sessionID,
                          java.lang.String metaInfo)
Description copied from class: AnnotationDatabase
Adds a new session to the annotation database.

Specified by:
addSession in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
metaInfo - metainformation associated with the session (XML String)
Returns:
true iff successful

addSession

public boolean addSession(java.lang.String sessionID)
Description copied from class: AnnotationDatabase
Adds a new session to the annotation database.

Specified by:
addSession in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
Returns:
true iff successful

addSession

public boolean addSession(java.lang.String sessionID,
                          org.w3c.dom.Node metaInfo)
Description copied from class: AnnotationDatabase
Adds a new session to the annotation database.

Specified by:
addSession in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
metaInfo - metainformation associated with the session (DOM object)
Returns:
true iff successful

deleteSession

public boolean deleteSession(java.lang.String sessionID)
Description copied from class: AnnotationDatabase
Deletes a session from the annotation database.

Specified by:
deleteSession in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
Returns:
true iff successful

addDocument

public boolean addDocument(java.lang.String sessionID,
                           java.lang.String docName)
Adds a new, empty annotation collection for a document.

Specified by:
addDocument in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
docName - identifier of the added document (must be unique within the same session collection)
Returns:
true iff successful
See Also:
AnnotationDatabase.addDocument(java.lang.String, java.lang.String)

deleteDocument

public boolean deleteDocument(java.lang.String sessionID,
                              java.lang.String docName)
delete an annotation collection for a document

Specified by:
deleteDocument in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
docName - identifier of the document to be deleted
Returns:
true iff successful
See Also:
AnnotationDatabase.deleteDocument(java.lang.String, java.lang.String)

addAnnotation

public boolean addAnnotation(java.lang.String sessionID,
                             java.lang.String docName,
                             java.lang.String layerName,
                             java.lang.String annotation)
Description copied from class: AnnotationDatabase
Adds XML annotation (as String) for the specified document.

Specified by:
addAnnotation in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
docName - identifier of the document for which annotation is to be added
layerName - name of the layer type (such as Tokens, NamedEntities etc.) of the annotation
annotation - the XML annotation as String
Returns:
true iff successful

addAnnotation

public boolean addAnnotation(java.lang.String sessionID,
                             java.lang.String docName,
                             java.lang.String layerName,
                             org.w3c.dom.Node domTree)
Description copied from class: AnnotationDatabase
Adds XML annotation (as DOM tree) for specified document.

Specified by:
addAnnotation in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
docName - identifier of the document for which annotation is to be added
layerName - name of the layer type (such as Tokens, NamedEntities etc.) of the annotation
domTree - the XML annotation as DOM object
Returns:
true iff successful

getAnnotationAsString

public java.lang.String getAnnotationAsString(java.lang.String sessionID,
                                              java.lang.String docName,
                                              java.lang.String layerName)
Description copied from class: AnnotationDatabase
Returns the annotation for the specified document and layer as String.

Specified by:
getAnnotationAsString in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
docName - identifier of the document for which annotation is to be added
layerName - name of the layer type (such as Tokens, NamedEntities etc.) of the annotation
Returns:
annotation as string

getAnnotationAsDOM

public org.w3c.dom.Node getAnnotationAsDOM(java.lang.String sessionID,
                                           java.lang.String docName,
                                           java.lang.String layerName)
Description copied from class: AnnotationDatabase
Returns the annotation for the specified document and layer as DOM tree.

Specified by:
getAnnotationAsDOM in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
docName - identifier of the document for which annotation is to be retrieved
layerName - name of the layer type (such as Tokens, NamedEntities etc.) of the annotation
Returns:
annotation as DOM object

XUpdateQuery

public long XUpdateQuery(java.lang.String sessionID,
                         java.lang.String query)
Description copied from class: AnnotationDatabase
Executes an XUpdate `query'. For details and syntax of XUpdate see http://xmldb.org/xupdate and http://xml.apache.org/xindice.

Specified by:
XUpdateQuery in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
query - the XUpdate query (XML syntax) as String
Returns:
number of updated entries

addIndex

public boolean addIndex(java.lang.String sessionID,
                        java.lang.String indexID,
                        java.lang.String indexPattern)
Description copied from class: AnnotationDatabase
Adds an index to the annotation database.

Specified by:
addIndex in class AnnotationDatabase
Parameters:
sessionID - the session Identifier (single token starting with a non-numerical character)
indexID - name of the index (must be unique within a collection)
indexPattern - pattern for the indexer to be generated
Returns:
true iff successful

readFileFromDisk

public java.lang.String readFileFromDisk(java.io.File file,
                                         java.lang.String charset)
                                  throws java.io.IOException
Auxiliary method that reads an XML file into a String object.

Parameters:
file - The file to be opened
Returns:
String XML String with default encoding assumed (!)
Throws:
java.io.IOException