rdf

simongray 2023-09-20T13:00:33.999029Z

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]?

simongray 2023-09-20T13:01:09.647629Z

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

quoll 2023-09-20T13:11:57.186529Z

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 .
     }

quoll 2023-09-20T13:13:28.696799Z

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
simongray 2023-09-20T13:14:08.151829Z

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

quoll 2023-09-20T13:14:35.445469Z

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

quoll 2023-09-20T13:16:13.351659Z

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.

quoll 2023-09-20T13:17:12.909299Z

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

simongray 2023-09-20T13:16:56.661059Z

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

quoll 2023-09-20T13:17:21.601829Z

lol

quoll 2023-09-20T13:17:41.175819Z

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

simongray 2023-09-20T13:18:07.868309Z

yup

simongray 2023-09-20T13:18:15.122829Z

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

quoll 2023-09-20T13:18:49.202859Z

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

quoll 2023-09-20T13:19:50.240949Z

also, some DBs are better at these queries than others

quoll 2023-09-20T13:25:12.503479Z

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
simongray 2023-09-20T13:47:58.754819Z

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 .
      }

quoll 2023-09-20T13:25:29.991879Z

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

simongray 2023-09-20T13:25:41.286019Z

OH! Have a good time!

simongray 2023-09-20T13:25:52.791459Z

I’m jealous

wikipunk 2023-09-20T13:26:41.791859Z

Ask chatgpt to optimize it? :)

wikipunk 2023-09-20T13:36:43.609239Z

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

simongray 2023-09-20T13:48:37.065989Z

DanNet (Danish WordNet) schema

simongray 2023-09-20T13:48:44.086919Z

yes, it’s my/our own 🙂

simongray 2023-09-20T13:50:45.785119Z

the schemas in question: https://wordnet.dk/schema/dns and https://wordnet.dk/schema/dnc In use: https://wordnet.dk/dannet/data/synset-31493

wikipunk 2023-09-20T13:52:55.071599Z

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

simongray 2023-09-20T13:53:31.376119Z

np

wikipunk 2023-09-20T13:56:36.759639Z

The website has a very beautiful design as well.

simongray 2023-09-20T15:12:20.281099Z

Thank you!