Skip to content

Commit

Permalink
Added specific comparison for geographic typed literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco De Salvo committed May 28, 2024
1 parent 7246436 commit 737b91a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RDFSharp.Test/Query/RDFQueryUtilitiesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public void ShouldCompareNullPatternMembers(string leftVal, string rightVal, int
[DataRow("P1Y^^http://www.w3.org/2001/XMLSchema#duration", "lit@en-US", -99)]
[DataRow("25^^http://www.w3.org/2001/XMLSchema#integer", "P1Y^^http://www.w3.org/2001/XMLSchema#duration", -99)]
[DataRow("P1Y^^http://www.w3.org/2001/XMLSchema#duration", "25^^http://www.w3.org/2001/XMLSchema#integer", -99)]
[DataRow("POINT (9.18854 45)^^http://www.opengis.net/ont/geosparql#wktLiteral", "POINT (9.18854 45)^^http://www.opengis.net/ont/geosparql#wktLiteral", 0)]
[DataRow("POINT (9.28854 50)^^http://www.opengis.net/ont/geosparql#wktLiteral", "POINT (9.18854 45)^^http://www.opengis.net/ont/geosparql#wktLiteral", 1)]
[DataRow("POINT (9.08854 40)^^http://www.opengis.net/ont/geosparql#wktLiteral", "POINT (9.18854 45)^^http://www.opengis.net/ont/geosparql#wktLiteral", -1)]
[DataRow("POINT (9.18854 45)^^http://www.opengis.net/ont/geosparql#wktLiteral", "25^^http://www.w3.org/2001/XMLSchema#integer", -99)]
public void ShouldCompareNotNullPatternMembers(string leftVal, string rightVal, int expectedCompare)
{
RDFPatternMember leftPMember = RDFQueryUtilities.ParseRDFPatternMember(leftVal);
Expand Down
19 changes: 19 additions & 0 deletions RDFSharp/Query/RDFQueryUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
using System.Globalization;
using System.Net;
using System.Xml;
using NetTopologySuite.Geometries;

namespace RDFSharp.Query
{
Expand Down Expand Up @@ -172,6 +173,24 @@ internal static int CompareRDFPatternMembers(RDFPatternMember left, RDFPatternMe
return -99; //Type Error
}

//GEOGRAPHIC
if (((RDFTypedLiteral)left).HasGeographicDatatype())
{
if (((RDFTypedLiteral)right).HasGeographicDatatype())
{
Geometry leftGeometry = ((RDFTypedLiteral)left).Datatype.ToString().Equals(RDFVocabulary.GEOSPARQL.WKT_LITERAL.ToString())
? RDFGeoExpression.WKTReader.Read(((RDFTypedLiteral)left).Value)
: RDFGeoExpression.GMLReader.Read(((RDFTypedLiteral)left).Value);
leftGeometry.SRID = 4326;
Geometry rightGeometry = ((RDFTypedLiteral)right).Datatype.ToString().Equals(RDFVocabulary.GEOSPARQL.WKT_LITERAL.ToString())
? RDFGeoExpression.WKTReader.Read(((RDFTypedLiteral)right).Value)
: RDFGeoExpression.GMLReader.Read(((RDFTypedLiteral)right).Value);
rightGeometry.SRID = 4326;
return leftGeometry.CompareTo(rightGeometry);
}
return -99; //Type Error
}

//TIMESPAN
if (((RDFTypedLiteral)left).HasTimespanDatatype())
{
Expand Down

0 comments on commit 737b91a

Please sign in to comment.