Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Nov 3, 2023
1 parent 67bc042 commit 5232949
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void ShouldApplyExpressionWithEVAndNotCalculateResultBecauseZeroRightExpr
DataRow row = table.NewRow();
row["?A"] = new RDFTypedLiteral("50", RDFModelEnums.RDFDatatypes.XSD_DOUBLE).ToString();
row["?B"] = new RDFTypedLiteral("25", RDFModelEnums.RDFDatatypes.XSD_INT).ToString();
row["?C"] = new RDFTypedLiteral("0", RDFModelEnums.RDFDatatypes.XSD_INT).ToString();
row["?C"] = RDFTypedLiteral.Zero.ToString();
table.Rows.Add(row);
table.AcceptChanges();

Expand Down Expand Up @@ -468,7 +468,7 @@ public void ShouldApplyExpressionWithVVAndNotCalculateResultBecauseZeroRightColu
table.Columns.Add("?B", typeof(string));
DataRow row = table.NewRow();
row["?A"] = new RDFTypedLiteral("5", RDFModelEnums.RDFDatatypes.XSD_DOUBLE).ToString();
row["?B"] = new RDFTypedLiteral("0", RDFModelEnums.RDFDatatypes.XSD_NONNEGATIVEINTEGER).ToString();
row["?B"] = RDFTypedLiteral.Zero.ToString();
table.Rows.Add(row);
table.AcceptChanges();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void ShouldApplyExpressionWithEXPAndCalculateResult()
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]);

Assert.IsNotNull(expressionResult);
Assert.IsTrue(expressionResult.Equals(new RDFTypedLiteral("0", RDFModelEnums.RDFDatatypes.XSD_INTEGER)));
Assert.IsTrue(expressionResult.Equals(RDFTypedLiteral.Zero));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void ShouldApplyExpressionWithExpressionAndCalculateResultOnNull()
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]);

Assert.IsNotNull(expressionResult);
Assert.IsTrue(expressionResult.Equals(new RDFTypedLiteral("0", RDFModelEnums.RDFDatatypes.XSD_INTEGER)));
Assert.IsTrue(expressionResult.Equals(RDFTypedLiteral.Zero));
}

[TestMethod]
Expand Down
8 changes: 2 additions & 6 deletions RDFSharp/Model/RDFGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ public RDFGraph AddContainer(RDFContainer container)
if (container != null)
{
//Reify the container to get its graph representation
RDFGraph reifCont = container.ReifyContainer();
//Iterate on the constructed triples
foreach (RDFTriple t in reifCont)
foreach (RDFTriple t in container.ReifyContainer())
AddTriple(t);
}
return this;
Expand All @@ -217,9 +215,7 @@ public RDFGraph AddCollection(RDFCollection collection)
if (collection != null)
{
//Reify the collection to get its graph representation
RDFGraph reifColl = collection.ReifyCollection();
//Iterate on the constructed triples
foreach (RDFTriple t in reifColl)
foreach (RDFTriple t in collection.ReifyCollection())
AddTriple(t);
}
return this;
Expand Down
12 changes: 6 additions & 6 deletions RDFSharp/Model/RDFNamespaceRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static void AddNamespace(RDFNamespace nSpace)
public static void RemoveByUri(string uri)
{
if (uri != null)
Instance.Register.RemoveAll(ns => ns.NamespaceUri.ToString().Equals(uri.Trim(), StringComparison.OrdinalIgnoreCase));
Instance.Register.RemoveAll(ns => string.Equals(ns.NamespaceUri.ToString(), uri.Trim(), StringComparison.OrdinalIgnoreCase));
}

/// <summary>
Expand All @@ -166,7 +166,7 @@ public static void RemoveByUri(string uri)
public static void RemoveByPrefix(string prefix)
{
if (prefix != null)
Instance.Register.RemoveAll(ns => ns.NamespacePrefix.Equals(prefix.Trim(), StringComparison.OrdinalIgnoreCase));
Instance.Register.RemoveAll(ns => string.Equals(ns.NamespacePrefix, prefix.Trim(), StringComparison.OrdinalIgnoreCase));
}

/// <summary>
Expand All @@ -176,7 +176,7 @@ public static RDFNamespace GetByUri(string uri, bool enablePrefixCCService = fal
{
if (uri != null)
{
RDFNamespace result = Instance.Register.Find(ns => ns.NamespaceUri.ToString().Equals(uri.Trim(), StringComparison.OrdinalIgnoreCase));
RDFNamespace result = Instance.Register.Find(ns => string.Equals(ns.NamespaceUri.ToString(), uri.Trim(), StringComparison.OrdinalIgnoreCase));
if (result == null && enablePrefixCCService)
result = LookupPrefixCC(uri.Trim().TrimEnd(new char[] { '#' }), 2);
return result;
Expand All @@ -191,7 +191,7 @@ public static RDFNamespace GetByPrefix(string prefix, bool enablePrefixCCService
{
if (prefix != null)
{
RDFNamespace result = Instance.Register.Find(ns => ns.NamespacePrefix.Equals(prefix.Trim(), StringComparison.OrdinalIgnoreCase));
RDFNamespace result = Instance.Register.Find(ns => string.Equals(ns.NamespacePrefix, prefix.Trim(), StringComparison.OrdinalIgnoreCase));
if (result == null && enablePrefixCCService)
result = LookupPrefixCC(prefix.Trim(), 1);
return result;
Expand All @@ -213,10 +213,10 @@ internal static RDFNamespace LookupPrefixCC(string data, int lookupMode)
{
string response = webclient.DownloadString(lookupString);
string prefix = response.Split('\t')[0];
string nspace = response.Split('\t')[1].TrimEnd(new char[] { '\n' });
string nspace = response.Split('\t')[1].TrimEnd(Environment.NewLine);
RDFNamespace result = new RDFNamespace(prefix, nspace);

//Also add the namespace to the register, to avoid future lookups
//Also add the namespace to the register (to avoid future lookups)
AddNamespace(result);

//Return the found result
Expand Down
5 changes: 5 additions & 0 deletions RDFSharp/Model/RDFTypedLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class RDFTypedLiteral : RDFLiteral
/// Represents an handy typed literal for boolean False
/// </summary>
public static readonly RDFTypedLiteral False = new RDFTypedLiteral("false", RDFModelEnums.RDFDatatypes.XSD_BOOLEAN);

/// <summary>
/// Represents an handy typed literal for integer Zero
/// </summary>
public static readonly RDFTypedLiteral Zero = new RDFTypedLiteral("0", RDFModelEnums.RDFDatatypes.XSD_INTEGER);
#endregion

#region Ctors
Expand Down

0 comments on commit 5232949

Please sign in to comment.