diff --git a/RDFSharp/Model/RDFModelUtilities.cs b/RDFSharp/Model/RDFModelUtilities.cs index 2f381803..0d49206d 100644 --- a/RDFSharp/Model/RDFModelUtilities.cs +++ b/RDFSharp/Model/RDFModelUtilities.cs @@ -90,7 +90,7 @@ internal static Uri GetUriFromString(string uriString) // blank node detection and normalization if (uriString?.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase) ?? false) uriString = string.Concat("bnode:", uriString.Substring(6)); - else if (uriString?.StartsWith("_:") ?? false) + else if (uriString?.StartsWith("_:", StringComparison.Ordinal) ?? false) uriString = string.Concat("bnode:", uriString.Substring(2)); Uri.TryCreate(uriString, UriKind.Absolute, out Uri tempUri); @@ -188,7 +188,7 @@ internal static string TrimEnd(this string source, string value) { if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(value) - || !source.EndsWith(value)) + || !source.EndsWith(value, StringComparison.Ordinal)) return source; return source.Remove(source.LastIndexOf(value, StringComparison.Ordinal)); @@ -527,13 +527,13 @@ internal static List GetGraphNamespaces(RDFGraph graph) : string.Empty; //Resolve subject Uri - result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => subj.StartsWith(ns.ToString()))); + result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => subj.StartsWith(ns.ToString(), StringComparison.Ordinal))); //Resolve predicate Uri - result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => pred.StartsWith(ns.ToString()))); + result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => pred.StartsWith(ns.ToString(), StringComparison.Ordinal))); //Resolve object Uri - result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => obj.StartsWith(ns.ToString()))); + result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => obj.StartsWith(ns.ToString(), StringComparison.Ordinal))); } return result.Distinct().ToList(); } @@ -593,8 +593,8 @@ internal static (bool,string) ValidateTypedLiteral(string literalValue, RDFModel catch { return (false, literalValue); } case RDFModelEnums.RDFDatatypes.RDF_JSON: - bool isValidJson = (literalValue.StartsWith("{") && literalValue.EndsWith("}")) - || (literalValue.StartsWith("[") && literalValue.EndsWith("]")); + bool isValidJson = (literalValue.StartsWith("{", StringComparison.Ordinal) && literalValue.EndsWith("}", StringComparison.Ordinal)) + || (literalValue.StartsWith("[", StringComparison.Ordinal) && literalValue.EndsWith("]", StringComparison.Ordinal)); return (isValidJson, literalValue); case RDFModelEnums.RDFDatatypes.XSD_ANYURI: diff --git a/RDFSharp/Model/Serializers/RDFNTriples.cs b/RDFSharp/Model/Serializers/RDFNTriples.cs index 63c06f5f..00dc57c2 100644 --- a/RDFSharp/Model/Serializers/RDFNTriples.cs +++ b/RDFSharp/Model/Serializers/RDFNTriples.cs @@ -221,7 +221,7 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) ntriple = ntriple.Trim(trimmableChars); //Skip empty or comment lines - if (ntriple == string.Empty || ntriple.StartsWith("#")) + if (ntriple == string.Empty || ntriple.StartsWith("#", StringComparison.Ordinal)) continue; //Tokenizes the sanitized triple @@ -244,9 +244,9 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) #endregion #region object - if (tokens[2].StartsWith("<") - || tokens[2].StartsWith("bnode:") - || tokens[2].StartsWith("_:")) + if (tokens[2].StartsWith("<", StringComparison.Ordinal) + || tokens[2].StartsWith("bnode:", StringComparison.OrdinalIgnoreCase) + || tokens[2].StartsWith("_:", StringComparison.Ordinal)) { string obj = tokens[2].TrimStart(openingBrackets) .TrimEnd(closingBrackets) @@ -274,13 +274,13 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) #region plain literal if (!tokens[2].Contains("^^") - || tokens[2].EndsWith("^^") + || tokens[2].EndsWith("^^", StringComparison.Ordinal) || tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") { if (regexLPL.Value.Match(tokens[2]).Success) { tokens[2] = tokens[2].Replace("\"@", "@"); - int lastIndexOfLanguage = tokens[2].LastIndexOf("@", StringComparison.OrdinalIgnoreCase); + int lastIndexOfLanguage = tokens[2].LastIndexOf("@", StringComparison.Ordinal); string pLitValue = tokens[2].Substring(0, lastIndexOfLanguage); string pLitLang = tokens[2].Substring(lastIndexOfLanguage + 1); L = new RDFPlainLiteral(HttpUtility.HtmlDecode(pLitValue), pLitLang); @@ -294,7 +294,7 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) else { tokens[2] = tokens[2].Replace("\"^^", "^^"); - int lastIndexOfDatatype = tokens[2].LastIndexOf("^^", StringComparison.OrdinalIgnoreCase); + int lastIndexOfDatatype = tokens[2].LastIndexOf("^^", StringComparison.Ordinal); string tLitValue = tokens[2].Substring(0, lastIndexOfDatatype); string tLitDatatype = tokens[2].Substring(lastIndexOfDatatype + 2) .TrimStart('<') @@ -332,13 +332,13 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) private static string[] TokenizeNTriple(string ntriple) { //A legal N-Triple starts with "_:" (blank) or "<" (uri) - if (!ntriple.StartsWith("_:") && !ntriple.StartsWith("<")) + if (!ntriple.StartsWith("_:", StringComparison.Ordinal) && !ntriple.StartsWith("<", StringComparison.Ordinal)) throw new Exception("found illegal N-Triple, must start with \"_:\" or with \"<\""); string[] tokens = new string[3]; //S->-> triple - if (ntriple.StartsWith("<")) + if (ntriple.StartsWith("<", StringComparison.Ordinal)) { //S->P->O if (SPO.Value.Match(ntriple).Success) diff --git a/RDFSharp/Model/Serializers/RDFTriX.cs b/RDFSharp/Model/Serializers/RDFTriX.cs index ee2dd990..de725e21 100644 --- a/RDFSharp/Model/Serializers/RDFTriX.cs +++ b/RDFSharp/Model/Serializers/RDFTriX.cs @@ -301,7 +301,7 @@ internal static void ParseTriXTriple(RDFGraph result, XmlNode graphChild, Dictio //Sanitize eventual blank node value if (graphChild.ChildNodes[0].Name.Equals("id", StringComparison.Ordinal)) { - if (!graphChild.ChildNodes[0].InnerText.StartsWith("bnode:")) + if (!graphChild.ChildNodes[0].InnerText.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) graphChild.ChildNodes[0].InnerText = string.Concat("bnode:", graphChild.ChildNodes[0].InnerText.Replace("_:", string.Empty)); } } @@ -331,7 +331,7 @@ internal static void ParseTriXTriple(RDFGraph result, XmlNode graphChild, Dictio //Sanitize eventual blank node value if (graphChild.ChildNodes[2].Name.Equals("id", StringComparison.Ordinal)) { - if (!graphChild.ChildNodes[2].InnerText.StartsWith("bnode:")) + if (!graphChild.ChildNodes[2].InnerText.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) graphChild.ChildNodes[2].InnerText = string.Concat("bnode:", graphChild.ChildNodes[2].InnerText.Replace("_:", string.Empty)); } diff --git a/RDFSharp/Model/Serializers/RDFTurtle.cs b/RDFSharp/Model/Serializers/RDFTurtle.cs index 73d58aa9..f9798f08 100644 --- a/RDFSharp/Model/Serializers/RDFTurtle.cs +++ b/RDFSharp/Model/Serializers/RDFTurtle.cs @@ -272,14 +272,14 @@ internal static void ParseStatement(string turtleData, RDFTurtleContext turtleCo } while (sb.Length < 8); string directive = sb.ToString(); - if (directive.StartsWith("@") - || directive.Equals("prefix", StringComparison.InvariantCultureIgnoreCase) - || directive.Equals("base", StringComparison.InvariantCultureIgnoreCase)) + if (directive.StartsWith("@", StringComparison.Ordinal) + || directive.Equals("prefix", StringComparison.OrdinalIgnoreCase) + || directive.Equals("base", StringComparison.OrdinalIgnoreCase)) { ParseDirective(turtleData, turtleContext, result, directive); SkipWhitespace(turtleData, turtleContext); // Turtle @base and @prefix directives MUST end with "." - if (directive.StartsWith("@")) + if (directive.StartsWith("@", StringComparison.Ordinal)) VerifyCharacterOrFail(turtleContext, ReadCodePoint(turtleData, turtleContext), "."); // SPARQL BASE and PREFIX directives MUST NOT end with "." else @@ -963,8 +963,8 @@ internal static object ParseQNameOrBoolean(string turtleData, RDFTurtleContext t { // prefix may actually be a boolean value string value = prefix.ToString(); - if (value.Equals("true", StringComparison.InvariantCultureIgnoreCase) - || value.Equals("false", StringComparison.InvariantCultureIgnoreCase)) + if (value.Equals("true", StringComparison.OrdinalIgnoreCase) + || value.Equals("false", StringComparison.OrdinalIgnoreCase)) { UnreadCodePoint(turtleContext, bufChar); return new RDFTypedLiteral(value, RDFModelEnums.RDFDatatypes.XSD_BOOLEAN); diff --git a/RDFSharp/Model/Serializers/RDFXml.cs b/RDFSharp/Model/Serializers/RDFXml.cs index 65edb5f1..16dc2408 100644 --- a/RDFSharp/Model/Serializers/RDFXml.cs +++ b/RDFSharp/Model/Serializers/RDFXml.cs @@ -170,7 +170,7 @@ internal static void Serialize(RDFGraph graph, Stream outputStream) // XmlAttribute subjNodeDesc; XmlText subjNodeDescText; - if (triplesGroup.Key.StartsWith("bnode:", StringComparison.Ordinal)) + if (triplesGroup.Key.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) { subjNodeDescText = rdfDoc.CreateTextNode(triplesGroup.Key.Replace("bnode:", string.Empty)); subjNodeDesc = rdfDoc.CreateAttribute("rdf:nodeID", RDFVocabulary.RDF.BASE_URI); @@ -250,7 +250,7 @@ internal static void Serialize(RDFGraph graph, Stream outputStream) XmlNode collElementToAppend = rdfDoc.CreateNode(XmlNodeType.Element, "rdf:Description", RDFVocabulary.RDF.BASE_URI); XmlAttribute collElementAttr; XmlText collElementAttrText; - if (collElement.CollectionValue.ToString().StartsWith("bnode:", StringComparison.Ordinal)) + if (collElement.CollectionValue.ToString().StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) { collElementAttrText = rdfDoc.CreateTextNode(collElement.CollectionValue.ToString().Replace("bnode:", string.Empty)); collElementAttr = rdfDoc.CreateAttribute("rdf:nodeID", RDFVocabulary.RDF.BASE_URI); @@ -280,7 +280,7 @@ internal static void Serialize(RDFGraph graph, Stream outputStream) XmlAttribute predNodeDesc; XmlText predNodeDescText; // rdf:nodeID="blankID"> - if (objString.StartsWith("bnode:")) + if (objString.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) { predNodeDescText = rdfDoc.CreateTextNode(objString.Replace("bnode:", string.Empty)); predNodeDesc = rdfDoc.CreateAttribute("rdf:nodeID", RDFVocabulary.RDF.BASE_URI); @@ -526,8 +526,9 @@ private static List ParseNodeList(XmlNodeList nodeList, RDFGraph re if (predNode.NamespaceURI == string.Empty) pred = new RDFResource(string.Concat(xmlBase, predNode.LocalName), hashContext); else - pred = predNode.LocalName.StartsWith("autoNS") ? new RDFResource(predNode.NamespaceURI, hashContext) - : new RDFResource(string.Concat(predNode.NamespaceURI, predNode.LocalName), hashContext); + pred = predNode.LocalName.StartsWith("autoNS", StringComparison.OrdinalIgnoreCase) + ? new RDFResource(predNode.NamespaceURI, hashContext) + : new RDFResource(string.Concat(predNode.NamespaceURI, predNode.LocalName), hashContext); #endregion #region objList @@ -760,7 +761,7 @@ private static List GetAutomaticNamespaces(RDFGraph graph) //Check if the predicate can be abbreviated to a valid QName if (!string.Equals(nspace.NamespaceUri.ToString(), pred)) { - if (nspace.NamespacePrefix.StartsWith("autoNS") && !result.Contains(nspace)) + if (nspace.NamespacePrefix.StartsWith("autoNS", StringComparison.OrdinalIgnoreCase) && !result.Contains(nspace)) result.Add(new RDFNamespace(string.Concat("autoNS", (result.Count + 1).ToString()), nspace.NamespaceUri.ToString())); } else @@ -815,9 +816,9 @@ private static string ResolveRelativeNode(XmlAttribute attr, Uri xmlBase) string xmlBaseString = xmlBase.ToString(); //Adjust corner case for clashes on namespace ending characters ("#", "/") - if (xmlBaseString.EndsWith("#") && attrValue.StartsWith("#")) + if (xmlBaseString.EndsWith("#", StringComparison.Ordinal) && attrValue.StartsWith("#", StringComparison.Ordinal)) attrValue = attrValue.TrimStart('#'); - if (xmlBaseString.EndsWith("/") && attrValue.StartsWith("/")) + if (xmlBaseString.EndsWith("/", StringComparison.Ordinal) && attrValue.StartsWith("/", StringComparison.Ordinal)) attrValue = attrValue.TrimStart('/'); //"rdf:ID" relative Uri: must be resolved against the xmlBase namespace @@ -825,9 +826,9 @@ private static string ResolveRelativeNode(XmlAttribute attr, Uri xmlBase) || string.Equals(attr.LocalName, "ID", StringComparison.OrdinalIgnoreCase)) { //This kind of syntax requires the attribute value to start with "#" - if (!attrValue.StartsWith("#")) + if (!attrValue.StartsWith("#", StringComparison.Ordinal)) attrValue = string.Concat("#", attrValue); - if (xmlBaseString.EndsWith("#")) + if (xmlBaseString.EndsWith("#", StringComparison.Ordinal)) xmlBaseString = xmlBaseString.TrimEnd('#'); attrValue = RDFModelUtilities.GetUriFromString(string.Concat(xmlBaseString, attrValue)).ToString(); } @@ -836,7 +837,7 @@ private static string ResolveRelativeNode(XmlAttribute attr, Uri xmlBase) else if (string.Equals(attr.LocalName, "rdf:nodeID", StringComparison.OrdinalIgnoreCase) || string.Equals(attr.LocalName, "nodeID", StringComparison.OrdinalIgnoreCase)) { - if (!attrValue.StartsWith("bnode:")) + if (!attrValue.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) attrValue = string.Concat("bnode:", attrValue); } @@ -1090,7 +1091,7 @@ private static void ParseContainerElements(RDFModelEnums.RDFContainerTypes contT //Sanitize eventual blank node value detected by presence of "nodeID" attribute if (string.Equals(elemUri.LocalName, "nodeID", StringComparison.OrdinalIgnoreCase)) { - if (!elemUri.Value.StartsWith("bnode:")) + if (!elemUri.Value.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)) elemUri.Value = string.Concat("bnode:", elemUri.Value); } diff --git a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFBooleanExpression.cs b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFBooleanExpression.cs index cde42dd1..b7b364a2 100644 --- a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFBooleanExpression.cs +++ b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFBooleanExpression.cs @@ -28,7 +28,7 @@ public abstract class RDFBooleanExpression : RDFExpression /// /// Default-ctor to build a boolean expression with given arguments /// - public RDFBooleanExpression(RDFExpression leftArgument, RDFExpression rightArgument) + protected RDFBooleanExpression(RDFExpression leftArgument, RDFExpression rightArgument) : base(leftArgument, rightArgument) { #region Guards diff --git a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFDateTimeExpression.cs b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFDateTimeExpression.cs index cc71deef..5a569f9d 100644 --- a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFDateTimeExpression.cs +++ b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFDateTimeExpression.cs @@ -32,12 +32,12 @@ public abstract class RDFDateTimeExpression : RDFExpression /// /// Default-ctor to build a datetime day expression with given arguments /// - public RDFDateTimeExpression(RDFExpression leftArgument) : base(leftArgument, null as RDFExpression) { } + protected RDFDateTimeExpression(RDFExpression leftArgument) : base(leftArgument, null as RDFExpression) { } /// /// Default-ctor to build a datetime day expression with given arguments /// - public RDFDateTimeExpression(RDFVariable leftArgument) : base(leftArgument, null as RDFExpression) { } + protected RDFDateTimeExpression(RDFVariable leftArgument) : base(leftArgument, null as RDFExpression) { } #endregion #region Interfaces diff --git a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFGeoExpression.cs b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFGeoExpression.cs index 14272c56..9a14f16f 100644 --- a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFGeoExpression.cs +++ b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFGeoExpression.cs @@ -62,7 +62,7 @@ public abstract class RDFGeoExpression : RDFExpression /// /// Default-ctor to build a geographic expression with given arguments /// - public RDFGeoExpression(RDFExpressionArgument leftArgument, RDFExpressionArgument rightArgument) + protected RDFGeoExpression(RDFExpressionArgument leftArgument, RDFExpressionArgument rightArgument) : base(leftArgument, rightArgument) { } #endregion diff --git a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFMathExpression.cs b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFMathExpression.cs index 57abde9e..383c4d83 100644 --- a/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFMathExpression.cs +++ b/RDFSharp/Query/Mirella/Algebra/Expressions/Abstractions/RDFMathExpression.cs @@ -32,7 +32,7 @@ public abstract class RDFMathExpression : RDFExpression /// /// Default-ctor to build an arithmetical expression with given arguments /// - public RDFMathExpression(RDFExpression leftArgument, RDFExpression rightArgument) + protected RDFMathExpression(RDFExpression leftArgument, RDFExpression rightArgument) : base(leftArgument, rightArgument) { #region Guards @@ -44,7 +44,7 @@ public RDFMathExpression(RDFExpression leftArgument, RDFExpression rightArgument /// /// Default-ctor to build an arithmetical expression with given arguments /// - public RDFMathExpression(RDFExpression leftArgument, RDFVariable rightArgument) + protected RDFMathExpression(RDFExpression leftArgument, RDFVariable rightArgument) : base(leftArgument, rightArgument) { #region Guards @@ -56,7 +56,7 @@ public RDFMathExpression(RDFExpression leftArgument, RDFVariable rightArgument) /// /// Default-ctor to build an arithmetical expression with given arguments /// - public RDFMathExpression(RDFExpression leftArgument, RDFTypedLiteral rightArgument) + protected RDFMathExpression(RDFExpression leftArgument, RDFTypedLiteral rightArgument) : base(leftArgument, rightArgument) { #region Guards @@ -70,7 +70,7 @@ public RDFMathExpression(RDFExpression leftArgument, RDFTypedLiteral rightArgume /// /// Default-ctor to build an arithmetical expression with given arguments /// - public RDFMathExpression(RDFVariable leftArgument, RDFExpression rightArgument) + protected RDFMathExpression(RDFVariable leftArgument, RDFExpression rightArgument) : base(leftArgument, rightArgument) { #region Guards @@ -82,7 +82,7 @@ public RDFMathExpression(RDFVariable leftArgument, RDFExpression rightArgument) /// /// Default-ctor to build an arithmetical expression with given arguments /// - public RDFMathExpression(RDFVariable leftArgument, RDFVariable rightArgument) + protected RDFMathExpression(RDFVariable leftArgument, RDFVariable rightArgument) : base(leftArgument, rightArgument) { #region Guards @@ -94,7 +94,7 @@ public RDFMathExpression(RDFVariable leftArgument, RDFVariable rightArgument) /// /// Default-ctor to build an arithmetical expression with given arguments /// - public RDFMathExpression(RDFVariable leftArgument, RDFTypedLiteral rightArgument) + protected RDFMathExpression(RDFVariable leftArgument, RDFTypedLiteral rightArgument) : base(leftArgument, rightArgument) { #region Guards diff --git a/RDFSharp/Query/Mirella/Algebra/Filters/RDFIsBlankFilter.cs b/RDFSharp/Query/Mirella/Algebra/Filters/RDFIsBlankFilter.cs index 0d0f41d8..25ca9ecb 100644 --- a/RDFSharp/Query/Mirella/Algebra/Filters/RDFIsBlankFilter.cs +++ b/RDFSharp/Query/Mirella/Algebra/Filters/RDFIsBlankFilter.cs @@ -74,7 +74,7 @@ internal override bool ApplyFilter(DataRow row, bool applyNegation) //Successful match if an absolute Uri starting with "bnode:" prefix can be created with the variable value if (!Uri.TryCreate(variableValue, UriKind.Absolute, out _)) keepRow = false; - keepRow = keepRow && variableValue.StartsWith("bnode:"); + keepRow = keepRow && variableValue.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase); //Apply the eventual negation if (applyNegation) diff --git a/RDFSharp/Query/Mirella/Algebra/Queries/RDFSelectQueryResult.cs b/RDFSharp/Query/Mirella/Algebra/Queries/RDFSelectQueryResult.cs index 3fc8dee2..15dd0226 100644 --- a/RDFSharp/Query/Mirella/Algebra/Queries/RDFSelectQueryResult.cs +++ b/RDFSharp/Query/Mirella/Algebra/Queries/RDFSelectQueryResult.cs @@ -115,7 +115,7 @@ public void ToSparqlXmlResult(Stream outputStream) RDFPatternMember rdfTerm = RDFQueryUtilities.ParseRDFPatternMember(((DataRow)resultRows.Current)[resultColumns.Current.ToString()].ToString()); switch (rdfTerm) { - case RDFResource _ when rdfTerm.ToString().StartsWith("bnode:"): + case RDFResource _ when rdfTerm.ToString().StartsWith("bnode:", StringComparison.OrdinalIgnoreCase): { XmlNode bnodeElement = sparqlDoc.CreateNode(XmlNodeType.Element, "bnode", null); XmlText bnodeElText = sparqlDoc.CreateTextNode(rdfTerm.ToString()); diff --git a/RDFSharp/Query/Mirella/Algebra/RDFExpression.cs b/RDFSharp/Query/Mirella/Algebra/RDFExpression.cs index c6c6013d..aa115839 100644 --- a/RDFSharp/Query/Mirella/Algebra/RDFExpression.cs +++ b/RDFSharp/Query/Mirella/Algebra/RDFExpression.cs @@ -41,25 +41,25 @@ public abstract class RDFExpression : RDFExpressionArgument /// /// Default-ctor to build an expression with given expression arguments /// - public RDFExpression(RDFExpression leftArgument, RDFExpression rightArgument) + protected RDFExpression(RDFExpression leftArgument, RDFExpression rightArgument) : this(leftArgument, rightArgument as RDFExpressionArgument) { } /// /// Default-ctor to build an expression with given mixed arguments /// - public RDFExpression(RDFExpression leftArgument, RDFPatternMember rightArgument) + protected RDFExpression(RDFExpression leftArgument, RDFPatternMember rightArgument) : this(leftArgument, rightArgument as RDFExpressionArgument) { } /// /// Default-ctor to build an expression with given mixed arguments /// - public RDFExpression(RDFPatternMember leftArgument, RDFExpression rightArgument) + protected RDFExpression(RDFPatternMember leftArgument, RDFExpression rightArgument) : this(leftArgument, rightArgument as RDFExpressionArgument) { } /// /// Default-ctor to build an expression with given pattern member arguments /// - public RDFExpression(RDFPatternMember leftArgument, RDFPatternMember rightArgument) + protected RDFExpression(RDFPatternMember leftArgument, RDFPatternMember rightArgument) : this(leftArgument, rightArgument as RDFExpressionArgument) { } /// diff --git a/RDFSharp/Query/Mirella/RDFOperationEngine.cs b/RDFSharp/Query/Mirella/RDFOperationEngine.cs index 1ef1311e..ab6a0b71 100644 --- a/RDFSharp/Query/Mirella/RDFOperationEngine.cs +++ b/RDFSharp/Query/Mirella/RDFOperationEngine.cs @@ -87,18 +87,20 @@ internal RDFOperationResult EvaluateInsertDataOperation(RDFInsertDataOperation i internal RDFOperationResult EvaluateInsertWhereOperation(RDFInsertWhereOperation insertWhereOperation, RDFDataSource datasource) { RDFOperationResult operationResult = new RDFOperationResult(); + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); //Execute the CONSTRUCT query for materialization of the operation templates RDFConstructQueryResult constructResult = ExecuteConstructQueryFromOperation(insertWhereOperation, datasource); //Use materialized templates for execution of the operation List insertTemplates = new List(); - if (datasource.IsGraph()) + if (isGraph) { RDFGraph insertGraph = RDFGraph.FromDataTable(constructResult.ConstructResults); insertTemplates.AddRange(insertGraph.Select(insertTriple => new RDFPattern(insertTriple.Subject, insertTriple.Predicate, insertTriple.Object))); } - else if (datasource.IsStore()) + else if (isStore) { RDFMemoryStore insertStore = RDFMemoryStore.FromDataTable(constructResult.ConstructResults); insertTemplates.AddRange(insertStore.Select(insertQuadruple => new RDFPattern(insertQuadruple.Context, insertQuadruple.Subject, insertQuadruple.Predicate, insertQuadruple.Object))); @@ -126,18 +128,20 @@ internal RDFOperationResult EvaluateDeleteDataOperation(RDFDeleteDataOperation d internal RDFOperationResult EvaluateDeleteWhereOperation(RDFDeleteWhereOperation deleteWhereOperation, RDFDataSource datasource) { RDFOperationResult operationResult = new RDFOperationResult(); - + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); + //Execute the CONSTRUCT query for materialization of the operation templates RDFConstructQueryResult constructResult = ExecuteConstructQueryFromOperation(deleteWhereOperation, datasource); //Use materialized templates for execution of the operation List deleteTemplates = new List(); - if (datasource.IsGraph()) + if (isGraph) { RDFGraph deleteGraph = RDFGraph.FromDataTable(constructResult.ConstructResults); deleteTemplates.AddRange(deleteGraph.Select(deleteTriple => new RDFPattern(deleteTriple.Subject, deleteTriple.Predicate, deleteTriple.Object))); } - else if (datasource.IsStore()) + else if (isStore) { RDFMemoryStore deleteStore = RDFMemoryStore.FromDataTable(constructResult.ConstructResults); deleteTemplates.AddRange(deleteStore.Select(deleteQuadruple => new RDFPattern(deleteQuadruple.Context, deleteQuadruple.Subject, deleteQuadruple.Predicate, deleteQuadruple.Object))); @@ -153,7 +157,9 @@ internal RDFOperationResult EvaluateDeleteWhereOperation(RDFDeleteWhereOperation internal RDFOperationResult EvaluateDeleteInsertWhereOperation(RDFDeleteInsertWhereOperation deleteInsertWhereOperation, RDFDataSource datasource) { RDFOperationResult operationResult = new RDFOperationResult(); - + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); + //Execute the CONSTRUCT query for materialization of the operation templates RDFConstructQueryResult constructDeleteResult = new RDFOperationEngine().ExecuteConstructQueryFromOperation(deleteInsertWhereOperation, datasource, "DELETE"); RDFConstructQueryResult constructInsertResult = new RDFOperationEngine().ExecuteConstructQueryFromOperation(deleteInsertWhereOperation, datasource, "INSERT"); @@ -161,7 +167,7 @@ internal RDFOperationResult EvaluateDeleteInsertWhereOperation(RDFDeleteInsertWh //Use materialized templates for execution of the operation List deleteTemplates = new List(); List insertTemplates = new List(); - if (datasource.IsGraph()) + if (isGraph) { RDFGraph deleteGraph = RDFGraph.FromDataTable(constructDeleteResult.ConstructResults); deleteTemplates.AddRange(deleteGraph.Select(deleteTriple => new RDFPattern(deleteTriple.Subject, deleteTriple.Predicate, deleteTriple.Object))); @@ -169,7 +175,7 @@ internal RDFOperationResult EvaluateDeleteInsertWhereOperation(RDFDeleteInsertWh RDFGraph insertGraph = RDFGraph.FromDataTable(constructInsertResult.ConstructResults); insertTemplates.AddRange(insertGraph.Select(insertTriple => new RDFPattern(insertTriple.Subject, insertTriple.Predicate, insertTriple.Object))); } - else if (datasource.IsStore()) + else if (isStore) { RDFMemoryStore deleteStore = RDFMemoryStore.FromDataTable(constructDeleteResult.ConstructResults); deleteTemplates.AddRange(deleteStore.Select(deleteQuadruple => new RDFPattern(deleteQuadruple.Context, deleteQuadruple.Subject, deleteQuadruple.Predicate, deleteQuadruple.Object))); @@ -189,17 +195,19 @@ internal RDFOperationResult EvaluateDeleteInsertWhereOperation(RDFDeleteInsertWh internal RDFOperationResult EvaluateLoadOperation(RDFLoadOperation loadOperation, RDFDataSource datasource) { RDFOperationResult operationResult = new RDFOperationResult(); - + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); + try { List insertTemplates = new List(); //GRAPH => Dereference triples - if (datasource.IsGraph()) + if (isGraph) insertTemplates.AddRange(RDFGraph.FromUri(loadOperation.FromContext).Select(loadTriple => new RDFPattern(loadTriple.Subject, loadTriple.Predicate, loadTriple.Object))); //STORE => Dereference quadruples (respect the target context, if provided by the operation) - else if (datasource.IsStore()) + else if (isStore) { RDFContext targetContext = (loadOperation.ToContext != null ? new RDFContext(loadOperation.ToContext) : null); insertTemplates.AddRange(RDFMemoryStore.FromUri(loadOperation.FromContext).Select(loadQuadruple => new RDFPattern(targetContext ?? loadQuadruple.Context, loadQuadruple.Subject, loadQuadruple.Predicate, loadQuadruple.Object))); @@ -223,16 +231,18 @@ internal RDFOperationResult EvaluateLoadOperation(RDFLoadOperation loadOperation internal RDFOperationResult EvaluateClearOperation(RDFClearOperation clearOperation, RDFDataSource datasource) { RDFOperationResult operationResult = new RDFOperationResult(); - + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); + //Graphs => automatically execute as "CLEAR ALL" (since they are contextless by design) - if (datasource.IsGraph()) + if (isGraph) { operationResult.DeleteResults = ((RDFGraph)datasource).ToDataTable(); ((RDFGraph)datasource).ClearTriples(); } //Stores => transform into a targeted "DELETE WHERE" - else if (datasource.IsStore()) + else if (isStore) { try { @@ -365,6 +375,7 @@ internal bool EvaluateOperationOnSPARQLUpdateEndpoint(RDFOperation operation, RD private RDFConstructQueryResult ExecuteConstructQueryFromOperation(RDFOperation operation, RDFDataSource datasource, string deleteInsertCommand = null) { DataTable resultTable = new DataTable(); + RDFConstructQueryResult constructResult = new RDFConstructQueryResult(); List evaluableQueryMembers = operation.GetEvaluableQueryMembers().ToList(); if (evaluableQueryMembers.Count > 0) @@ -405,7 +416,9 @@ private RDFConstructQueryResult ExecuteConstructQueryFromOperation(RDFOperation private DataTable PopulateInsertOperationResults(List insertDataTemplates, RDFDataSource datasource) { DataTable resultTable = new DataTable("INSERT_RESULTS"); - if (datasource.IsStore()) + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); + if (isStore) resultTable.Columns.Add("?CONTEXT", typeof(string)); resultTable.Columns.Add("?SUBJECT", typeof(string)); resultTable.Columns.Add("?PREDICATE", typeof(string)); @@ -415,7 +428,7 @@ private DataTable PopulateInsertOperationResults(List insertDataTemp insertDataTemplates.ForEach(insertTemplate => { //GRAPH - if (datasource.IsGraph()) + if (isGraph) { RDFTriple insertTriple = insertTemplate.Object is RDFLiteral litObj ? new RDFTriple((RDFResource)insertTemplate.Subject, (RDFResource)insertTemplate.Predicate, litObj) @@ -435,7 +448,7 @@ private DataTable PopulateInsertOperationResults(List insertDataTemp } //STORE - else if (datasource.IsStore()) + else if (isStore) { RDFContext insertContext = insertTemplate.Context as RDFContext ?? new RDFContext(RDFNamespaceRegister.DefaultNamespace.NamespaceUri); RDFQuadruple insertQuadruple = insertTemplate.Object is RDFLiteral litObj @@ -466,7 +479,9 @@ private DataTable PopulateInsertOperationResults(List insertDataTemp private DataTable PopulateDeleteOperationResults(List deleteDataTemplates, RDFDataSource datasource) { DataTable resultTable = new DataTable("DELETE_RESULTS"); - if (datasource.IsStore()) + bool isGraph = datasource.IsGraph(); + bool isStore = datasource.IsStore(); + if (isStore) resultTable.Columns.Add("?CONTEXT", typeof(string)); resultTable.Columns.Add("?SUBJECT", typeof(string)); resultTable.Columns.Add("?PREDICATE", typeof(string)); @@ -476,7 +491,7 @@ private DataTable PopulateDeleteOperationResults(List deleteDataTemp deleteDataTemplates.ForEach(deleteTemplate => { //GRAPH - if (datasource.IsGraph()) + if (isGraph) { RDFTriple deleteTriple = deleteTemplate.Object is RDFLiteral litObj ? new RDFTriple((RDFResource)deleteTemplate.Subject, (RDFResource)deleteTemplate.Predicate, litObj) @@ -496,7 +511,7 @@ private DataTable PopulateDeleteOperationResults(List deleteDataTemp } //STORE - else if (datasource.IsStore()) + else if (isStore) { RDFContext deleteContext = deleteTemplate.Context as RDFContext ?? new RDFContext(RDFNamespaceRegister.DefaultNamespace.NamespaceUri); RDFQuadruple deleteQuadruple = deleteTemplate.Object is RDFLiteral litObj diff --git a/RDFSharp/Query/Mirella/RDFQueryEngine.cs b/RDFSharp/Query/Mirella/RDFQueryEngine.cs index f33d0299..1047480a 100644 --- a/RDFSharp/Query/Mirella/RDFQueryEngine.cs +++ b/RDFSharp/Query/Mirella/RDFQueryEngine.cs @@ -1194,7 +1194,7 @@ internal DataTable ApplyPropertyPath(RDFPropertyPath propertyPath, RDFDataSource //Remove property path variables List propPathCols = (from DataColumn dtCol in resultTable.Columns - where dtCol.ColumnName.StartsWith("?__PP") + where dtCol.ColumnName.StartsWith("?__PP", StringComparison.Ordinal) select dtCol.ColumnName).ToList(); propPathCols.ForEach(ppc => resultTable.Columns.Remove(ppc)); @@ -1213,7 +1213,7 @@ void AdjustVariableColumnNames(DataTable qrTable) int columnsCount = qrTable.Columns.Count; for (int i = 0; i < columnsCount; i++) { - if (!qrTable.Columns[i].ColumnName.StartsWith("?")) + if (!qrTable.Columns[i].ColumnName.StartsWith("?", StringComparison.Ordinal)) qrTable.Columns[i].ColumnName = string.Concat("?", qrTable.Columns[i].ColumnName); } } diff --git a/RDFSharp/Query/RDFQueryUtilities.cs b/RDFSharp/Query/RDFQueryUtilities.cs index 35b672ed..a89e46e4 100644 --- a/RDFSharp/Query/RDFQueryUtilities.cs +++ b/RDFSharp/Query/RDFQueryUtilities.cs @@ -48,7 +48,7 @@ public static RDFPatternMember ParseRDFPatternMember(string pMember) #region Plain Literal int lastIndexOfDatatype = pMember.LastIndexOf("^^", StringComparison.OrdinalIgnoreCase); if (!pMember.Contains("^^") - || pMember.EndsWith("^^") + || pMember.EndsWith("^^", StringComparison.Ordinal) || RDFModelUtilities.GetUriFromString(pMember.Substring(lastIndexOfDatatype + 2)) == null) { RDFPlainLiteral pLit; @@ -239,7 +239,7 @@ internal static (bool, string) AbbreviateRDFPatternMember(RDFPatternMember patte string nspString = nsp.ToString(); if (!pmemberString.Equals(nspString, StringComparison.OrdinalIgnoreCase)) { - if (pmemberString.StartsWith(nspString)) + if (pmemberString.StartsWith(nspString, StringComparison.Ordinal)) { pmemberString = pmemberString.Replace(nspString, string.Concat(nsp.NamespacePrefix, ":")) .TrimEnd('/'); diff --git a/RDFSharp/Store/RDFStoreUtilities.cs b/RDFSharp/Store/RDFStoreUtilities.cs index bb4f03c0..ae310b36 100644 --- a/RDFSharp/Store/RDFStoreUtilities.cs +++ b/RDFSharp/Store/RDFStoreUtilities.cs @@ -54,7 +54,7 @@ public static RDFQuadruple ParseQuadruple(IDataReader fetchedQuadruples) //PlainLiteral int lastIndexOfDatatype = literal.LastIndexOf("^^", StringComparison.OrdinalIgnoreCase); if (!literal.Contains("^^") - || literal.EndsWith("^^") + || literal.EndsWith("^^", StringComparison.Ordinal) || RDFModelUtilities.GetUriFromString(literal.Substring(lastIndexOfDatatype + 2)) == null) { RDFPlainLiteral pLit; diff --git a/RDFSharp/Store/Serializers/RDFNQuads.cs b/RDFSharp/Store/Serializers/RDFNQuads.cs index c2b17faa..10554679 100644 --- a/RDFSharp/Store/Serializers/RDFNQuads.cs +++ b/RDFSharp/Store/Serializers/RDFNQuads.cs @@ -214,7 +214,7 @@ internal static RDFMemoryStore Deserialize(Stream inputStream) nquad = nquad.Trim(' ', '\t', '\r', '\n'); //Skip empty or comment lines - if (nquad == string.Empty || nquad.StartsWith("#")) + if (nquad == string.Empty || nquad.StartsWith("#", StringComparison.Ordinal)) continue; //Tokenizes the sanitized quad @@ -235,9 +235,9 @@ internal static RDFMemoryStore Deserialize(Stream inputStream) #endregion #region object - if (tokens[2].StartsWith("<") || - tokens[2].StartsWith("bnode:") || - tokens[2].StartsWith("_:")) + if (tokens[2].StartsWith("<", StringComparison.Ordinal) || + tokens[2].StartsWith("bnode:", StringComparison.OrdinalIgnoreCase) || + tokens[2].StartsWith("_:", StringComparison.Ordinal)) { string obj = tokens[2].TrimStart('<') .TrimEnd('>') @@ -263,7 +263,7 @@ internal static RDFMemoryStore Deserialize(Stream inputStream) #region plain literal if (!tokens[2].Contains("^^") - || tokens[2].EndsWith("^^") + || tokens[2].EndsWith("^^", StringComparison.Ordinal) || tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") { if (RDFNTriples.regexLPL.Value.Match(tokens[2]).Success) @@ -329,13 +329,13 @@ internal static RDFMemoryStore Deserialize(Stream inputStream) private static string[] TokenizeNQuad(string nquad) { //A legal N-Quad starts with "_:" of blanks or "<" of non-blanks - if (!nquad.StartsWith("_:") && !nquad.StartsWith("<")) + if (!nquad.StartsWith("_:", StringComparison.Ordinal) && !nquad.StartsWith("<", StringComparison.Ordinal)) throw new Exception("found illegal N-Quad, must start with \"_:\" or with \"<\""); string[] tokens = new string[4]; //S->->-> quadruple - if (nquad.StartsWith("<")) + if (nquad.StartsWith("<", StringComparison.Ordinal)) { //S->P->O->C if (SPOC.Value.Match(nquad).Success) diff --git a/RDFSharp/Store/Serializers/RDFTriG.cs b/RDFSharp/Store/Serializers/RDFTriG.cs index 3deea767..a296d35a 100644 --- a/RDFSharp/Store/Serializers/RDFTriG.cs +++ b/RDFSharp/Store/Serializers/RDFTriG.cs @@ -185,14 +185,14 @@ internal static void ParseStatement(string trigData, RDFTriGContext trigContext) } while (sb.Length < 8); string directive = sb.ToString(); - if (directive.StartsWith("@") - || directive.Equals("prefix", StringComparison.InvariantCultureIgnoreCase) - || directive.Equals("base", StringComparison.InvariantCultureIgnoreCase)) + if (directive.StartsWith("@", StringComparison.Ordinal) + || directive.Equals("prefix", StringComparison.OrdinalIgnoreCase) + || directive.Equals("base", StringComparison.OrdinalIgnoreCase)) { ParseDirective(trigData, trigContext, trigContext.Graph, directive); SkipWhitespace(trigData, trigContext); // Turtle @base and @prefix directives MUST end with "." - if (directive.StartsWith("@")) + if (directive.StartsWith("@", StringComparison.Ordinal)) VerifyCharacterOrFail(trigContext, ReadCodePoint(trigData, trigContext), "."); // SPARQL BASE and PREFIX directives MUST NOT end with "." else