I have different string distance metric implementations (for example they are all in C #) For example, Levensteen, NeedleNew Jackcard, etc. Their job is basically the same; Take two strings in the form of input and return a similarity score in the range [0,1]. Therefore, I have planned to implement these classes with the same basic interface, as in the following:
Public Interface Expert Distances Metric {// Return a Similar Between 0 and 1 Similar Comparison Equality (String Stra, String Strobe); }
Each of my metrics will implement this method. But there are some matrix which will work directly on two wires, without any other input and some matrix which requires some extra parameters (Like penalties for any one of the input strings). In general, I can give these parameters in the constructor phase or before calculating the equality score.
My question is, in general, what would be good design practice to control such distinction of solid distance classes? My goal is that the client code that wants to use any distance metric should be unaware of the details of any underlying implementation after deciding to use a specific type of metric. The most obvious way is to implement something like this:
IStringDistanceMetric metric; If (MetricType == Metric. IdlemanWatch) {Metric = New Needyman Wunch (parameter NW); } And if (MetricType == Metric. Levenstein) {Metric = New Levenstein (parameter L); }. .
But this does not seem to be a good solution for me. I am surprised to get caught up on this basic basic design problem. Any help would be appreciated.
I think it depends on excessive use; Are the values of these parameters fixed or should they be provided when comparing? If the number of possible values for these standards is very low, the design used in the .NET can be followed (courtesy):
Private static text only string compiler _invariantCulture = new CultureAwareComparer ( CultureInfo.InvariantCulture, False); Private Static Read-Only String Compiler _invariantCultureIgnoreCase = New Cultureware Comparator (Culture Info. Inventive Culture, True); Private static readonly string compiler _rod inal = new ordinal computer (wrong); Private static readonly string compactor _ordinalIgnoreCase = new ordinal computer (true); Public static string compiler invariant culture {receive {return_increent culture; }}
If you are getting user input or configuration settings to specify your parameter values, and each time you compare strings, a factory method may be The appropriate solution will be, 'the most obvious way' presented in your reply.
Comments
Post a Comment