在Logicblox中设置

时间:2016-10-03 21:05:40

标签: logicblox

是否可以在Logicblox中建模集。具体来说,我希望有一个set of Integers,比如{1,4,9},并想检查该集是否为空集,以及某个元素是否属于该集。

1 个答案:

答案 0 :(得分:1)

谓词实际上是自然的模型集,所以如果你想建模一个集合你可以为它创建一个谓词,如下例所示:

create --unique
addblock <doc>
  my_set(x) -> int(x).
  my_set_not_empty() <- my_set(_).
  my_set_empty() <- !my_set_not_empty().
</doc>
echo 'my_set'
print my_set
echo 'my_set_empty'
print my_set_empty
echo 'my_set_not_empty'
print my_set_not_empty
echo 'adding an element'
exec '+my_set(1).'
echo 'my_set'
print my_set
echo 'my_set_empty'
print my_set_empty
echo 'my_set_not_empty'
print my_set_not_empty
close --destroy

如果您想将集合建模为实体,则只需一个额外的密钥:

create --unique
addblock <doc>
  integer_set(set),integer_set:name(set:name) -> string(name).
  contains(set,integer) -> integer_set(set),int(integer).
  not_empty(set) <- contains(set,_).
  empty(set) <- !not_empty(set), integer_set(set).
</doc>
exec <doc>
  +integer_set(my_set),+integer_set:name(my_set:"my_set").
</doc>
echo "empty"
print empty
echo "not empty"
print not_empty
echo "adding elements and creating another set"
exec <doc>
  +integer_set(my_set),+integer_set:name(my_set:"other_set").
  +contains(my_set,1) <- integer_set:name(my_set:"my_set").
  +contains(my_set,4) <- integer_set:name(my_set:"my_set").
  +contains(my_set,9) <- integer_set:name(my_set:"my_set").
</doc>
echo "contains"
print contains
echo "empty"
print empty
echo "not empty"
print not_empty

close --destroy