Skip to content

Commit

Permalink
Code optimizations + Added validation of GeoSPARQL typed literals
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo authored Sep 16, 2023
1 parent 0bd55cb commit fdaf2a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions RDFSharp.Test/Model/RDFTypedLiteralTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class RDFTypedLiteralTest
[DataRow("{}", RDFModelEnums.RDFDatatypes.RDF_JSON)]
[DataRow("[{\"value\":25}]", RDFModelEnums.RDFDatatypes.RDF_JSON)]
[DataRow("[]", RDFModelEnums.RDFDatatypes.RDF_JSON)]
[DataRow("POINT(12.496365 41.902782)", RDFModelEnums.RDFDatatypes.GEOSPARQL_WKT)]
[DataRow("<gml:Point xmlns:gml=\"http://www.opengis.net/gml/3.2\"><gml:pos>12.496365 41.902782</gml:pos></gml:Point>", RDFModelEnums.RDFDatatypes.GEOSPARQL_GML)]
[DataRow("http://hello/world#hi", RDFModelEnums.RDFDatatypes.XSD_ANYURI)]
[DataRow("http://hello/world#", RDFModelEnums.RDFDatatypes.XSD_ANYURI)]
[DataRow("http://hello/world/", RDFModelEnums.RDFDatatypes.XSD_ANYURI)]
Expand Down Expand Up @@ -318,6 +320,8 @@ public void ShouldCreateTypedLiteralOfTimeSpanCategory(string value, RDFModelEnu
[DataRow("value:", RDFModelEnums.RDFDatatypes.RDF_JSON)]
[DataRow("[{value:}", RDFModelEnums.RDFDatatypes.RDF_JSON)]
[DataRow("{value:}]", RDFModelEnums.RDFDatatypes.RDF_JSON)]
[DataRow("POINT(12.496365)", RDFModelEnums.RDFDatatypes.GEOSPARQL_WKT)]
[DataRow("<gml:Point xmlns:gml=\"http://www.opengis.net/gml/3.2\"><gml:pos>12.496365</gml:pos></gml:Point>", RDFModelEnums.RDFDatatypes.GEOSPARQL_GML)]
[DataRow("hello", RDFModelEnums.RDFDatatypes.XSD_ANYURI)]
[DataRow("http:/hello#", RDFModelEnums.RDFDatatypes.XSD_ANYURI)]
[DataRow("http:// ", RDFModelEnums.RDFDatatypes.XSD_ANYURI)]
Expand Down
17 changes: 14 additions & 3 deletions RDFSharp/Model/RDFModelUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ limitations under the License.
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using NetTopologySuite.Geometries;
using NetTopologySuite.Geometries.Prepared;
using RDFSharp.Query;

namespace RDFSharp.Model
{
Expand Down Expand Up @@ -610,12 +613,20 @@ bool TryParseDateTime(string value, string formatToParse, string formatToConvert
#region STRING CATEGORY
case RDFModelEnums.RDFDatatypes.RDFS_LITERAL:
case RDFModelEnums.RDFDatatypes.XSD_STRING:
case RDFModelEnums.RDFDatatypes.RDF_HTML:
case RDFModelEnums.RDFDatatypes.GEOSPARQL_WKT:
case RDFModelEnums.RDFDatatypes.GEOSPARQL_GML:
case RDFModelEnums.RDFDatatypes.RDF_HTML:
default:
return true;

case RDFModelEnums.RDFDatatypes.GEOSPARQL_WKT:
case RDFModelEnums.RDFDatatypes.GEOSPARQL_GML:
try
{
_ = typedLiteral.Datatype.Equals(RDFModelEnums.RDFDatatypes.GEOSPARQL_WKT) ?
RDFGeoExpression.WKTReader.Read(typedLiteral.Value) : RDFGeoExpression.GMLReader.Read(typedLiteral.Value);
return true;
}
catch { return false; }

case RDFModelEnums.RDFDatatypes.RDF_XMLLITERAL:
try
{
Expand Down
3 changes: 2 additions & 1 deletion RDFSharp/Model/RDFPlainLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class RDFPlainLiteral : RDFLiteral
/// <summary>
/// Regex for validation of language tags
/// </summary>
internal static readonly Lazy<Regex> LangTag = new Lazy<Regex>(() => new Regex("^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$", RegexOptions.Compiled));
internal static readonly Lazy<Regex> LangTag = new Lazy<Regex>(() => LangTagRegex);
internal static readonly Regex LangTagRegex = new Regex("^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$", RegexOptions.Compiled);

/// <summary>
/// Optional language of the plain literal
Expand Down

0 comments on commit fdaf2a4

Please sign in to comment.