Imran Azad
Imran Azad

Reputation: 1048

SPARQL query split by case

Is it possible to use a built-in SPARQL function to split a string by case?

For example take the following test AllDrugs

Is possible to use a function that would return "All Drugs"?

Upvotes: 2

Views: 655

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85853

Sure, you just need to replace the pattern ([a-z])([A-Z]) with $1 $2 (where $1 is the lower case letter and $2 is the upper case letter). Here's an example:

select * where {
  values ?string { "AllDrugs" "FourScoreAndSevenYearsAgo" }

  bind(replace(?string, "([a-z])([A-Z])", "$1 $2") as ?splitString)
}
------------------------------------------------------------------
| string                      | splitString                      |
==================================================================
| "AllDrugs"                  | "All Drugs"                      |
| "FourScoreAndSevenYearsAgo" | "Four Score And Seven Years Ago" |
------------------------------------------------------------------

Upvotes: 6

Related Questions