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

+ in aggregator: added translation of interpreter's queried input attributes

+ in attribute: added reciprocity of synonyms in equalsTypeOf()
+ in attributeList: added synonyms in clone()
+ in translation: added functions for checking and accessing both synonyms
parent f5b9fb21
No related branches found
No related tags found
No related merge requests found
......@@ -525,6 +525,16 @@ define(['MathUuid', 'widget', 'attribute', 'attributeList', 'subscriber', 'subsc
var theInAttribute = inAttributes[inAttributeIdentifier];
console.log("The interpreter needs the attribute "+theInAttribute+".");
var allTranslations = this._discoverer.getTranslations();
for (var translationIndex in allTranslations) {
var translation = allTranslations[translationIndex];
if (translation.isTranslation(theInAttribute)) {
theInAttribute = translation.getOrigin();
console.log("This attribute seems to be a translation. One possible synonym is "+theInAttribute+".")
break;
}
}
// if required attribute is not already satisfied by the aggregator search for components that do
if (!this.doesSatisfyTypeOf(theInAttribute)) {
console.log("It seems that I can't satisfy "+theInAttribute+", but I will search for components that can.");
......
......@@ -221,9 +221,9 @@ define(['parameterList'], function(ParameterList) {
*/
Attribute.prototype.addSynonym = function(synonym){
if (synonym instanceof Attribute)
this.synonymList.push(synonym.getName());
else if (typeof _synonym == 'string')
this.synonymList.push(synonym);
this._synonymList.push(synonym.getName());
else if (typeof synonym == 'string')
this._synonymList.push(synonym);
};
/**
......@@ -308,9 +308,12 @@ define(['parameterList'], function(ParameterList) {
* @returns {boolean}
*/
Attribute.prototype.equalsTypeOf = function(attribute) {
var name = attribute.getName();
if (attribute instanceof Attribute) {
if ((this.getName() == name || this.getSynonyms().indexOf(name) != -1)
var thisName = this.getName();
var thatName = attribute.getName();
if ((thisName == thatName
|| this.getSynonyms().indexOf(thatName) != -1
|| attribute.getSynonyms().indexOf(thisName) != -1)
&& this.getType() == attribute.getType()
&& this.getParameters().equals(attribute.getParameters())) {
return true;
......
......@@ -212,7 +212,11 @@ define(['abstractList', 'attribute'], function(AbstractList, Attribute) {
var newList = new AttributeList();
for (var index in this._items) {
var oldAttribute = this._items[index];
var newAttribute = new Attribute().withName(oldAttribute.getName()).withType(oldAttribute.getType()).withParameters(oldAttribute.getParameters());
var newAttribute = new Attribute()
.withName(oldAttribute.getName())
.withType(oldAttribute.getType())
.withParameters(oldAttribute.getParameters())
.withSynonyms(oldAttribute.getSynonyms());
if (!typeOnly) newAttribute.setValue(oldAttribute.getValue());
newList.put(newAttribute);
}
......
define(['attributeList', 'widget', 'interpreter', 'aggregator' ],
function(AttributeList, Widget, Interpreter, Aggregator) {
define(['attributeList', 'attribute', 'parameter', 'widget', 'interpreter', 'aggregator' ],
function(AttributeList, Attribute, Parameter, Widget, Interpreter, Aggregator) {
return (function() {
/**
* Constructor: All known components given in the associated functions will be registered as startup.
......
......@@ -36,7 +36,7 @@ define('translation', ['attribute'], function(Attribute) {
}
/**
* Look for a translation and return the found synonym.
* Return the target synonym.
*
* @returns {Attribute} The synonymous attribute
*/
......@@ -44,6 +44,15 @@ define('translation', ['attribute'], function(Attribute) {
return this._toAttribute;
};
/**
* Return the original attribute for which a translation exists.
*
* @returns {Attribute} The original attribute
*/
Translation.prototype.getOrigin = function() {
return this._fromAttribute;
};
/**
* Look for a translation and return true if one exists.
*
......@@ -54,6 +63,16 @@ define('translation', ['attribute'], function(Attribute) {
return this._fromAttribute.equalsTypeOf(attribute);
};
/**
* Look for a translation result and return true if one exists.
*
* @param {Attribute} attribute Attribute whose synonym is queried
* @returns {boolean}
*/
Translation.prototype.isTranslation = function(attribute) {
return this._toAttribute.equalsTypeOf(attribute);
};
return Translation;
})();
});
\ No newline at end of file
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