Metaclass (Semantic Web) and punning

Hello everyone,

First of all, thanks for using a freedom respecting software license and contributing to software liberty!

I have not started to use TerminusDB yet, but got excited when I read what it’s about. My use-case is pretty specific though and I wasn’t able to find out if TerminusDB is suitable. I want to use databases to model things that don’t differentiate between schema and concrete data. The Wikipedia article sounds like that’s what I’d like, especially the feature “punning”.

Now to my question: Is TerminusDB built for handling metaclasses with punning like data? Or would that be a dirty hack resulting in all kinds of troubles, because TerminusDB was built for differentiation between schema and data?

A quick example:
I might want to model animals. A bird is an animal and has 2 wings. Now this sounds like schema, right? But at runtime I’d like to edit the schema and add eagle as a subclass of animal. It should then automatically also have the property 2 wings. One might think I’d just add eagle as an instance of the class bird, but I’d also like to use “eagle” as a class for example when I want to add “golden eagle”. Hence my desire to unify schema and data by punning and with metaclasses, if that’s the right terminology.

I did find this post about “Iterative Schema Development Possible?” Iterative Schema Development Possible? and read it.

Another question I have is where can I find documentation about WOQL semantic web metaclasses and punning? I don’t even know how the syntax would look :slight_smile:

Thanks in advance for reading and replies!


Hi GNUrocks

From the point of view of how schema works in TerminusDB, all of what you desire is covered by standard class inheritance within the schema. If you create a “Bird” class with two wings and an Eagle class as a subclass of Bird, the Eagle will inherit the wings from the Bird. The flip side of this way of working is often called ‘duck-typing’ (walks like a duck, sound like a duck => is a duck) - where you would create a Thing, declare it to have 2 wings, then have the system infer that it is a Bird because having 2 wings is your definition of what makes a thing a Bird.

You can also do this with TerminusDB - in addition to having a schema graph, there is also an inference graph - which operates broadly in the normal semantic web open world punning / duck typing way. That is to say that subclass relations can be inferred rather than pre-defined. There should be a lot of literature out there about how this works in OWL / semantic web but be warned it is significantly trickier than closed world schema reasoning. If I was you I’d try to see if I can make it work in a closed world schema way first and only then turn to inference - it’s hard to make duck-typing line up just the way you want it - you might infer, for example, that a large house with 2 wings is a bird.

You can also use TerminusDB in schema free mode in which case you can add class definitions and instance data to the same graph and do all of your reasoning through queries. Generally though in my experience, it is much easier to handle if you distinguish between schema and instance data because you do not want errors in instance data to propagate to your model. So, for example, if you inadvertently give a house 2 wings, you can get situations where the machine makes the inference that all houses are birds and then you’re in trouble! (this is what we call the ManBearPig problem :slight_smile:


Hi kevin, thank you for your detailed reply!

I’d like the system to think that everything that has 2 wings is a Bird. Since my minimal example didn’t include any useful data about Eagles it makes sense that that would happen. However I could still query for all descendants of Bird and get Eagle. Thus so far it sounds great!

Interesting, what advantages does using an inference graph have over pre-defining? I don’t mind the definitions.

Thanks for the tips, I do want to try it out! However I still don’t know about the WOQL syntax to write metaclasses. I only find information about Python metaclasses or Javascript even when including woql or owl in the search. Do you or does anyone else have a pointer for me?

GNUrocks - WOQL is a language that is written in native python or javascript or other client language and exchanged as a json-ld document. The class hierarchy encodes the meta-classes, you can have multiple inheritance without problem so you just get your more concrete classes to inherit from whichever of the meta-classes you want. You can also write the schema directly in OWL through the console or triples API if you want, but generally schema creation is easy in the console: add_class(“Eagle”).parent(“Bird”) encapsulates a lot of lines of turtle!

1 Like