0

I am creating a knowledge graph in SPARQL. I am importing data from a csv file. Now I want to filter a data corresponding to a country. In the csv I don't want to make data in column to all lower or upper case.

Now I want to filter a data, such that I want a SPARQL query that can get me data which is case insensitive (to give data either when typed lower or upper case).

I used the FILTER statement as below: FILTER(?country, "Japan"). How to make Japan case insensitive

FILTER(?country, "Japan").

Expecting a filter or any other statement that makes it case insensitive

Rahul
  • 11
  • 2

1 Answers1

2

One way is to convert ?country to lower case and test against the lower case version as in:

  FILTER (lcase(?country) = "japan")

Likewise you could test it after converting to upper case

  FILTER (ucase(?country) = "JAPAN")
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • thank you, but I want a single command which could work both for lower or upper case. – Rahul Jan 23 '23 at 19:23
  • The FILTER I suggested will do that. It first converts the value of `?country` and then tests it. If you just want to make sure the value is some form of Japan (could be japan, Japan, JAPAN, JaPaN etc.) converting to a known form (like lower case) and then testing against that form will work. If I am misunderstanding what you really want to do can you please clarify the question. I was not suggesting you need both filters, you can just pick one of the FILTER I showed. – Kelvin Lawrence Jan 23 '23 at 21:07
  • `lcase` works fine. It is also possible to use `REGEX(?country, "^ja..n$", "i")` for more than case-insensitve string matching – AndyS Jan 24 '23 at 14:28