1 
  2 ////////////////////////////////////////////////////////////////////////////////
  3 /**
  4  * @fileOverview Copyright (C) 2009 www.webis.de
  5  * @author Christof Braeutigam christof.braeutigam@uni-weimar.de
  6  * @version 0.1
  7  */
  8 
  9 // info: ein Feature hat genau einen namen, und kann mehrere key-value-paare
 10 //       enthalten. vordefinierte keys gibt es in AttributeKey. keys sind
 11 //       eindeutig.
 12 
 13 /* predefined keys for attributes */
 14 var AttributeKey = {
 15   /** name of <code>FEATURE</code> */
 16   NAME : "name",
 17   
 18   /** feature value */
 19   VALUE : "value",
 20   
 21   /** data type of <code>VALUE</code> */
 22   TYPE : "type",
 23   
 24   /** id of <code>FEATURE</code> */
 25   ID : "id",
 26   
 27   /** starting position of a referenced entry in the associated utf8
 28   document */
 29   OFFSET : "offset",
 30   
 31   /** length of a referenced entry in the associated utf8 document */
 32   LENGTH : "length",
 33   
 34   /** processing mode for the feature processor */
 35   MODE : "mode"
 36 };
 37 
 38 /**
 39  * A Feature is a property container for the Document class<br>
 40  * @deprecated Needs refactoring to match concept of current Java aitools
 41  * Feature version
 42  * @see de.aitools.js.Document
 43  * @class Property container for a document
 44  * @constructor
 45  * @param {Object} name
 46  * @param {Object} value
 47  */
 48 de.aitools.js.Feature = function(name, value) {
 49   
 50   var name_ = "";
 51   var attributes_ = {};
 52   
 53   CHECK_NOT_NULL(name);
 54   CHECK_NOT_UNDEFINED(name);
 55   
 56   if(typeof(name) !== "string") { name = String(name); }
 57 
 58   name_ = name;
 59   
 60   if(typeof(value) !== "undefined") {
 61     CHECK_NOT_NULL(value);
 62     // TODO: allow everything as value i.e. a term frequency vector?
 63     //       Problem: toXML function harder
 64     if(typeof(value) !== "string") { value = String(value); }
 65     attributes_[AttributeKey.VALUE] = value;
 66   }
 67   
 68   this.addAttribute = function(key, value) {
 69     CHECK_NOT_UNDEFINED(key, "key is not defined");
 70     CHECK_NOT_NULL(key, "key must not be null");
 71     CHECK_NOT_UNDEFINED(value, "value is not defined");
 72     attributes_[key] = value;
 73   };
 74   
 75   this.getAttributes = function() { return attributes_; };
 76   // returns Map<String, String>, here Object
 77   
 78   this.getAttribute = function(attributeKey) {
 79     CHECK_NOT_NULL(attributeKey);
 80     CHECK(!(attributes_[attributeKey] === undefined),
 81 	  "no such attributeKey exists: " + attributeKey);
 82     return attributes_[attributeKey];
 83   };
 84   
 85   this.getName = function() { return name_; };
 86   
 87   this.setAttributes = function(attributes) { attributes_ = attributes; };
 88   // param type: Map<String, String> in Java, Object() here
 89   
 90   // TODO: this will not work if values are not strings
 91   this.toString = function() {
 92     temp = "";
 93     temp += "attributes: {";
 94     for(var i in attributes_) {
 95       if (attributes_.hasOwnProperty(i)) {
 96         temp += (i + "=");
 97         temp += (attributes_[i] + ", ");
 98       }
 99     }
100     temp = (temp.substring(0, temp.length-2) + "}");
101     return temp;
102   };
103   
104   /*
105    * TODO: brauchen wir diese Funktionealitaeten?
106   public String toXml() { return new XStream().toXML(this); }
107   
108   public static Feature fromXml(String xml) {
109     return (Feature)new XStream().fromXML(xml);
110   };
111   */
112 };
113 
114 // Feature.js
115 ////////////////////////////////////////////////////////////////////////////////
116