// file: $isip/class/mmedia/Annotation/Annotation.h
// version: $Id: Annotation.h 8830 2002-11-24 16:43:55Z gao $
//

// make sure definitions are only made once
//
#ifndef ISIP_ANNOTATION
#define ISIP_ANNOTATION

#ifndef ISIP_STRING
#include <String.h>
#endif

#ifndef ISIP_HASH_TABLE
#include <HashTable.h>
#endif

#ifndef ISIP_ANCHOR
#include <Anchor.h>
#endif

// Annotation: a class used to represent an annotation
//
// Reference:
//
// [1] S. Bird, M. Liberman, A Formal Framework for Linguistic Annotation,
// Linguistic Data Consortium, University of Pennsylvania, Philadelphia,
// Pennsylvania, USA, 2000.
//
// [2] K. Maeda, X. Ma, H. Lee, S. Bird, The Annotation Graph Toolkit:
// Application Developer's Manual (Draft), Linguistic Data Consortium,
// University of Pennsylvania, Philadelphia, Pennsylvania, USA, 2001.
//
class Annotation {
  
  //--------------------------------------------------------------------------
  //
  // public constants
  //
  //--------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;

  // i/o related constants
  //
  static const String DEF_PARAM;
  static const String PARAM_ID;
  static const String PARAM_TYPE;  
  static const String PARAM_START;
  static const String PARAM_END;
  static const String PARAM_FEATURES;
  static const String PARAM_CHANNEL_INDEX;

  // define default values
  //
  static const long DEF_CHANNEL_INDEX = 0;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
  protected:

  // declare the annotation id
  //
  String id_d;

  // declare the annotation type
  //
  String type_d;
  
  // declare the start anchor
  //
  Anchor* start_d;

  // declare the end anchor
  //  
  Anchor* end_d;

  // declare the channel index
  //
  Long channel_index_d;
  
  // declare the annotation feature map
  //
  HashTable<String, String> feature_map_d;
  
  // declare a static debug level for all class instantiations
  //
  static Integral::DEBUG debug_level_d;
  
  // a static memory manager
  //
  static MemoryManager mgr_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }
  
  static boolean diagnose(Integral::DEBUG debug_level);
  
  // debug methods
  //
  boolean debug(const unichar* msg) const;

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG arg) {
    debug_level_d = arg;
    return true;
  }
  
  // method: destructor
  //
  ~Annotation();

  // method: default constructor
  //
  Annotation();

  // method: copy constructor
  //
  Annotation(const Annotation& arg) {
    assign(arg);
  }

  // method: assign
  //
  boolean assign(const Annotation& arg);
  
  // method: sofSize
  //
  long sofSize() const;

  // method: read
  //
  boolean read(Sof& sof, long tag) {
    return read(sof, tag, name());
  }

  // other read methods
  //
  boolean read(Sof& sof, long tag, const String& name);
  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT, boolean param = true,
		   boolean nested = false);
  
  // method: write
  //
  boolean write(Sof& sof, long tag) const {
    return write(sof, tag, name());
  }

  // other write methods
  //
  boolean write(Sof& sof, long tag, const String& name) const;
  boolean writeData(Sof& sof, const String& pname =  DEF_PARAM) const;   
  
  // method: eq
  //
  boolean eq(const Annotation& arg) const;

  // method: new
  //
  static void* operator new(size_t arg) {
    return mgr_d.get();
  }

  // method: new[]
  //
  static void* operator new[](size_t arg) {
    return mgr_d.getBlock(arg);
  }

  // method: delete
  //
  static void operator delete(void* arg) {
    mgr_d.release(arg);
  }

  // method: delete[]
  //
  static void operator delete[](void* arg) {
    mgr_d.releaseBlock(arg);
  }

  // method: setGrowSize
  //
  static boolean setGrowSize(long arg) {
    return mgr_d.setGrow(arg);
  }

  // method: clear
  //
  boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);

  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------

  // method: constructor
  //
  Annotation(String& id, const Annotation* arg);
  
  // method: constructor
  //
  Annotation(String& id, Anchor* start, Anchor* end,
	     String& type, long channel_index = DEF_CHANNEL_INDEX);

  /// method: getId
  //
  String getId() const {
    return id_d;
  }
  
  // method: setStartAnchor
  //
  boolean setStartAnchor(Anchor* arg) {
    start_d = arg;
    return true;
  }

  // method: setEndAnchor
  //
  boolean setEndAnchor(Anchor* arg) {
    end_d = arg;
    return true;
  }

  // method: setChannel
  //
  boolean setChannel(long arg) {
    channel_index_d = arg;
    return true;
  }

  // method: getStartAnchor
  //
  Anchor* getStartAnchor() const {
    return start_d;
  }

  // method: getEndAnchor
  //
  Anchor* getEndAnchor() const {
    return end_d;
  }

  // method: getType
  //
  String getType() const {
    return type_d;
  }

  // method: getChannel
  //
  Long getChannel() const {
    return channel_index_d;
  }

  // method: getFeatureMap
  //
  HashTable<String, String>& getFeatureMap() {
    return feature_map_d;
  }

  // method: setFeatureMap
  //
  boolean setFeatureMap(HashTable<String, String>& arg) {
    feature_map_d.assign(arg);
    return true;
  }  

  // method: existsFeature
  //
  boolean existsFeature(const String& feature) {
    return feature_map_d.containsKey(feature);
  }

  // method: deleteFeature
  //
  boolean deleteFeature(const String& feature) {
    return feature_map_d.remove(feature);
  }

  // method: setFeature
  //
  boolean setFeature(String& feature, String& value) {
    return feature_map_d.insert(feature, &value);
  }
  
  // method to get the specified feature of the annotation
  //
  String getFeature(const String& feature);
  
  // method to return a vector of all feature names
  //
  boolean getFeatureNames(Vector<String>& features);

  // method to set all the features to an empty string
  //
  boolean unsetFeatures();
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
  private:

  // method to compare
  //
  boolean compare(const String& arg1, const String& arg2) const;
  
  // friend class
  //
  friend class AnnotationGraph;
};

//end of include file
//
#endif
