protected internal void SetAttribute(Entity entity, EntityInstance targetInstance, string attributeName, IAttributeData attributeData) { if (attributeData.Value == null && !attributeData.Changepoints.Any()) { return; } RBAttr attribute = entity.GetAttribute(attributeName); if (attribute != null) { if (attributeData.Changepoints.Any()) { var changePoints = this.MapTemporalValue(attributeData.Changepoints); attribute.SetValue(targetInstance, new TemporalValue(null, changePoints)); } else if (attribute.GetValueType() == 16) { attribute.SetValue(targetInstance, new Date(DateTime.Parse(attributeData.Value.ToString()))); } else if (attribute.GetValueType() == 4) { attribute.SetValue(targetInstance, new Oracle.Determinations.Masquerade.Lang.Double(attributeData.Value.ToString())); } else if (attribute.GetValueType() == 8) { attribute.SetValue(targetInstance, new Oracle.Determinations.Masquerade.Lang.Double(attributeData.Value.ToString())); } else if (attribute.GetValueType() == 2) { attribute.SetValue(targetInstance, attributeData.Value.ToString().Trim()); } else { attribute.SetValue(targetInstance, bool.Parse(attributeData.Value.ToString())); } } else { // TODO: Log something } }
public override object Evaluate(EntityInstance ei, object[] os) { String relationshipName = ""; String attributeName = ""; String delimiter = ""; int qty = ((Oracle.Determinations.Masquerade.Lang.Double)os[3]).IntValue(); relationshipName = os[0].ToString(); attributeName = os[1].ToString(); delimiter = os[2].ToString(); String result = ""; Entity ent, currEntity; Relationship rel = null; Oracle.Determinations.Masquerade.Util.List targets; Oracle.Determinations.Masquerade.Util.List relationships; Oracle.Determinations.Masquerade.Util.List attributes; //RBAttr currAttr = null; // We have to access relationships from the entity not the entity instance so we get the entity ent = ei.GetEntity(); relationships = ent.GetRelationships(); rel = ent.GetRelationship(relationshipName); //Relationships can only be directly accessed by public id, so we get them all and iterate to find the sentence form if (rel == null) { foreach (Relationship possibleRelationship in relationships) { if (possibleRelationship.GetText().Equals(relationshipName)) { rel = possibleRelationship; } } } if (rel == null) { return(""); } //Debug - return rel.GetName(); //Now we need to find a list of entity Instances that are all the know instances on the far end of the relationship for our specific entity innstance start point targets = rel.GetKnownTargets(ei); //Now we iterate the instances to obtain the attribute - again we have to get the enity from th instance, then we can gat the attribute foreach (EntityInstance targetEntity in targets) { currEntity = targetEntity.GetEntity(); // First see if we can get the attibute using a public name RBAttr currAttr = null; currAttr = currEntity.GetAttribute(attributeName); //We use an iteator so we can match by text name and so we can exit early if we get a match, obviously a lot slower! if (currAttr == null) { attributes = currEntity.GetAttributes(); Iterator iAttributes = attributes.Iterator(); while (currAttr == null && iAttributes.HasNext()) { RBAttr a = (RBAttr)iAttributes.Next(); if (a.GetText(SentenceForm.BASIC).Equals(attributeName)) { currAttr = a; } } } if (currAttr == null) { return(""); } Object attributeValue = currAttr.GetValue(targetEntity); if (attributeValue != null && attributeValue != Uncertain.INSTANCE) { if (result == null || result == "") { result = attributeValue.ToString(); } else { result += (delimiter + attributeValue.ToString()); } } } return(result); }
protected internal IAttributeData MapOpaAttributeToDataEntity(EntityInstance entityInstance, RBAttr attr) { var value = attr.GetValue(entityInstance); if (value is TemporalValue temporalValue) { IAttributeData attributeData = new AttributeData(null); for (int period = 0; period < 12; period++) { var date = _yearStartDate.AddMonths(period); var index = temporalValue.FindChangePointIndex(new ChangePointDate(date.Year, date.Month, date.Day)); var val = temporalValue.GetValue(index); attributeData.AddChangepoint(new TemporalValueItem(date, val, string.Empty)); } return(attributeData); } return(new AttributeData(value is string?value.ToString().Trim() : value)); }