lvaudor / glitter

an R package which writes SPARQL queries
https://lvaudor.github.io/glitter
44 stars 5 forks source link

pb with spq_filter, str_detect and | #171

Open lvaudor opened 1 year ago

lvaudor commented 1 year ago

Hey! I think there's something wrong with the results of filtering through "spq_filter(str_detect(x,"a|b"))

For instance:

spq_init() %>%      
    spq_add("?labo skos:prefLabel ?labo_label") %>%
    spq_filter(str_detect(labo_label,"Environnement Ville Soc|EVS")) %>%
    spq_perform("hal")

returns 0 lines while

spq_init() %>%      
    spq_add("?labo skos:prefLabel ?labo_label") %>%
    spq_filter(str_detect(labo_label,"Environnement Ville Soc")) %>%
    spq_perform("hal")

returns 3 lines

Right now I have this as a workaround:

spq_init() %>%      
    spq_add("?labo skos:prefLabel ?labo_label") %>%
    spq_filter(str_detect(labo_label,"EVS")|str_detect(labo_label,"Environnement Ville Soc")) %>%
    spq_perform("hal")
maelle commented 1 year ago

no | in https://en.wikibooks.org/wiki/SPARQL/Expressions_and_Functions#REGEX

maelle commented 1 year ago

but the example has FILTER REGEX (?itemLabel, "(ow|itz)$").

maelle commented 1 year ago
library("glitter")
spq_init() %>%      
    spq_add("?labo skos:prefLabel ?labo_label") %>%
    spq_filter(str_detect(labo_label,"(Environnement Ville Soc)|EVS")) %>%
    spq_perform("hal")
#> # A tibble: 20 × 2
#>    labo                                                labo_label               
#>    <chr>                                               <chr>                    
#>  1 https://data.archives-ouvertes.fr/revue/36364       REVSTAT - Statistical Jo…
#>  2 https://data.archives-ouvertes.fr/revue/115361      Issue 4 of SCS Transacti…
#>  3 https://data.archives-ouvertes.fr/structure/54063   GEVSM                    
#>  4 https://data.archives-ouvertes.fr/structure/145345  Environnement Ville Soci…
#>  5 https://data.archives-ouvertes.fr/structure/390864  UMR 5600 EVS             
#>  6 https://data.archives-ouvertes.fr/structure/493368  Environnement Ville Soci…
#>  7 https://data.archives-ouvertes.fr/structure/516259  UMR CNRS 5600 EVS-EMSE-G…
#>  8 https://data.archives-ouvertes.fr/structure/516301  Environnement Ville Soci…
#>  9 https://data.archives-ouvertes.fr/structure/520344  EVS-LAURE                
#> 10 https://data.archives-ouvertes.fr/structure/536301  Mines Saint-Etienne, Uni…
#> 11 https://data.archives-ouvertes.fr/structure/540878  Mines Saint-Etienne, Uni…
#> 12 https://data.archives-ouvertes.fr/structure/553708  UMR EVS/EA EIREST        
#> 13 https://data.archives-ouvertes.fr/structure/1029995 MSH UMR EVS LYON         
#> 14 https://data.archives-ouvertes.fr/structure/1030105 UNIVERSITE DE LYON II UM…
#> 15 https://data.archives-ouvertes.fr/structure/1030283 UMR 5600 EVS « ENVIRONNE…
#> 16 https://data.archives-ouvertes.fr/structure/1028810 EVS UMR 5600 LYON FRA    
#> 17 https://data.archives-ouvertes.fr/structure/1027291 ENTSORGUNGSVERBAD SAAR E…
#> 18 https://data.archives-ouvertes.fr/structure/1050501 University of Lyon, UJM-…
#> 19 https://data.archives-ouvertes.fr/structure/1053792 EVS-LAURe                
#> 20 https://data.archives-ouvertes.fr/structure/1098107 AECTT-EVS UMR 5600, Univ…

Created on 2023-09-07 with reprex v2.0.2

@lvaudor I think it's due to the space. Maybe an example to put in the docs?