Skip to content

Instantly share code, notes, and snippets.

@giacomociti
Created May 27, 2023 08:32
Show Gist options
  • Save giacomociti/8d11c0d8ad8917474d2858fcafd80d9c to your computer and use it in GitHub Desktop.
Save giacomociti/8d11c0d8ad8917474d2858fcafd80d9c to your computer and use it in GitHub Desktop.
variable renaming affects query result
#r "nuget: dotNetRdf.Core"
open VDS.RDF
open VDS.RDF.Parsing
let graph = new Graph()
StringParser.Parse(graph, "
@prefix : <http://example.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:age rdfs:domain :Person .
")
// correctly find the solution
graph.ExecuteQuery("
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE {
?property rdfs:domain ?class .
?sub rdfs:subClassOf* ?class .
}")
// renaming variable ?sub to ?c with get no solution
graph.ExecuteQuery("
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE {
?property rdfs:domain ?class .
?c rdfs:subClassOf* ?class .
}")
// the following script demonstrates that the issue is present
// for the letters from a to p (and for all uppercase letters)
open VDS.RDF.Query
let query = SparqlParameterizedString "
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE {
?property rdfs:domain ?class .
@sub rdfs:subClassOf* ?class .
}
"
let hasEmptyResult variableName =
query.SetParameter("sub", graph.CreateVariableNode(variableName))
printfn "%O" query
graph.ExecuteQuery(query) :?> SparqlResultSet |> Seq.isEmpty
[ 'a' .. 'z' ]
|> List.map string
|> List.filter hasEmptyResult
[ 'A' .. 'Z' ]
|> List.map string
|> List.filter hasEmptyResult
// experimenting with different values I think
// I found the problem is for variable names
// 'less than' "property"
[
"az" // no solution
"aaaaaaaaaaaaaa" // no solution
"pr" // no solution
"pro" // no solution
"propert" // no solution
"propertx" // no solution
"property" // found solution
"ps" // found solution
"pu" // found solution
"qz" // found solution
"zz" // found solution
] |> List.filter hasEmptyResult
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment