【发布时间】:2017-07-20 14:24:01
【问题描述】:
我最近开始为一个项目试验合金,但遇到了一个不平等的问题。这是一个简化的例子。我有四个签名:
- 字
- 定义
- 文档:文档包含文本(单词序列)
- 字典:字典将一个单词序列映射到一个定义序列(为简单起见,假设一个单词应该只有一个定义)
这是一个最小的代码示例:
module dictionaries
open util/relation as relation
sig Word {}
sig Definition {}
sig Document {
text: seq Word
}
sig Dictionary {
entries: seq Word,
defseq: seq Definition,
define: Word->Definition,
}{
//dictionary maps word to def only for the word present in dictionary
dom[define] = elems [entries] function [define, elems [entries]]
//content of the list of defintions
defseq = entries.define
}
//assert all word in a dictionary have a definition
assert all_word_defined {
all w: Word | all dict: Dictionary | some def: Definition |
//w in dict.entries implies w->def in dict.define
}
check all_word_defined
所以我的问题是:
如何限制字典,以使字典中的每个单词都准确映射到一个定义?像上面的代码那样做对吗?
如何检查断言是否遵守此约束?显然代码
w in dict.entries implies w->def in dict.define不起作用,因为w in dict.entries和w->def in dict.define没有相同的元数,我收到错误消息“in can be used only between 2 expression of the same arity”...
【问题讨论】: