Fork me on GitHub
#rdf
<
2023-09-20
>
simongray13:09:33

TIL rdfs:member for doing searches in e.g. Bags

SELECT ?al ?ql ?member
     WHERE {
       ?q dns:orthogonalHypernym ?a .
       ?q <> "zoo"@da .
       ?q dns:ontologicalType ?qo .
       ?qo rdfs:member dnc:Animal .
       ?qo rdfs:member dnc:Object .
       FILTER NOT EXISTS {
         ?qo rdfs:member dnc:Comestible .
       }
       ?a rdfs:label ?al .
       ?q rdfs:label ?ql .
     }
However, I wonder if there is a way to define a query where I can just exclusively return matches containing exactly [dnc:Animal dnc:Object]?

simongray13:09:09

i.e. I don’t want to define a huge list of FILTER NOT EXISTS triples.

quoll13:09:57

SELECT ?al ?ql ?member
     WHERE {
       ?q dns:orthogonalHypernym ?a .
       ?q <> "zoo"@da .
       ?q dns:ontologicalType ?qo .
       ?qo rdfs:member dnc:Animal .
       ?qo rdfs:member dnc:Object .
       MINUS {
         ?qo rdfs:member ?member . FILTER (?member != dnc:Animal && ?member != dnc:Object)
       }
       ?a rdfs:label ?al .
       ?q rdfs:label ?ql .
     }

quoll13:09:28

i.e. Select all the ones with dnc:Animal and dnc:Object, and then remove any which have members that are not dnc:Animal or dnc:Object

🙏 1
simongray13:09:08

Thank you @quoll! I’m so fortunate to have someone like you here.

quoll13:09:35

Incidentally, I have asked GPT-4 to answer tougher questions than this, and it’s distressingly good at writing SPARQL

quoll13:09:13

I had one SPARQL query that was really tough to figure out. I was proud of it, and I was convinced ChatGPT wouldn’t get it… only for it get it on the first try.

quoll13:09:12

It was also based on MINUS with embedded filters/minuses, which is why I thought of this

simongray13:09:56

Right, I should probably reach for ChatGPT more often. Incidentally, these queries are actually for extracting data to test ChatGPT with 😛

quoll13:09:41

It seems that graphs and LLMs are what everyone in the RDF space is interested in at the moment

simongray13:09:15

Hm… it appears that the added MINUS clause makes the query take ages to finish, though… investigating

quoll13:09:49

Sigh… yes, that can happen 😕 I knew this was possible, but didn’t know how big your dataset was

quoll13:09:50

also, some DBs are better at these queries than others

quoll13:09:12

Can also try:

SELECT ?al ?ql ?member
     WHERE {
       ?q dns:orthogonalHypernym ?a .
       ?q <> "zoo"@da .
       ?q dns:ontologicalType ?qo .
       ?qo rdfs:member dnc:Animal .
       ?qo rdfs:member dnc:Object .
       MINUS { ?qo rdfs:member ?member . FILTER (?member NOT IN(dnc:Animal, dnc:Object)) }
       ?a rdfs:label ?al .
       ?q rdfs:label ?ql .
     }
or:
SELECT ?al ?ql ?member
     WHERE {
       ?q dns:orthogonalHypernym ?a .
       ?q <> "zoo"@da .
       ?q dns:ontologicalType ?qo .
       ?qo rdfs:member dnc:Animal .
       ?qo rdfs:member dnc:Object .
       FILTER (NOT EXISTS { ?qo rdfs:member ?member . FILTER (?member NOT IN(dnc:Animal, dnc:Object)) })
       ?a rdfs:label ?al .
       ?q rdfs:label ?ql .
     }
But they’ll probably perform similarly. It totally depends on implementation

🙏 1
simongray13:09:58

Went with this

SELECT ?al ?ql
      WHERE {
        ?q dns:orthogonalHypernym ?a .
        ?q dns:ontologicalType ?qo .
        ?qo rdfs:member dnc:Animal .
        ?qo rdfs:member dnc:Object .
        FILTER NOT EXISTS {
          ?qo rdfs:member ?member .
          FILTER (?member NOT IN(dnc:Animal, dnc:Object))
        }
        ?a rdfs:label ?al .
        ?q rdfs:label ?ql .
      }

quoll13:09:29

Sorry… getting offline now. I’m going to the airport for Strangeloop

simongray13:09:41

OH! Have a good time!

simongray13:09:52

I’m jealous

wikipunk13:09:41

Ask chatgpt to optimize it? :)

wikipunk13:09:43

What’s the vocabulary for dns / dnc in your examples? Your own ontology? Looks interesting :)

simongray13:09:37

DanNet (Danish WordNet) schema

simongray13:09:44

yes, it’s my/our own 🙂

wikipunk13:09:55

Very cool. It is so cool how internationalized RDF is. Thank you for sharing :)

wikipunk13:09:36

The website has a very beautiful design as well.