Skip to content

Commit

Permalink
Add regression tests for LIKE/ILIKE operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjonesbr committed Mar 22, 2024
1 parent deea608 commit 21dc068
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 1 deletion.
153 changes: 152 additions & 1 deletion expected/virtuoso-dbpedia.out
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,157 @@ LIMIT 10
Japón
(1 row)

CREATE FOREIGN TABLE public.regex_test1 (
txt text OPTIONS (variable '?o', nodetype 'literal')
)
SERVER dbpedia OPTIONS (
log_sparql 'true',
sparql '
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT * {<http://dbpedia.org/resource/%5Etxt2regex$> foaf:name ?o}
');
/*
ILIKE expression containing "^" and "$"
*/
SELECT txt FROM public.regex_test1
WHERE txt ~~* '%^___2reGeX$';
INFO: SPARQL query sent to 'https://dbpedia.org/sparql':

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?o
{<http://dbpedia.org/resource/%5Etxt2regex$> foaf:name ?o FILTER(REGEX(?o,".*\\^...2reGeX\\$$","i"))
}

txt
-------------
^txt2regex$
(1 row)

CREATE FOREIGN TABLE public.regex_test (
name text OPTIONS (variable '?name', nodetype 'literal'),
abstract text OPTIONS (variable '?abstract', expression 'STR(?abs)')
)
SERVER dbpedia OPTIONS (
log_sparql 'true',
sparql '
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT *
{?s a dbo:WrittenWork ;
dbo:genre dbr:Computer_magazine;
dbo:abstract ?abs ;
foaf:name ?name .
FILTER(LANG(?abs) = "en")
}');
/*
LIKE and ILIKE expressions containing "."
*/
SELECT name FROM regex_test
WHERE name LIKE '%P.P.%' AND abstract ILIKE '%wITh_MAC__.';
INFO: SPARQL query sent to 'https://dbpedia.org/sparql':

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?name (STR(?abs) AS ?abstract)
{?s a dbo:WrittenWork ;
dbo:genre dbr:Computer_magazine;
dbo:abstract ?abs ;
foaf:name ?name .
FILTER(LANG(?abs) = "en")
FILTER(REGEX(?name,".*P\\.P\\..*"))
FILTER(REGEX(STR(?abs),".*wITh.MAC..\\.$","i"))
}

name
-----------------
Call-A.P.P.L.E.
(1 row)

/*
LIKE and ILIKE expressions containing "(" and "["
*/
SELECT name FROM regex_test
WHERE abstract ~~ '%(Computer%' AND abstract ~~* '%[WwW%' ;
INFO: SPARQL query sent to 'https://dbpedia.org/sparql':

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?name (STR(?abs) AS ?abstract)
{?s a dbo:WrittenWork ;
dbo:genre dbr:Computer_magazine;
dbo:abstract ?abs ;
foaf:name ?name .
FILTER(LANG(?abs) = "en")
FILTER(REGEX(STR(?abs),".*\\(Computer.*"))
FILTER(REGEX(STR(?abs),".*\\[WwW.*","i"))
}

name
------------
Computerra
(1 row)

/*
LIKE and ILIKE expressions containing "-"
*/
SELECT name FROM regex_test
WHERE abstract ~~ '%VIC-_0%' AND abstract ~~* '%__-MoNtHlY%' AND name ~~ 'Your___';
INFO: SPARQL query sent to 'https://dbpedia.org/sparql':

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?name (STR(?abs) AS ?abstract)
{?s a dbo:WrittenWork ;
dbo:genre dbr:Computer_magazine;
dbo:abstract ?abs ;
foaf:name ?name .
FILTER(LANG(?abs) = "en")
FILTER(REGEX(STR(?abs),".*VIC\\-.0.*"))
FILTER(REGEX(STR(?abs),".*..\\-MoNtHlY.*","i"))
FILTER(REGEX(?name,"^Your..."))
}

name
---------
Your 64
(1 row)

/*
LIKE and ILIKE expressions containing single and double quotes
*/
SELECT name FROM regex_test
WHERE abstract ~~ '%"serious end"%' AND abstract ~~* E'%rEADer\'s%' ;
INFO: SPARQL query sent to 'https://dbpedia.org/sparql':

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>

SELECT ?name (STR(?abs) AS ?abstract)
{?s a dbo:WrittenWork ;
dbo:genre dbr:Computer_magazine;
dbo:abstract ?abs ;
foaf:name ?name .
FILTER(LANG(?abs) = "en")
FILTER(REGEX(STR(?abs),".*\"serious end\".*"))
FILTER(REGEX(STR(?abs),".*rEADer's.*","i"))
}

name
-----------
ST Review
(1 row)

DROP SERVER dbpedia CASCADE;
NOTICE: drop cascades to 18 other objects
NOTICE: drop cascades to 20 other objects
DETAIL: drop cascades to foreign table film
drop cascades to foreign table politicians
drop cascades to foreign table party_members
Expand All @@ -1846,3 +1995,5 @@ drop cascades to foreign table generic_rdf_table
drop cascades to foreign table generic_rdf_table2
drop cascades to foreign table generic_rdf_table3
drop cascades to foreign table generic_rdf_table4
drop cascades to foreign table regex_test1
drop cascades to foreign table regex_test
64 changes: 64 additions & 0 deletions sql/virtuoso-dbpedia.sql
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,68 @@ FROM generic_rdf_table4
WHERE uri = 'http://dbpedia.org/resource/Japan'
LIMIT 10;



CREATE FOREIGN TABLE public.regex_test1 (
txt text OPTIONS (variable '?o', nodetype 'literal')
)
SERVER dbpedia OPTIONS (
log_sparql 'true',
sparql '
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT * {<http://dbpedia.org/resource/%5Etxt2regex$> foaf:name ?o}
');


/*
ILIKE expression containing "^" and "$"
*/
SELECT txt FROM public.regex_test1
WHERE txt ~~* '%^___2reGeX$';



CREATE FOREIGN TABLE public.regex_test (
name text OPTIONS (variable '?name', nodetype 'literal'),
abstract text OPTIONS (variable '?abstract', expression 'STR(?abs)')
)
SERVER dbpedia OPTIONS (
log_sparql 'true',
sparql '
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT *
{?s a dbo:WrittenWork ;
dbo:genre dbr:Computer_magazine;
dbo:abstract ?abs ;
foaf:name ?name .
FILTER(LANG(?abs) = "en")
}');

/*
LIKE and ILIKE expressions containing "."
*/
SELECT name FROM regex_test
WHERE name LIKE '%P.P.%' AND abstract ILIKE '%wITh_MAC__.';

/*
LIKE and ILIKE expressions containing "(" and "["
*/
SELECT name FROM regex_test
WHERE abstract ~~ '%(Computer%' AND abstract ~~* '%[WwW%' ;

/*
LIKE and ILIKE expressions containing "-"
*/
SELECT name FROM regex_test
WHERE abstract ~~ '%VIC-_0%' AND abstract ~~* '%__-MoNtHlY%' AND name ~~ 'Your___';

/*
LIKE and ILIKE expressions containing single and double quotes
*/
SELECT name FROM regex_test
WHERE abstract ~~ '%"serious end"%' AND abstract ~~* E'%rEADer\'s%' ;


DROP SERVER dbpedia CASCADE;

0 comments on commit 21dc068

Please sign in to comment.