From 681053f82949c98b5648983cd1057da7ed18978f Mon Sep 17 00:00:00 2001 From: mdesalvo Date: Mon, 27 May 2024 20:09:57 +0200 Subject: [PATCH] Drop support for RDFFractionDigitsFacet --- .../Facets/RDFFractionDigitsFacetTest.cs | 87 ------------------- RDFSharp.Test/Model/RDFGraphTest.cs | 6 -- .../Model/Facets/RDFFractionDigitsFacet.cs | 68 --------------- RDFSharp/Model/Facets/RDFPatternFacet.cs | 3 - RDFSharp/Model/RDFModelUtilities.cs | 7 -- RDFSharp/Model/Vocabularies/XSD.cs | 5 -- 6 files changed, 176 deletions(-) delete mode 100644 RDFSharp.Test/Model/Facets/RDFFractionDigitsFacetTest.cs delete mode 100644 RDFSharp/Model/Facets/RDFFractionDigitsFacet.cs diff --git a/RDFSharp.Test/Model/Facets/RDFFractionDigitsFacetTest.cs b/RDFSharp.Test/Model/Facets/RDFFractionDigitsFacetTest.cs deleted file mode 100644 index 2b043c21..00000000 --- a/RDFSharp.Test/Model/Facets/RDFFractionDigitsFacetTest.cs +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright 2012-2024 Marco De Salvo - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using RDFSharp.Model; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Linq; - -namespace RDFSharp.Test.Model -{ - [TestClass] - public class RDFFractionDigitsFacetTest - { - #region Tests - [TestMethod] - - public void ShouldCreateFractionDigitsFacet() - { - RDFFractionDigitsFacet facet = new RDFFractionDigitsFacet(2); - - Assert.IsNotNull(facet); - Assert.IsTrue(facet.AllowedDigits == 2); - Assert.IsTrue(facet.URI.IsBlank); - } - - [TestMethod] - - public void ShouldValidateFractionDigitsFacet() - { - RDFFractionDigitsFacet facet = new RDFFractionDigitsFacet(2); - - Assert.IsTrue(facet.Validate("-2.00")); - Assert.IsTrue(facet.Validate("-2.77")); - Assert.IsTrue(facet.Validate("-2")); - Assert.IsTrue(facet.Validate("2")); - Assert.IsTrue(facet.Validate("2.00")); - Assert.IsTrue(facet.Validate("2.77")); - Assert.IsFalse(facet.Validate(null)); - Assert.IsFalse(facet.Validate(string.Empty)); - Assert.IsFalse(facet.Validate("2.000")); - Assert.IsFalse(facet.Validate("2.5773")); - Assert.IsFalse(facet.Validate("2.57.73")); - Assert.IsFalse(facet.Validate("-2.009")); - Assert.IsFalse(facet.Validate("abcdefgh")); - - RDFFractionDigitsFacet facet0 = new RDFFractionDigitsFacet(0); - Assert.IsFalse(facet0.Validate("-2.00")); - Assert.IsFalse(facet0.Validate("-2.77")); - Assert.IsTrue(facet0.Validate("-2")); - Assert.IsTrue(facet0.Validate("2")); - Assert.IsFalse(facet0.Validate("2.00")); - Assert.IsFalse(facet0.Validate("2.77")); - Assert.IsFalse(facet0.Validate(null)); - Assert.IsFalse(facet0.Validate(string.Empty)); - Assert.IsFalse(facet0.Validate("2.000")); - Assert.IsFalse(facet0.Validate("2.5773")); - Assert.IsFalse(facet0.Validate("-2.009")); - Assert.IsFalse(facet0.Validate("abcdefgh")); - } - - [TestMethod] - - public void ShouldConvertFractionDigitsFacetToGraph() - { - RDFFractionDigitsFacet facet = new RDFFractionDigitsFacet(2); - RDFGraph graph = facet.ToRDFGraph(); - - Assert.IsNotNull(graph); - Assert.IsTrue(graph.TriplesCount == 1); - Assert.IsTrue(graph.Single().Predicate.Equals(RDFVocabulary.XSD.FRACTION_DIGITS)); - Assert.IsTrue(graph.Single().Object.Equals(new RDFTypedLiteral("2", RDFDatatypeRegister.GetDatatype(RDFVocabulary.XSD.NON_NEGATIVE_INTEGER.ToString())))); - } - #endregion - } -} \ No newline at end of file diff --git a/RDFSharp.Test/Model/RDFGraphTest.cs b/RDFSharp.Test/Model/RDFGraphTest.cs index abb5f9f0..3960cdca 100644 --- a/RDFSharp.Test/Model/RDFGraphTest.cs +++ b/RDFSharp.Test/Model/RDFGraphTest.cs @@ -1924,7 +1924,6 @@ public void ShouldRaiseExceptionOnImportingFromRelativeUri() [TestMethod] public void ShouldExtractDatatypeDefinitionsFromGraph() { - RDFDatatype exFractionDigits6 = new RDFDatatype(new Uri("ex:fractiondigits6"), RDFModelEnums.RDFDatatypes.XSD_DOUBLE, [new RDFFractionDigitsFacet(6)]); RDFDatatype exLength6 = new RDFDatatype(new Uri("ex:length6"), RDFModelEnums.RDFDatatypes.XSD_STRING, [ new RDFLengthFacet(6) ]); RDFDatatype exMinLength6 = new RDFDatatype(new Uri("ex:minlength6"), RDFModelEnums.RDFDatatypes.XSD_STRING, [ new RDFMinLengthFacet(6) ]); RDFDatatype exMaxLength6 = new RDFDatatype(new Uri("ex:maxlength6"), RDFModelEnums.RDFDatatypes.XSD_STRING, [ new RDFMaxLengthFacet(6) ]); @@ -1935,7 +1934,6 @@ public void ShouldExtractDatatypeDefinitionsFromGraph() RDFDatatype exPatternEx = new RDFDatatype(new Uri("ex:patternex"), RDFModelEnums.RDFDatatypes.XSD_STRING, [ new RDFPatternFacet("^ex") ]); RDFDatatype exInteger = new RDFDatatype(new Uri("ex:integer"), RDFModelEnums.RDFDatatypes.XSD_INTEGER, null); RDFGraph graph = new RDFGraph() - .AddDatatype(exFractionDigits6) .AddDatatype(exLength6) .AddDatatype(exMinLength6) .AddDatatype(exMaxLength6) @@ -1947,10 +1945,6 @@ public void ShouldExtractDatatypeDefinitionsFromGraph() .AddDatatype(exInteger); List datatypes = graph.ExtractDatatypeDefinitions(); - Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:fractiondigits6") - && dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_DOUBLE - && dt.Facets.Single() is RDFFractionDigitsFacet fractiondigitsFacet - && fractiondigitsFacet.AllowedDigits == 6)); Assert.IsTrue(datatypes.Any(dt => string.Equals(dt.URI.ToString(), "ex:length6") && dt.TargetDatatype == RDFModelEnums.RDFDatatypes.XSD_STRING && dt.Facets.Single() is RDFLengthFacet lengthFacet diff --git a/RDFSharp/Model/Facets/RDFFractionDigitsFacet.cs b/RDFSharp/Model/Facets/RDFFractionDigitsFacet.cs deleted file mode 100644 index ff0d6aa4..00000000 --- a/RDFSharp/Model/Facets/RDFFractionDigitsFacet.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - Copyright 2012-2024 Marco De Salvo - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.Collections.Generic; -using System.Globalization; - -namespace RDFSharp.Model -{ - /// - /// RDFFractionDigitsFacet represents a constraint requiring the values of a literal to have a maximum number of fraction digits - /// - public class RDFFractionDigitsFacet : RDFFacet - { - #region Properties - /// - /// Maximum number of fraction digits allowed by the facet - /// - public uint AllowedDigits { get; internal set; } - #endregion - - #region Ctors - /// - /// Builds a facet allowing the given maximum number of fraction digits - /// - public RDFFractionDigitsFacet(uint allowedDigits) - => AllowedDigits = allowedDigits; - #endregion - - #region Methods - /// - /// Gives a graph representation of the FractionDigits facet - /// - public override RDFGraph ToRDFGraph() - => new RDFGraph(new List() { - new RDFTriple(URI, RDFVocabulary.XSD.FRACTION_DIGITS, new RDFTypedLiteral(Convert.ToString(AllowedDigits, CultureInfo.InvariantCulture), RDFModelEnums.RDFDatatypes.XSD_NONNEGATIVEINTEGER)) }); - - /// - /// Validates the given literal value against the FractionDigits facet - /// - public override bool Validate(string literalValue) - { - if (double.TryParse(literalValue, NumberStyles.Float, CultureInfo.InvariantCulture, out double _)) - { - if (literalValue.IndexOf(NumberFormatInfo.InvariantInfo.NumberDecimalSeparator) == -1) - return true; - - string fractionDigits = literalValue.Split(NumberFormatInfo.InvariantInfo.NumberDecimalSeparator[0])[1]; - return fractionDigits.Length <= AllowedDigits; - } - return false; - } - #endregion - } -} \ No newline at end of file diff --git a/RDFSharp/Model/Facets/RDFPatternFacet.cs b/RDFSharp/Model/Facets/RDFPatternFacet.cs index ae431789..f6ea3ebd 100644 --- a/RDFSharp/Model/Facets/RDFPatternFacet.cs +++ b/RDFSharp/Model/Facets/RDFPatternFacet.cs @@ -14,11 +14,8 @@ You may obtain a copy of the License at limitations under the License. */ -using System; using System.Collections.Generic; -using System.Globalization; using System.Text.RegularExpressions; -using System.Xml.Schema; namespace RDFSharp.Model { diff --git a/RDFSharp/Model/RDFModelUtilities.cs b/RDFSharp/Model/RDFModelUtilities.cs index 8f93a115..573bb2a3 100644 --- a/RDFSharp/Model/RDFModelUtilities.cs +++ b/RDFSharp/Model/RDFModelUtilities.cs @@ -335,13 +335,6 @@ public static List ExtractDatatypeDefinitions(this RDFGraph graph) RDFCollection facetsCollection = DeserializeCollectionFromGraph(graph, facetsRepresentative, RDFModelEnums.RDFTripleFlavors.SPO); foreach (RDFResource facet in facetsCollection.Items.Cast()) { - //xsd:fractionDigits - if (graph[facet, RDFVocabulary.XSD.FRACTION_DIGITS, null, null].FirstOrDefault()?.Object is RDFTypedLiteral facetFractionDigits - && facetFractionDigits.HasDecimalDatatype() && uint.TryParse(facetFractionDigits.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out uint facetFractionDigitsValue)) - { - targetFacets.Add(new RDFFractionDigitsFacet(facetFractionDigitsValue)); - continue; - } //xsd:length if (graph[facet, RDFVocabulary.XSD.LENGTH, null, null].FirstOrDefault()?.Object is RDFTypedLiteral facetLength && facetLength.HasDecimalDatatype() && uint.TryParse(facetLength.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out uint facetLengthValue)) diff --git a/RDFSharp/Model/Vocabularies/XSD.cs b/RDFSharp/Model/Vocabularies/XSD.cs index 9eb86381..570c80df 100644 --- a/RDFSharp/Model/Vocabularies/XSD.cs +++ b/RDFSharp/Model/Vocabularies/XSD.cs @@ -284,11 +284,6 @@ public static class XSD /// xsd:minInclusive /// public static readonly RDFResource MIN_INCLUSIVE = new RDFResource(string.Concat(XSD.BASE_URI, "minInclusive")); - - /// - /// xsd:fractionDigits - /// - public static readonly RDFResource FRACTION_DIGITS = new RDFResource(string.Concat(XSD.BASE_URI, "fractionDigits")); #endregion } #endregion