COUNT[Class/class]
The result will look like
119 in COUNT[Class/class] end
SUM_Attribute[Bill/objname,Employee!salary/attrcat]
Unfortunately, the result is returned everytime as a real number, even if the input numbers were integers.
2.5001000000000e+04 in SUM_Attribute[Bill/objname,Employee!salary/attrcat] end
You can also use functions also in query class to assign a value to a ``computed_attribute'':
QueryClass EmployeesWithSumSalaries isA Employee with
computed_attribute
sumsalary : Real
constraint
c: $ (~sumsalary in
SUM_Attribute[this/objname,Employee!salary/attrcat]) $
endQueryClass PercentageOfQueryClasses isA Real with
constraint
c: $ exists i1,i2/Integer r/Real
(i1 in COUNT[QueryClass/class]) and (i2 in COUNT[Class/class]) and
(r in DIV[i1/r1,i2/r2]) and (this in MULT[100/r1,r/r2]) $
end
The query can be simplified with the use of complex query calls (see section 2.3.3):
QueryClass PercentageOfQueryClasses isA Real with
constraint
c: $ (this in MULT[100/r1,
DIV[COUNT[QueryClass/class]/r1,
COUNT[Class/class]/r2]/r2]) $
end
Functions that yield a single numerical value can directly be incorporated in comparison literals. For example, the following query will return all individual objects that have more than two attributes:
ObjectWithMoreThanTwoAttributes in QueryClass isA Individual with
attribute,constraint
c1 : $ (COUNT_Attribute[~this/objname,Proposition!attribute/attrcat] > 2) $
end
The functional expression used in the comparison can be nested. See section 2.3.3 for details. You can also re-use the above query to form further functional expressions, e.g. for counting the number of objects that have more than two attribute:
COUNT[ObjectWithMoreThanTwoAttributes/class]