/// <summary> /// Returns the preferred similairy using the provided attribute /// </summary> /// <param name="attribute">The target attribute</param> /// <returns>an instance of the preffered Similarity Measure; otherwise null</returns> private ISimilarityMeasure GetPrefferedSimilarityMeasure(Data.Attributes.Attribute attribute) { // Check if a preffered similarity measure has been set for // the given attribute if (string.IsNullOrEmpty(attribute.PreferredSimilarityMeasure)) { return(null); } // Return the MEF maintained instant of the prefered similarity measure return(GetSimilarityMeasureInstance(attribute.PreferredSimilarityMeasure)); }
/// <summary> /// Returns the preferred similarity measure using the provided attribute /// name /// </summary> /// <param name="attributeName">The name of the target attribute</param> /// <returns>an instance of the Preffered Similarity Measure; otherwise null</returns> private ISimilarityMeasure GetPrefferedSimilarityMeasure(string attributeName) { // Retrieve the Attribute instance from the GlobalAttributeCollection Data.Attributes.Attribute attribute = GlobalAttributeCollection.GetInstance(this.scope).GetAttribute(attributeName); if (attribute == null) { return(null); } else { return(GetPrefferedSimilarityMeasure(attribute)); } }
/// <summary> /// Returns a collection of all Similarity Measures that are valid for /// the specified attribute /// </summary> /// <param name="attributeName">The attribute name to retrieve valid Similarity /// Measures for</param> /// <returns>a collection of all Similarity Measures that are valid /// for the specified attribute</returns> public ICollection <ISimilarityMeasure> GetValidSimilarityMeasures(string attributeName) { // Validate the parameter if (string.IsNullOrEmpty(attributeName)) { throw new ArgumentNullException("AttributeName", "No valid attribute name was provided"); } List <ISimilarityMeasure> validMeasures = new List <ISimilarityMeasure>(); // Retrieve the Attribute instance from the GlobalAttributeCollection Data.Attributes.Attribute attribute = GlobalAttributeCollection.GetInstance(this.scope).GetAttribute(attributeName); // Make sure that the SimilairyMeasures collection has values //if (this.SimilarityMeasures.IsValueCreated) //{ // Loop over the MEF maintained similarity collection foreach (ISimilarityMeasure currentMeasure in SimilarityMeasures) { SimilarityMeasureBase measure = currentMeasure as SimilarityMeasureBase; // Check if current measure is valid based on allowed // semantic types if (measure.SemanticTypes.HasFlag(attribute.SemanticType)) { validMeasures.Add(measure); } else { // If we are here, appropriate semantic types not matching so // something was setup wrong initially //TODO: HANDLE THIS } } //} return(validMeasures); }
private void GenerateAttributes(Node newNode) { // Randomly select a record from the sample data int recordIndex = rand.Next(0, data.Count - 1); string name = string.Empty; foreach (Tuple<string, string> fieldData in this.data[recordIndex]) { Data.Attributes.Attribute attribute = new Data.Attributes.Attribute(fieldData.Item1); AttributeValue attributeValue = null; switch (fieldData.Item1) { case ("GivenName"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.Name; name = fieldData.Item2; break; case ("MiddleInitial"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.Name; name = name + " " + fieldData.Item2; break; case ("Surname"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.Name; name = name + ". " + fieldData.Item2; attribute = new Data.Attributes.Attribute("Full Name"); attributeValue = new AttributeValue(name, name); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("Gender"): attribute.SetPreferredSimilarityMeasure(typeof(ExactMatchSimilarityMeasure)); attribute.SemanticType = SemanticType.GeneralString; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("EmailAddress"): attribute.SetPreferredSimilarityMeasure(typeof(EmailDomainSimilarityMeasure)); attribute.SemanticType = SemanticType.EmailAddress; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("TelephoneNumber"): attribute.SetPreferredSimilarityMeasure(typeof(LevenshteinDistanceStringSimilarityMeasure)); attribute.SemanticType = SemanticType.Number; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("Birthday"): attribute.SetPreferredSimilarityMeasure(typeof(DateTimeSimilarityMeasure)); attribute.SemanticType = SemanticType.Date; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("Occupation"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.GeneralString; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; default: attribute.SetPreferredSimilarityMeasure(typeof(LevenshteinDistanceStringSimilarityMeasure)); attribute.SemanticType = SemanticType.GeneralString; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; } } // Make the node's display name the name field newNode.DisplayValue = name; newNode.Description = "Generated by internal generator"; // Remove the item we used this.data.RemoveAt(recordIndex); }
private void GenerateAttributes(Node newNode) { // Randomly select a record from the sample data int recordIndex = rand.Next(0, data.Count - 1); string name = string.Empty; foreach (Tuple <string, string> fieldData in this.data[recordIndex]) { Data.Attributes.Attribute attribute = new Data.Attributes.Attribute(fieldData.Item1); AttributeValue attributeValue = null; switch (fieldData.Item1) { case ("GivenName"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.Name; name = fieldData.Item2; break; case ("MiddleInitial"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.Name; name = name + " " + fieldData.Item2; break; case ("Surname"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.Name; name = name + ". " + fieldData.Item2; attribute = new Data.Attributes.Attribute("Full Name"); attributeValue = new AttributeValue(name, name); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("Gender"): attribute.SetPreferredSimilarityMeasure(typeof(ExactMatchSimilarityMeasure)); attribute.SemanticType = SemanticType.GeneralString; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("EmailAddress"): attribute.SetPreferredSimilarityMeasure(typeof(EmailDomainSimilarityMeasure)); attribute.SemanticType = SemanticType.EmailAddress; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("TelephoneNumber"): attribute.SetPreferredSimilarityMeasure(typeof(LevenshteinDistanceStringSimilarityMeasure)); attribute.SemanticType = SemanticType.Number; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("Birthday"): attribute.SetPreferredSimilarityMeasure(typeof(DateTimeSimilarityMeasure)); attribute.SemanticType = SemanticType.Date; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; case ("Occupation"): attribute.SetPreferredSimilarityMeasure(typeof(DoubleMetaphoneSimilarityMeasure)); attribute.SemanticType = SemanticType.GeneralString; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; default: attribute.SetPreferredSimilarityMeasure(typeof(LevenshteinDistanceStringSimilarityMeasure)); attribute.SemanticType = SemanticType.GeneralString; attributeValue = new AttributeValue(fieldData.Item2, fieldData.Item2); // Add the attribute and it's value to the provided node UpdateAttributeCollection(newNode, attribute, attributeValue); break; } } // Make the node's display name the name field newNode.DisplayValue = name; newNode.Description = "Generated by internal generator"; // Remove the item we used this.data.RemoveAt(recordIndex); }
/// <summary> /// Returns the similarity measure for the specified Attribute /// </summary> /// <param name="attribute">The Attribute</param> /// <returns>the default similarity measure for the specified attribute</returns> public ISimilarityMeasure GetDefaultSimilarityMeasure(Data.Attributes.Attribute attribute) { return(GetDefaultSimilarityMeasure(attribute.Name)); }