Skip to content

Commit

Permalink
Fixed culture problem. In German and other language the decimal separ…
Browse files Browse the repository at this point in the history
…ator is a , instead of a .

Using CultureInfo.InvarientCulture solves that problem when converting ToString()
  • Loading branch information
bsandmann authored May 17, 2023
1 parent 5cba3cf commit 1f5e684
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class GeoCoordinates
{
public GeoCoordinates(float? latitude, float? longitude)
Expand All @@ -26,5 +28,5 @@ public GeoCoordinates(float? latitude, float? longitude)
public float? Latitude { get; }
public float? Longitude { get; }

public override string ToString() => $"{{latitude:{Latitude},longitude:{Longitude}}}";
public override string ToString() => $"{{latitude:{Latitude.Value.ToString(CultureInfo.InvariantCulture)},longitude:{Longitude.Value.ToString(CultureInfo.InvariantCulture)}}}";
}
4 changes: 3 additions & 1 deletion src/SearchPioneer.Weaviate.Client/Api/Filters/GeoDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class GeoDistance
{
public float? Max { get; set; }

public override string ToString() => $"{{max:{Max}}}";
public override string ToString() => $"{{max:{Max.Value.ToString(CultureInfo.InvariantCulture)}}}";
}
2 changes: 1 addition & 1 deletion src/SearchPioneer.Weaviate.Client/Api/Filters/GeoRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class GeoRange
public override string ToString() =>
Coordinates is { Latitude: { }, Longitude: { } }
&& Distance is { Max: { } }
? $"{{geoCoordinates:{Coordinates.ToString()},distance:{Distance.ToString()}}}"
? $"{{geoCoordinates:{Coordinates},distance:{Distance}}}"
: string.Empty;
}
6 changes: 4 additions & 2 deletions src/SearchPioneer.Weaviate.Client/Api/Filters/Where.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class Where
{
public Where[]? Operands { get; set; }
Expand Down Expand Up @@ -47,7 +49,7 @@ public override string ToString()
{
if (Path is { Length: > 0 }) args.Add($"path:[{Path.WrapDoubleQuoteAndJoinWithComma()}]");
if (ValueInt.HasValue) args.Add($"valueInt:{ValueInt}");
if (ValueNumber.HasValue) args.Add($"valueNumber:{ValueNumber}");
if (ValueNumber.HasValue) args.Add($"valueNumber:{ValueNumber.Value.ToString(CultureInfo.InvariantCulture)}");
if (ValueBoolean.HasValue) args.Add($"valueBoolean:{ValueBoolean.Value.ToString().ToLower()}");
if (ValueString != null)
{
Expand All @@ -62,7 +64,7 @@ public override string ToString()
}

if (ValueDate.HasValue) args.Add($"valueDate:\"{ValueDate.Value:o}\"");
if (ValueGeoRange != null) args.Add($"valueGeoRange:{ValueGeoRange}");
if (ValueGeoRange != null) args.Add($"valueGeoRange:{ValueGeoRange.ToString()}");
if (Operator.HasValue) args.Add($"operator:{Operator}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class Ask
{
public string? Question { get; set; }
Expand All @@ -29,8 +31,8 @@ public override string ToString()
var arg = new HashSet<string>();
if (!string.IsNullOrEmpty(Question)) arg.Add($"question:\"{Question}\"");
if (Properties is { Length: > 0 }) arg.Add($"properties: [{Properties.WrapDoubleQuoteAndJoinWithComma()}]");
if (Certainty != null) arg.Add($"certainty:{Certainty}");
if (Distance != null) arg.Add($"distance:{Distance}");
if (Certainty != null) arg.Add($"certainty:{Certainty.Value.ToString(CultureInfo.InvariantCulture)}");
if (Distance != null) arg.Add($"distance:{Distance.Value.ToString(CultureInfo.InvariantCulture)}");
if (Autocorrect != null) arg.Add($"autocorrect:{Autocorrect.ToLower()}");
if (Rerank != null) arg.Add($"rerank:{Rerank.ToLower()}");
var s = string.Join(" ", arg.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class Group
{
public GroupType? Type { get; set; }
Expand All @@ -24,7 +26,7 @@ public override string ToString()
{
var arg = new HashSet<string>();
if (Type != null) arg.Add($"type:{Type.Value.ToString("f").ToLower()}");
if (Force != null) arg.Add($"force:{Force}");
if (Force != null) arg.Add($"force:{Force.Value.ToString(CultureInfo.InvariantCulture)}");
var s = string.Join(" ", arg.ToArray());
return $"group:{{{s}}}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class NearImage
{
public string? Image { get; set; }
Expand All @@ -27,8 +29,8 @@ public override string ToString()
var fields = new HashSet<string>();
var content = GetContent();
if (!string.IsNullOrEmpty(content)) fields.Add($"image:\"{content}\"");
if (Certainty != null) fields.Add($"certainty:{Certainty}");
if (Distance != null) fields.Add($"distance:{Distance}");
if (Certainty != null) fields.Add($"certainty:{Certainty.Value.ToString(CultureInfo.InvariantCulture)}");
if (Distance != null) fields.Add($"distance:{Distance.Value.ToString(CultureInfo.InvariantCulture)}");
var s = string.Join(" ", fields.ToArray());
return $"nearImage:{{{s}}}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class NearObject
{
public string? Id { get; set; }
Expand All @@ -27,8 +29,8 @@ public override string ToString()
var arg = new HashSet<string>();
if (!string.IsNullOrEmpty(Id)) arg.Add($"id:\"{Id}\"");
if (!string.IsNullOrEmpty(Beacon)) arg.Add($"beacon:\"{Beacon}\"");
if (Certainty != null) arg.Add($"certainty:{Certainty}");
if (Distance != null) arg.Add($"distance:{Distance}");
if (Certainty != null) arg.Add($"certainty:{Certainty.Value.ToString(CultureInfo.InvariantCulture)}");
if (Distance != null) arg.Add($"distance:{Distance.Value.ToString(CultureInfo.InvariantCulture)}");
var s = string.Join(" ", arg.ToArray());
return $"nearObject:{{{s}}}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class NearText
{
public string[]? Concepts { get; set; } // TODO! change to class with object equivalency for arrays and single items
Expand All @@ -28,8 +30,8 @@ public override string ToString()
{
var arg = new HashSet<string>();
if (Concepts is { Length: > 0 }) arg.Add($"concepts: [{Concepts.WrapDoubleQuoteAndJoinWithComma()}]");
if (Certainty != null) arg.Add($"certainty:{Certainty}");
if (Distance != null) arg.Add($"distance:{Distance}");
if (Certainty != null) arg.Add($"certainty:{Certainty.Value.ToString(CultureInfo.InvariantCulture)}");
if (Distance != null) arg.Add($"distance:{Distance.Value.ToString(CultureInfo.InvariantCulture)}");
if (MoveTo != null) arg.Add($"moveTo:{{{MoveTo}}}");
if (MoveAwayFrom != null) arg.Add($"moveAwayFrom:{{{MoveAwayFrom}}}");
if (Autocorrect != null) arg.Add($"autocorrect:{Autocorrect.ToLower()}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// ReSharper disable once CheckNamespace
namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class NearTextMoveParameters
{
public string[]? Concepts { get; set; }
Expand All @@ -25,7 +27,7 @@ public override string ToString()
{
var arg = new HashSet<string>();
if (Concepts is { Length: > 0 }) arg.Add($"concepts: [{Concepts.WrapDoubleQuoteAndJoinWithComma()}]");
if (Force != null) arg.Add($"force:{Force}");
if (Force != null) arg.Add($"force:{Force.Value.ToString(CultureInfo.InvariantCulture)}");
if (Objects is { Length: > 0 })
{
var values = Objects.Select(o => o.ToString()).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,29 @@
// limitations under the License.

// ReSharper disable once CheckNamespace

namespace SearchPioneer.Weaviate.Client;

using System.Globalization;

public class NearVector
{
public float[]? Vector { get; set; }
public float? Certainty { get; set; }
public float? Distance { get; set; }
public float[]? Vector { get; set; }
public float? Certainty { get; set; }
public float? Distance { get; set; }

public override string ToString()
{
var arg = new HashSet<string>();
if (Vector != null)
{
var v = string.Join(",", Vector);
arg.Add($"vector: [{v}]");
}
public override string ToString()
{
var arg = new HashSet<string>();
if (Vector != null)
{
var v = string.Join(",", Vector.Select(p => p.ToString(CultureInfo.InvariantCulture)));
arg.Add($"vector: [{v}]");
}

if (Certainty != null) arg.Add($"certainty:{Certainty}");
if (Distance != null) arg.Add($"distance:{Distance}");
var s = string.Join(" ", arg.ToArray());
return $"nearVector:{{{s}}}";
}
if (Certainty != null) arg.Add($"certainty:{Certainty.Value.ToString(CultureInfo.InvariantCulture)}");
if (Distance != null) arg.Add($"distance:{Distance.Value.ToString(CultureInfo.InvariantCulture)}");
var s = string.Join(" ", arg.ToArray());
return $"nearVector:{{{s}}}";
}
}

0 comments on commit 1f5e684

Please sign in to comment.