0

I query occupations in Wikidata OPTIONAL { ?item wdt:P106 ?occupation }. No problem in grouping those by label ?occupation rdfs:label ?occupationLabel FILTER((LANG(?occupationLabel)) = "en") .

So far, so good. But now I want to further group certain values together, such as: "lawyer", "jurist" ... (e.g. here all "law" related occupations). E.g. judge, jurist, lawyer -> law | physicist, mathematician, computer scientist -> MINT ....

Best solution I have found to do it with IF

bind ( IF(CONTAINS(?_occupationLabel, "law") || CONTAINS(?_occupationLabel, "jurist"),  "law!", 
             IF(CONTAINS(?_occupationLabel, "chemi") || CONTAINS(?_occupationLabel, "physicist"), "MINT!", ?_occupationLabel)
     ) as ?occupationLabelE)

Considered my use case I would end up with a deeply nested statement. Probably I could shorten it a bit by using RegExp, but with 10-15 categories not very elegant. Full query (shortening failed, had to add full link).

Anything cleaner/smarter?

Edit: Here I have found a trick way to avoid the nested statement. This IMHO is still some kind of hack, but much easier to write (as I can just add the various conditions).

   BIND (
     COALESCE(
       IF(CONTAINS(?occupationLabel, "law"), "law!", 1/0),
       IF(CONTAINS(?occupationLabel, "jurist"), "law!", 1/0),
       IF(CONTAINS(?occupationLabel, "chemi"), "MINT!", 1/0),
       ?occupationLabel
    ) AS ?occupationLabelE
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • 1
    How do you decide how to group occupations? A lawyer may be related to a prison guard as they both are linked to the law, but equally a lawyer is similar to a doctor, since both will have to have certain qualifications to exercise their job. So first you need to decide on your criteria. Then maybe you should spend some time looking at the pages of lawyer, jurist and others and see what they have in common, and also what they don't have in common. – Valerio Cocchi Nov 30 '20 at 22:40
  • In this very case I do it manually. I completely understand that this approach is not generic, so I use domain specific knowledge to do it manually. I have tried to use occupation categories (which do exist), but they do not serve my purpose. – Horst Walter Nov 30 '20 at 23:52

0 Answers0