How to get only url results in sparql query?

Member

by rollin , in category: MySQL , 23 days ago

How to get only url results in sparql query?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 22 days ago

@rollin 

To get only URL results in a SPARQL query, you can use the FILTER function to filter out only results that are valid URLs. You can do this by checking if the result starts with "http://" or "https://" using regular expressions.


Here is an example SPARQL query that retrieves only URL results:

1
2
3
4
5
SELECT ?url
WHERE {
  ?s ?p ?o .
  FILTER(STRSTARTS(str(?o), "http://") || STRSTARTS(str(?o), "https://"))
}


In this query, we are selecting the variable ?url and filtering out results where the object (?o) starts with "http://" or "https://". This will only return results that are valid URLs.