query-6df9ebdaa74e176b04bac47d5ca60bd1
Dropdown URL matcherI'm working on improving the dropdown URL matcher. I'll put the improved draft here in case others want to help. Feel free to test against URLs that don't get matched (just place the one you care about in one of the VALUES brackets).
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?iri ?prop ?propLabel ?id_uncut ?id ?lcid ?regex ?item ?itemLabel ?test_url ?formatter_url WHERE {
VALUES ( ?test_url0 ) {
( "http://plantnet.rbgsyd.nsw.gov.au/cgi-bin/NSWfl.pl?page=nswfl&lvl=sp&name=Hibbertia~spanantha" )
( "https://www.lions.com.au/players/7" )
( "https://reiseauskunft.bahn.de/bin/bhftafel.exe/en?input=8400285&boardType=dep&time=actual&productsDefault=1111101&start=yes" )
( "https://www.inaturalist.org/taxa/47582-Ostreidae" )
( "https://twitter.com/BarackObama" )
}
BIND( IRI(?test_url0) AS ?iri ).
{?prop p:P1630/ps:P1630 ?formatter_url0 .}
UNION
{?prop p:P3303/ps:P3303 ?formatter_url0 .}
BIND (REPLACE(?test_url0,"^https://","") AS ?test_url1)
BIND (REPLACE(?test_url1,"^http://","") AS ?test_url2)
BIND (REPLACE(?test_url2,"^www.","") AS ?test_url)
BIND (REPLACE(?formatter_url0,"^https://","") AS ?formatter_url1)
BIND (REPLACE(?formatter_url1,"^http://","") AS ?formatter_url2)
BIND (REPLACE(?formatter_url2,"^www.","") AS ?formatter_url)
FILTER (CONTAINS( ?formatter_url, "$1" ) )
BIND (STRBEFORE( ?formatter_url, "$1" ) AS ?f_url_start )
BIND (STRAFTER( ?formatter_url, "$1" ) AS ?f_url_end )
FILTER(STRSTARTS( ?test_url, ?f_url_start ))
FILTER(STRENDS( ?test_url, ?f_url_end ))
BIND ( SUBSTR( ?test_url, 1+STRLEN(?f_url_start), STRLEN(?test_url)-STRLEN(?f_url_start)-STRLEN(?f_url_end) ) AS ?id_uncut)
?prop p:P1793/ps:P1793 ?regex .
BIND ( REPLACE (?id_uncut, CONCAT("(",?regex,").*"),"$1","i") AS ?id )
BIND ( LCASE(?id) AS ?lcid)
?prop wikibase:directClaim ?propRel .
{?item ?propRel ?id .}
UNION
{?item ?propRel ?lcid .}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v13("?f_url_end")
v13("?f_url_start")
v13("?formatter_url"):::projected
v8("?formatter_url0")
v11("?formatter_url1")
v12("?formatter_url2")
v15("?id"):::projected
v13("?id_uncut"):::projected
v6("?iri"):::projected
v18("?item"):::projected
v16("?lcid"):::projected
v7("?prop"):::projected
v17("?propRel")
v14("?regex"):::projected
v11("?test_url"):::projected
v5("?test_url0")
v9("?test_url1")
v10("?test_url2")
a1((" "))
a2((" "))
a3((" "))
c10(["bd:serviceParam"]):::iri
c12(["en"]):::literal
f0[["ends-with(?test_url,?f_url_end)"]]
f0 --> v11
f0 --> v13
f1[["starts-with(?test_url,?f_url_start)"]]
f1 --> v11
f1 --> v13
f2[["contains(?formatter_url,'$1')"]]
f2 --> v13
bind3[/VALUES ?test_url0/]
bind3-->v5
bind30(["http://plantnet.rbgsyd.nsw.gov.au/cgi-bin/NSWfl.pl?page=nswfl&lvl=sp&name=Hibbertia~spanantha"])
bind30 --> bind3
bind31(["https://www.lions.com.au/players/7"])
bind31 --> bind3
bind32(["https://reiseauskunft.bahn.de/bin/bhftafel.exe/en?input=8400285&boardType=dep&time=actual&productsDefault=1111101&start=yes"])
bind32 --> bind3
bind33(["https://www.inaturalist.org/taxa/47582-Ostreidae"])
bind33 --> bind3
bind34(["https://twitter.com/BarackObama"])
bind34 --> bind3
bind4[/"?test_url0"/]
v5 --o bind4
bind4 --as--o v6
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v7 --"p:P3303"--> a2
a2 --"p:statement/P3303"--> v8
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v7 --"p:P1630"--> a1
a1 --"p:statement/P1630"--> v8
end
union0r <== or ==> union0l
end
bind5[/"replace(?test_url0,'^https://','')"/]
v5 --o bind5
bind5 --as--o v9
bind6[/"replace(?test_url1,'^http://','')"/]
v9 --o bind6
bind6 --as--o v10
bind7[/"replace(?test_url2,'^www.','')"/]
v10 --o bind7
bind7 --as--o v11
bind8[/"replace(?formatter_url0,'^https://','')"/]
v8 --o bind8
bind8 --as--o v11
bind9[/"replace(?formatter_url1,'^http://','')"/]
v11 --o bind9
bind9 --as--o v12
bind10[/"replace(?formatter_url2,'^www.','')"/]
v12 --o bind10
bind10 --as--o v13
bind11[/"substring-before(?formatter_url,'$1')"/]
v13 --o bind11
bind11 --as--o v13
bind12[/"substring-after(?formatter_url,'$1')"/]
v13 --o bind12
bind12 --as--o v13
bind13[/"substring(?test_url,'1^^xsd:integer' + string-length(?f_url_start),string-length(?test_url) - string-length(?f_url_start) - string-length(?f_url_end))"/]
v11 --o bind13
v13 --o bind13
v13 --o bind13
bind13 --as--o v13
v7 --"p:P1793"--> a3
a3 --"p:statement/P1793"--> v14
bind14[/"replace(?id_uncut,concat('(',?regex,').*'),'$1','i')"/]
v13 --o bind14
v14 --o bind14
bind14 --as--o v15
bind15[/"lower-case(?id)"/]
v15 --o bind15
bind15 --as--o v16
v7 --"wikibase:directClaim"--> v17
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v18 -->v17--> v16
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v18 -->v17--> v15
end
union1r <== or ==> union1l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c10 --"wikibase:language"--> c12
end