Skip to content
Snippets Groups Projects
Commit b65c1953 authored by Helena Jank's avatar Helena Jank
Browse files

+ added synonyms and according helper/builder functions to Attribute

+ added function buildAttribute to Discoverer
# corrected stale name 'AttributeType' changing it to 'Attribute'
# simplified Translation
parent 789e9709
No related branches found
No related tags found
No related merge requests found
/** /**
* This module represents an AttributeType. * This module represents an Attribute.
* AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. * Attributes defines name, type (string, double,...) an associated parameter of an attribute.
* *
* @module AttributeType * @module Attribute
* @fileOverview * @fileOverview
*/ */
define(['easejs', define(['easejs',
...@@ -23,7 +23,7 @@ define(['easejs', ...@@ -23,7 +23,7 @@ define(['easejs',
* @alias name * @alias name
* @protected * @protected
* @type {string} * @type {string}
* @memberof AttributeType# * @memberof Attribute#
* @desc Name of the Attribute * @desc Name of the Attribute
*/ */
'protected name' : '', 'protected name' : '',
...@@ -32,7 +32,7 @@ define(['easejs', ...@@ -32,7 +32,7 @@ define(['easejs',
* @alias type * @alias type
* @protected * @protected
* @type {string} * @type {string}
* @memberof AttributeType# * @memberof Attribute#
* @desc Defines the type of the Attribute (i.e String, Double,...) * @desc Defines the type of the Attribute (i.e String, Double,...)
*/ */
'protected type' : '', 'protected type' : '',
...@@ -41,10 +41,19 @@ define(['easejs', ...@@ -41,10 +41,19 @@ define(['easejs',
* @alias parameterList * @alias parameterList
* @protected * @protected
* @type {ParameterList} * @type {ParameterList}
* @memberof AttributeType# * @memberof Attribute#
* @desc Name of the Attribute * @desc Name of the Attribute
*/ */
'protected parameterList' : [], 'protected parameterList' : [],
/**
* @alias synonymList
* @protected
* @type {Array}
* @memberof Attribute#
* @desc Alternative names of the Attribute; this is simply an array of strings
*/
'protected synonymList' : [],
/** /**
* @alias value * @alias value
...@@ -66,11 +75,11 @@ define(['easejs', ...@@ -66,11 +75,11 @@ define(['easejs',
/** /**
* Constructor: Initializes the ParameterList. * Constructor: Initializes the ParameterList.
* *
* @class AttributeType * @class Attribute
* @classdesc AttributeTypes defines name, type (string, double,...) an associated parameter of an attribute. * @classdesc Attributes defines name, type (string, double,...) an associated parameter of an attribute.
* @requires easejs * @requires easejs
* @requires ParameterList * @requires ParameterList
* @constructs AttributeType * @constructs Attribute
*/ */
'public __construct' : function(){ 'public __construct' : function(){
this.parameterList = new ParameterList(); this.parameterList = new ParameterList();
...@@ -81,9 +90,9 @@ define(['easejs', ...@@ -81,9 +90,9 @@ define(['easejs',
* *
* @public * @public
* @alias withName * @alias withName
* @memberof AttributeType# * @memberof Attribute#
* @param {String} _name Name * @param {String} _name Name
* @returns {AttributeType} * @returns {Attribute}
*/ */
'public withName' : function(_name){ 'public withName' : function(_name){
this.setName(_name); this.setName(_name);
...@@ -95,9 +104,9 @@ define(['easejs', ...@@ -95,9 +104,9 @@ define(['easejs',
* *
* @public * @public
* @alias withType * @alias withType
* @memberof AttributeType# * @memberof Attribute#
* @param {String} _type Type * @param {String} _type Type
* @returns {AttributeType} * @returns {Attribute}
*/ */
'public withType' : function(_type){ 'public withType' : function(_type){
this.setType(_type); this.setType(_type);
...@@ -108,10 +117,10 @@ define(['easejs', ...@@ -108,10 +117,10 @@ define(['easejs',
* Builder for one parameter. * Builder for one parameter.
* *
* @public * @public
* @alias withParameters * @alias withParameter
* @memberof AttributeType# * @memberof Attribute#
* @param {Parameter} _parameter Parameter * @param {Parameter} _parameter Parameter
* @returns {AttributeType} * @returns {Attribute}
*/ */
'public withParameter' : function(_parameter){ 'public withParameter' : function(_parameter){
this.addParameter(_parameter); this.addParameter(_parameter);
...@@ -123,9 +132,9 @@ define(['easejs', ...@@ -123,9 +132,9 @@ define(['easejs',
* *
* @public * @public
* @alias withParameters * @alias withParameters
* @memberof AttributeType# * @memberof Attribute#
* @param {(ParameterList|Array)} _parameterList ParameterList * @param {(ParameterList|Array)} _parameterList ParameterList
* @returns {AttributeType} * @returns {Attribute}
*/ */
'public withParameters' : function(_parameterList){ 'public withParameters' : function(_parameterList){
this.setParameters(_parameterList); this.setParameters(_parameterList);
...@@ -160,13 +169,41 @@ define(['easejs', ...@@ -160,13 +169,41 @@ define(['easejs',
this.setTimestamp(_timestamp); this.setTimestamp(_timestamp);
return this; return this;
}, },
/**
* Builder for synonyms from single translation, called by discoverer's buildAttribute().
*
* @public
* @alias withSynonym
* @memberof Attribute#
* @param {Translation} _translation Translations
* @returns {Attribute}
*/
'public withSynonym' : function(_translation){
this.addSynonym(_translation);
return this;
},
/**
* Builder for synonyms from translations, called by discoverer's buildAttribute().
*
* @public
* @alias withSynonyms
* @memberof Attribute#
* @param {Array} _translations Translations
* @returns {Attribute}
*/
'public withSynonyms' : function(_translations){
this.setSynonyms(_translations);
return this;
},
/** /**
* Returns the name. * Returns the name.
* *
* @public * @public
* @alias getName * @alias getName
* @memberof AttributeType# * @memberof Attribute#
* @returns {string} * @returns {string}
*/ */
'public getName' : function(){ 'public getName' : function(){
...@@ -178,7 +215,7 @@ define(['easejs', ...@@ -178,7 +215,7 @@ define(['easejs',
* *
* @public * @public
* @alias getType * @alias getType
* @memberof AttributeType# * @memberof Attribute#
* @returns {string} * @returns {string}
*/ */
'public getType' : function(){ 'public getType' : function(){
...@@ -190,19 +227,31 @@ define(['easejs', ...@@ -190,19 +227,31 @@ define(['easejs',
* *
* @public * @public
* @alias getParameters * @alias getParameters
* @memberof AttributeType# * @memberof Attribute#
* @returns {ParameterList} * @returns {ParameterList}
*/ */
'public getParameters' : function(){ 'public getParameters' : function(){
return this.parameterList; return this.parameterList;
}, },
/**
* Returns the list of synonyms.
*
* @public
* @alias getSynonyms
* @memberof Attribute#
*/
'public getSynonyms' : function(){
return this.synonymList;
},
/** /**
* Sets the name. * Sets the name.
* *
* @public * @public
* @alias setName * @alias setName
* @memberof AttributeType# * @memberof Attribute#
* @param {string} _name Name * @param {string} _name Name
*/ */
'public setName' : function(_name){ 'public setName' : function(_name){
...@@ -216,7 +265,7 @@ define(['easejs', ...@@ -216,7 +265,7 @@ define(['easejs',
* *
* @public * @public
* @alias setType * @alias setType
* @memberof AttributeType# * @memberof Attribute#
* @param {string} _type Type * @param {string} _type Type
*/ */
'public setType' : function(_type){ 'public setType' : function(_type){
...@@ -230,7 +279,7 @@ define(['easejs', ...@@ -230,7 +279,7 @@ define(['easejs',
* *
* @public * @public
* @alias addParameter * @alias addParameter
* @memberof AttributeType# * @memberof Attribute#
* @param {Parameter} _parameter Parameter * @param {Parameter} _parameter Parameter
*/ */
'public addParameter' : function(_parameter){ 'public addParameter' : function(_parameter){
...@@ -242,7 +291,7 @@ define(['easejs', ...@@ -242,7 +291,7 @@ define(['easejs',
* *
* @public * @public
* @alias setParameters * @alias setParameters
* @memberof AttributeType# * @memberof Attribute#
* @param {ParameterList} _parameters ParameterList * @param {ParameterList} _parameters ParameterList
*/ */
'public setParameters' : function(_parameters){ 'public setParameters' : function(_parameters){
...@@ -308,6 +357,35 @@ define(['easejs', ...@@ -308,6 +357,35 @@ define(['easejs',
'public getTimestamp' : function() { 'public getTimestamp' : function() {
return this.timestamp; return this.timestamp;
}, },
/**
* Adds a list of synonyms.
*
* @public
* @alias setSynonyms
* @memberof Attribute#
* @param {Array} _synonyms Array of synonyms
*/
'public setSynonyms' : function(_synonyms){
for (synIndex in _synonyms) {
this.addSynonym(_synonyms[synIndex]);
}
},
/**
* Adds one synonym.
*
* @public
* @alias addSynonym
* @memberof Attribute#
* @param {Attribute} _synonym
*/
'public addSynonym' : function(_synonym){
if (Class.isA(Attribute, _synonym))
this.synonymList.push(_synonym.getName());
else if (typeof _synonym == 'string')
this.synonymList.push(_synonym);
},
/** /**
* *
...@@ -363,7 +441,7 @@ define(['easejs', ...@@ -363,7 +441,7 @@ define(['easejs',
* *
* @public * @public
* @alias toString * @alias toString
* @memberof AttributeType# * @memberof Attribute#
* @returns {String} * @returns {String}
* @example (CI_USER_LOCATION_DISTANCE:FLOAT)#[CP_TARGET_LATITUDE:52][CP_TARGET_LONGITUDE:13][CP_UNIT:KILOMETERS] * @example (CI_USER_LOCATION_DISTANCE:FLOAT)#[CP_TARGET_LATITUDE:52][CP_TARGET_LONGITUDE:13][CP_UNIT:KILOMETERS]
*/ */
......
...@@ -42,7 +42,7 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun ...@@ -42,7 +42,7 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun
* @private * @private
* @type {Array} * @type {Array}
* @memberof Discoverer# * @memberof Discoverer#
* @desc List of available attributeType translations (or synonyms). * @desc List of available attribute translations (or synonyms).
*/ */
'private translations' : [], 'private translations' : [],
...@@ -251,6 +251,24 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun ...@@ -251,6 +251,24 @@ define([ 'easejs', 'attributeList', 'widget', 'interpreter', 'aggregator' ], fun
'public getTranslations' : function() { 'public getTranslations' : function() {
return this.translations; return this.translations;
}, },
'public buildAttribute' : function(name, type, parameterList) {
var newAttribute = new Attribute().withName(name).withType(type);
while (typeof parameterList != 'undefined' && parameterList.length > 0)
{
var param = parameterList.pop();
var value = param.pop();
var key = param.pop();
if (typeof key != 'undefined' && typeof value != 'undefined')
newAttribute = newAttribute.withParameter(new Parameter().withKey(key).withValue(value));
}
for (translation in this.translations) {
if (translation.translates(newAttribute))
newAttribute = newAttribute.withSynonym(translation.getSynonym());
}
return newAttribute;
},
/*********************************************************************** /***********************************************************************
* Helper * * Helper *
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* @module Translation * @module Translation
* @fileOverview * @fileOverview
*/ */
define('translation', ['easejs', 'attributeType'], function(easejs, AttributeType) { define('translation', ['easejs', 'attribute'], function(easejs, Attribute) {
var Class = easejs.Class; var Class = easejs.Class;
var Translation = Class('Translation', { var Translation = Class('Translation', {
...@@ -20,13 +20,15 @@ define('translation', ['easejs', 'attributeType'], function(easejs, AttributeTyp ...@@ -20,13 +20,15 @@ define('translation', ['easejs', 'attributeType'], function(easejs, AttributeTyp
* @classdesc This class represents a translation tuple. * @classdesc This class represents a translation tuple.
* It holds two synonymous attribute types. * It holds two synonymous attribute types.
* @requires easejs * @requires easejs
* @requires attributeType * @requires attribute
* @constructs Translation * @constructs Translation
*/ */
'public __construct' : function(_fromAttributeType, _toAttributeType) { 'public __construct' : function(_fromAttributeType, _toAttributeType) {
if (Class.isA(Attribute, _fromAttributeType) && Class.isA(Attribute, _toAttributeType))
this.fromAttributeType = _fromAttributeType; {
this.toAttributeType = _toAttributeType; this.fromAttributeType = _fromAttributeType;
this.toAttributeType = _toAttributeType;
}
}, },
/** /**
...@@ -35,26 +37,24 @@ define('translation', ['easejs', 'attributeType'], function(easejs, AttributeTyp ...@@ -35,26 +37,24 @@ define('translation', ['easejs', 'attributeType'], function(easejs, AttributeTyp
* @public * @public
* @alias getSynonym * @alias getSynonym
* @memberof Translation# * @memberof Translation#
* @param {AttributeType} attributeType AttributeType whose synonym is queried * @returns {Attribute} The synonymous attribute
* @returns {AttributeType} The synonym if one exists, otherwise the given attributeType
*/ */
'public getSynonym': function(_attributeType) { 'public getSynonym': function() {
return this.toAttributeType;
return this.hasSynonym(_attributeType) ? this.toAttributeType : _attributeType;
}, },
/** /**
* Look for a translation and return true if one exists. * Look for a translation and return true if one exists.
* *
* @public * @public
* @alias hasSynonym * @alias translates
* @memberof Translation# * @memberof Translation#
* @param {AttributeType} attributeType AttributeType whose synonym is queried * @param {Attribute} attribute Attribute whose synonym is queried
* @returns {boolean} * @returns {boolean}
*/ */
'public hasSynonym': function(_attributeType) { 'public translates': function(_attribute) {
return this.fromAttributeType.equals(_attributeType); return this.fromAttributeType.equalsTypeOf(_attribute);
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment