Discussion Forum

Relation with n-inputs

New here, so forgive my ignorance and if I’ve missed the answer in the docs, just hit me with the link!

I’m having difficulty figuring out how to specify a relationship with 1+ of a certain type. The simplest example I have is defining data aggregation. We have anywhere between 1-4 data values which we aggregate into a single value, I’d like to be able to model the relationship between the pre- and post- averaged data. So crudely, something like this:

average sub relation,
owns average_method,
relates averaged_data,
relates unaveraged_data;

datum sub entity,
owns value,
plays average:averaged_data,
plays average:unaveraged_data;

Where the actual data may anywhere between 1 and 4 un-averaged values and we may be averaging by different methods (Arithmetic, geomean, handling qualifiers, etc).

Hi @Fischer70 and welcome!

There’s no need to specify the number of instances that you’ll for any given role in a relation. This is because by specifying any role for a relation, instances of the relation can have from 0 to infinite things playing that role.

You’ll see what I mean for your case if we do an example insertion using the schema you’ve given:

insert
$d1 isa datum, has value 3.0;
$d2 isa datum, has value 5.0;
$d3 isa datum, has value 7.0;
$d-mean isa datum, has value 7.0;
$av(unaveraged_data: $d1, unaveraged_data: $d2, unaveraged_data: $d3, averaged_data: $d-mean) isa average;

So you can see we use the unaveraged_data role type multiple times for the same relation instance.