-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#347 Implement LANG expression for extracting language of plain liter…
…als (#348)
- Loading branch information
Showing
24 changed files
with
407 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
255 changes: 255 additions & 0 deletions
255
RDFSharp.Test/Query/Mirella/Algebra/Expressions/RDFLangExpressionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
/* | ||
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 Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Data; | ||
using RDFSharp.Model; | ||
using RDFSharp.Query; | ||
|
||
namespace RDFSharp.Test.Query | ||
{ | ||
[TestClass] | ||
public class RDFLangExpressionTest | ||
{ | ||
#region Tests | ||
[TestMethod] | ||
public void ShouldCreateLangExpressionWithExpression() | ||
{ | ||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFAddExpression(new RDFVariable("?V1"), new RDFVariable("?V2"))); | ||
|
||
Assert.IsNotNull(expression); | ||
Assert.IsNotNull(expression.LeftArgument); | ||
Assert.IsNull(expression.RightArgument); | ||
Assert.IsTrue(expression.ToString().Equals("(LANG((?V1 + ?V2)))")); | ||
Assert.IsTrue(expression.ToString([]).Equals("(LANG((?V1 + ?V2)))")); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldCreateLangExpressionWithVariable() | ||
{ | ||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariable("?V1")); | ||
|
||
Assert.IsNotNull(expression); | ||
Assert.IsNotNull(expression.LeftArgument); | ||
Assert.IsNull(expression.RightArgument); | ||
Assert.IsTrue(expression.ToString().Equals("(LANG(?V1))")); | ||
Assert.IsTrue(expression.ToString([]).Equals("(LANG(?V1))")); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldThrowExceptionOnCreatingLangExpressionWithExpressionBecauseNullLeftArgument() | ||
=> Assert.ThrowsException<RDFQueryException>(() => new RDFLangExpression(null as RDFExpression)); | ||
|
||
[TestMethod] | ||
public void ShouldThrowExceptionOnCreatingLangExpressionWithVariableBecauseNullLeftArgument() | ||
=> Assert.ThrowsException<RDFQueryException>(() => new RDFLangExpression(null as RDFVariable)); | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithExpressionAndCalculateResultOnNull() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = null; | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariableExpression(new RDFVariable("?A"))); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNotNull(expressionResult); | ||
Assert.IsTrue(expressionResult.Equals(RDFPlainLiteral.Empty)); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithExpressionAndCalculateResultOnResource() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFResource("ex:subj").ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariableExpression(new RDFVariable("?A"))); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNull(expressionResult); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithExpressionAndCalculateResultOnPlainLiteral() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFPlainLiteral("hello").ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariableExpression(new RDFVariable("?A"))); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNotNull(expressionResult); | ||
Assert.IsTrue(expressionResult.Equals(RDFPlainLiteral.Empty)); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithExpressionAndCalculateResultOnPlainLiteralWithLanguage() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFPlainLiteral("hello","en-US").ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariableExpression(new RDFVariable("?A"))); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNotNull(expressionResult); | ||
Assert.IsTrue(expressionResult.Equals(new RDFPlainLiteral("EN-US"))); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithExpressionAndCalculateResultOnTypedLiteral() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFTypedLiteral("hello", RDFModelEnums.RDFDatatypes.RDFS_LITERAL).ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariableExpression(new RDFVariable("?A"))); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNull(expressionResult); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithExpressionAndNotCalculateResultBecauseNotBoundVariable() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFTypedLiteral("45", RDFModelEnums.RDFDatatypes.XSD_NORMALIZEDSTRING).ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariableExpression(new RDFVariable("?Q"))); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNull(expressionResult); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithVariableAndCalculateResultOnResource() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFResource("ex:subj").ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariable("?A")); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNull(expressionResult); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithVariableAndCalculateResultOnPlainLiteral() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFPlainLiteral("hello").ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariable("?A")); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNotNull(expressionResult); | ||
Assert.IsTrue(expressionResult.Equals(RDFPlainLiteral.Empty)); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithVariableAndCalculateResultOnPlainLiteralWithLanguage() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFPlainLiteral("hello", "en-US").ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariable("?A")); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNotNull(expressionResult); | ||
Assert.IsTrue(expressionResult.Equals(new RDFPlainLiteral("EN-US"))); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithVariableAndCalculateResultOnTypedLiteral() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFTypedLiteral("hello", RDFModelEnums.RDFDatatypes.RDFS_LITERAL).ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariable("?A")); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNull(expressionResult); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldApplyExpressionWithVariableAndNotCalculateResultBecauseNotBoundVariable() | ||
{ | ||
DataTable table = new DataTable(); | ||
table.Columns.Add("?A", typeof(string)); | ||
DataRow row = table.NewRow(); | ||
row["?A"] = new RDFTypedLiteral("45", RDFModelEnums.RDFDatatypes.XSD_NORMALIZEDSTRING).ToString(); | ||
table.Rows.Add(row); | ||
table.AcceptChanges(); | ||
|
||
RDFLangExpression expression = new RDFLangExpression( | ||
new RDFVariable("?Q")); | ||
RDFPatternMember expressionResult = expression.ApplyExpression(table.Rows[0]); | ||
|
||
Assert.IsNull(expressionResult); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.