Skip to content

Commit

Permalink
Update descriptions for Extract methods, remove ExtractOne, add proje…
Browse files Browse the repository at this point in the history
…ct reference and remove reference to FuzzyResult
  • Loading branch information
peterjamesnugent committed Jan 17, 2024
1 parent 3193fe6 commit 6e48708
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 115 deletions.
10 changes: 5 additions & 5 deletions Search_Engine/Compute/Extract/ExtractAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public static partial class Compute
[Input("scorer", "The method to use to score the strings when compared.")]
[Input("cutOff", "The cuttoff score (i.e. lower bound) for results to be returned.")]
[Output("result", "A SearchResult containing the strings, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<string>> ExtractAll(string query, IEnumerable<string> choices, Scorer scorer = Scorer.DefaultRatioScorer, int cutOff = 0)
public static List<SearchResult<string>> ExtractAll(string query, IEnumerable<string> choices, Scorer scorer = Scorer.DefaultRatio, int cutOff = 0)
{
IRatioScorer scorerMethod = ScorerCache.Get<DefaultRatioScorer>();
if (scorer != Scorer.DefaultRatioScorer)
if (scorer != Scorer.DefaultRatio)
scorerMethod = GetScorer(scorer);

IEnumerable<ExtractedResult<string>> extractedResults = Process.ExtractAll(query, choices.ToArray(), s => s, scorerMethod, cutOff);
Expand All @@ -72,14 +72,14 @@ public static List<SearchResult<string>> ExtractAll(string query, IEnumerable<st
[Description("Extracts all BHoMObjects unsorted with a score greater than the cutoff when comparing the query to the choices.")]
[Input("query", "The string to carry out the fuzzy matching on.")]
[Input("objects", "A list of BHoMObjects to compare the query against.")]
[Input("propertyName", "The propertyName to compare the query against - the property must be a string.")]
[Input("propertyName", "The propertyName to compare the query against - the property must be a string and an exact match.")]
[Input("scorer", "The method to use to score the strings when compared.")]
[Input("cutOff", "The cuttoff score (i.e. lower bound) for results to be returned.")]
[Output("result", "A SearchResult containing the objects, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<BHoMObject>> ExtractAll(string query, List<BHoMObject> objects, string propertyName, Scorer scorer = Scorer.DefaultRatioScorer, int cutOff = 0)
public static List<SearchResult<BHoMObject>> ExtractAll(string query, List<BHoMObject> objects, string propertyName, Scorer scorer = Scorer.DefaultRatio, int cutOff = 0)
{
IRatioScorer scorerMethod = ScorerCache.Get<DefaultRatioScorer>();
if (scorer != Scorer.DefaultRatioScorer)
if (scorer != Scorer.DefaultRatio)
scorerMethod = GetScorer(scorer);

IEnumerable<string> choices = objects.Select(x => x.PropertyValue(propertyName).ToString());
Expand Down
68 changes: 0 additions & 68 deletions Search_Engine/Compute/Extract/ExtractOne.cs

This file was deleted.

18 changes: 9 additions & 9 deletions Search_Engine/Compute/Extract/ExtractSorted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public static partial class Compute
/**** Public Methods ****/
/***************************************************/

[Description("Extracts all values sorted in order of score when comparing the query to the choices.")]
[Description("Extracts all values sorted in descending order of score when comparing the query to the choices.")]
[Input("query", "The string to carry out the fuzzy matching on.")]
[Input("choices", "A list of strings to compare the query against.")]
[Input("scorer", "The method to use to score the strings when compared.")]
[Output("result", "A FuzzyStringResult containing the strings, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<string>> ExtractSorted(string query, IEnumerable<string> choices, Scorer scorer = Scorer.DefaultRatioScorer)
[Output("result", "A SearchResult containing the strings, scores and indexes resulting from the fuzzy matching algorithm sorted in descending order by score.")]
public static List<SearchResult<string>> ExtractSorted(string query, IEnumerable<string> choices, Scorer scorer = Scorer.DefaultRatio)
{
IRatioScorer scorerMethod = ScorerCache.Get<DefaultRatioScorer>();
if (scorer != Scorer.DefaultRatioScorer)
if (scorer != Scorer.DefaultRatio)
scorerMethod = GetScorer(scorer);

IEnumerable<ExtractedResult<string>> extractedResults = Process.ExtractSorted(query, choices.ToArray(), s => s, scorerMethod);
Expand All @@ -68,16 +68,16 @@ public static List<SearchResult<string>> ExtractSorted(string query, IEnumerable

/***************************************************/

[Description("Extracts all values sorted in order of score when comparing the query to the choices.")]
[Description("Extracts all values sorted in descending order of score when comparing the query to the choices.")]
[Input("query", "The string to carry out the fuzzy matching on.")]
[Input("objects", "A list of BHoMObjects to compare the query against.")]
[Input("propertyName", "The propertyName to compare the query against - the property must be a string.")]
[Input("propertyName", "The propertyName to compare the query against - the property must be a string and an exact match.")]
[Input("scorer", "The method to use to score the strings when compared.")]
[Output("result", "A FuzzyObjectResult containing the objects, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<BHoMObject>> ExtractSorted(string query, List<BHoMObject> objects, string propertyName, Scorer scorer = Scorer.DefaultRatioScorer)
[Output("result", "A SearchResult containing the objects, scores and indexes resulting from the fuzzy matching algorithm sorted in descending order by score.")]
public static List<SearchResult<BHoMObject>> ExtractSorted(string query, List<BHoMObject> objects, string propertyName, Scorer scorer = Scorer.DefaultRatio)
{
IRatioScorer scorerMethod = ScorerCache.Get<DefaultRatioScorer>();
if (scorer != Scorer.DefaultRatioScorer)
if (scorer != Scorer.DefaultRatio)
scorerMethod = GetScorer(scorer);

IEnumerable<string> choices = objects.Select(x => x.PropertyValue(propertyName).ToString());
Expand Down
14 changes: 7 additions & 7 deletions Search_Engine/Compute/Extract/ExtractTop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public static partial class Compute
[Input("choices", "A list of strings to compare the query against.")]
[Input("scorer", "The method to use to score the strings when compared.")]
[Input("n", "Number of values to return.")]
[Output("result", "A FuzzyStringResult containing the strings, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<string>> ExtractTop(string query, IEnumerable<string> choices, Scorer scorer = Scorer.DefaultRatioScorer, int n = 1)
[Output("result", "A SearchResult containing the strings, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<string>> ExtractTop(string query, IEnumerable<string> choices, Scorer scorer = Scorer.DefaultRatio, int n = 1)
{
IRatioScorer scorerMethod = ScorerCache.Get<DefaultRatioScorer>();
if (scorer != Scorer.DefaultRatioScorer)
if (scorer != Scorer.DefaultRatio)
scorerMethod = GetScorer(scorer);

IEnumerable<ExtractedResult<string>> extractedResults = Process.ExtractTop(query, choices.ToArray(), s => s, scorerMethod, n);
Expand All @@ -72,14 +72,14 @@ public static List<SearchResult<string>> ExtractTop(string query, IEnumerable<st
[Description("Extracts the top n BHoMObjects with the highest score when comparing the query to the choices.")]
[Input("query", "The string to carry out the fuzzy matching on.")]
[Input("objects", "A list of BHoMObjects to compare the query against.")]
[Input("propertyName", "The propertyName to compare the query against - the property must be a string.")]
[Input("propertyName", "The propertyName to compare the query against - the property must be a string and an exact match.")]
[Input("scorer", "The method to use to score the strings when compared.")]
[Input("n", "Number of values to return.")]
[Output("result", "A FuzzyObjectResult containing the objects, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<BHoMObject>> ExtractTop(string query, List<BHoMObject> objects, string propertyName, Scorer scorer = Scorer.DefaultRatioScorer, int n = 1)
[Output("result", "A SearchResult containing the objects, scores and indexes resulting from the fuzzy matching algorithm.")]
public static List<SearchResult<BHoMObject>> ExtractTop(string query, List<BHoMObject> objects, string propertyName, Scorer scorer = Scorer.DefaultRatio, int n = 1)
{
IRatioScorer scorerMethod = ScorerCache.Get<DefaultRatioScorer>();
if (scorer != Scorer.DefaultRatioScorer)
if (scorer != Scorer.DefaultRatio)
scorerMethod = GetScorer(scorer);

IEnumerable<string> choices = objects.Select(x => x.PropertyValue(propertyName).ToString());
Expand Down
41 changes: 20 additions & 21 deletions Search_Engine/Compute/Ratios/FuzzyMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,33 @@ public static partial class Compute
[Input("compare", "The string to compare against.")]
[Input("scorer", "The method to use to score the strings when compared.")]
[Output("r", "The ratio of similarity between the two strings.")]
public static int FuzzyMatch(string text, string compare, Scorer scorer = Scorer.DefaultRatioScorer)
public static int FuzzyMatch(string text, string compare, Scorer scorer = Scorer.DefaultRatio)
{
switch (scorer)
{
case Scorer.DefaultRatioScorer:
case Scorer.DefaultRatio:
default:
return Fuzz.Ratio(text, compare);
case Scorer.PartialRatioScorer:
case Scorer.PartialRatio:
return Fuzz.PartialRatio(text, compare);
case Scorer.TokenSetScorer:
case Scorer.TokenSet:
return Fuzz.TokenSetRatio(text, compare);
case Scorer.PartialTokenSetScorer:
case Scorer.PartialTokenSet:
return Fuzz.PartialTokenSetRatio(text, compare);
case Scorer.TokenSortScorer:
case Scorer.TokenSort:
return Fuzz.TokenSortRatio(text, compare);
case Scorer.PartialTokenSortScorer:
case Scorer.PartialTokenSort:
return Fuzz.PartialTokenSortRatio(text, compare);
case Scorer.TokenAbbreviationScorer:
case Scorer.TokenAbbreviation:
return Fuzz.TokenAbbreviationRatio(text, compare, PreprocessMode.Full);
case Scorer.PartialTokenAbbreviationScorer:
case Scorer.PartialTokenAbbreviation:
return Fuzz.PartialTokenAbbreviationRatio(text, compare, PreprocessMode.Full);
case Scorer.TokenInitialismScorer:
case Scorer.TokenInitialism:
return Fuzz.TokenInitialismRatio(text, compare);
case Scorer.PartialTokenInitialismScorer:
case Scorer.PartialTokenInitialism:
return Fuzz.PartialTokenInitialismRatio(text, compare);
case Scorer.WeightedRatioScorer:
case Scorer.WeightedRatio:
return Fuzz.WeightedRatio(text, compare);

}
}

Expand All @@ -89,22 +88,22 @@ private static IRatioScorer GetScorer(Scorer scorer)
{
switch (scorer)
{
case Scorer.DefaultRatioScorer:
case Scorer.DefaultRatio:
default:
return ScorerCache.Get<DefaultRatioScorer>();
case Scorer.PartialRatioScorer:
case Scorer.PartialRatio:
return ScorerCache.Get<PartialRatioScorer>();
case Scorer.TokenSetScorer:
case Scorer.TokenSet:
return ScorerCache.Get<TokenSetScorer>();
case Scorer.PartialTokenSetScorer:
case Scorer.PartialTokenSet:
return ScorerCache.Get<PartialTokenSetScorer>();
case Scorer.TokenSortScorer:
case Scorer.TokenSort:
return ScorerCache.Get<TokenSortScorer>();
case Scorer.TokenAbbreviationScorer:
case Scorer.TokenAbbreviation:
return ScorerCache.Get<TokenSortScorer>();
case Scorer.PartialTokenAbbreviationScorer:
case Scorer.PartialTokenAbbreviation:
return ScorerCache.Get<PartialTokenAbbreviationScorer>();
case Scorer.WeightedRatioScorer:
case Scorer.WeightedRatio:
return ScorerCache.Get<WeightedRatioScorer>();
}
}
Expand Down
9 changes: 4 additions & 5 deletions Search_Engine/Search_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
<Private>false</Private>
<SpecificVersion>false</SpecificVersion>
</Reference>
<Reference Include="BHoM_Engine">
<HintPath>$(ProgramData)\BHoM\Assemblies\BHoM_Engine.dll</HintPath>
<SpecificVersion>false</SpecificVersion>
<Private>false</Private>
</Reference>
<Reference Include="Search_oM">
<HintPath>$(ProgramData)\BHoM\Assemblies\Search_oM.dll</HintPath>
<SpecificVersion>false</SpecificVersion>
Expand All @@ -42,6 +37,10 @@
<Folder Include="Query\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BHoM_Engine\BHoM_Engine.csproj" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y&#xD;&#xA;xcopy &quot;$(TargetDir)FuzzySharp.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
</Target>
Expand Down

0 comments on commit 6e48708

Please sign in to comment.