等价关系代数和图灵语言
我正在启动一个项目,我想尝试用类似 java 的编程语言来识别关系代数。
例如,给定两个关系: 美国演员(姓名) EuropianActor(Name)
RA 中的以下表达式:
AmericanActor U EuropianActor
应等效于以下程序:
void RAMethod(Set<Name> AmericanActors, Set<Name> EuropianActors) {
Set<Name> xs = new Set<Name>();
for(R r : rs) {
xs.Add(r);
}
for(S s : ss) {
xs.Add(s);
}
return xs;
}
我正在寻找有关此主题的任何出版物。
I'm starting a project where I want to try to recognize relational algebra's in java-like programming language.
For example, given two relations:
AmericanActor(Name)
EuropianActor(Name)
The following expression in RA:
AmericanActor U EuropianActor
should be equivalent to the following program:
void RAMethod(Set<Name> AmericanActors, Set<Name> EuropianActors) {
Set<Name> xs = new Set<Name>();
for(R r : rs) {
xs.Add(r);
}
for(S s : ss) {
xs.Add(s);
}
return xs;
}
I'm looking for any publications about this topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人不知道有任何软件库可以做到这一点。
但是,如果我要做这样的事情,我会编写一个解析器,将关系代数表达式拆分为标记。然后调用您编写的“RAMethod”,以便根据令牌列表中的关系代数运算符在幕后执行关系代数。
I don't know personally any software libraries that do this.
But if I was going to do something like this, I would write a parser that splits up your relational algebra expressions into tokens. Then call your "RAMethod" that you wrote in order to do the relational algebra behind the scenes based on which relational algebra operators are in the token list.
你可以这样实现关系代数:
然后直接在代码中编写关系代数:
基本上“投影”对应“地图”,“选择”对应“过滤器”。
显然并不是每个代码都对应一个关系代数表达式。如果您限制语言没有
while
、异常等,您可以将条件转换为选择,将多个嵌套循环转换为叉积,添加到联合等。形式化这是另一个故事。您可能更喜欢使用更具声明性的语言,例如 Haskell 或 ML;这是使用列表的实现:
You can implement relational algebra like this:
and then directly write relational algebra in code:
basically "projection" corresponds to "map" and "selection" to "filter".
Obviously not every code corresponds to a relational algebra expression. If you constrain to language without
while
, exceptions etc. you could translate conditionals to selection, multiple nested loops to cross product, adding to union etc. Formalising that is another story.You might be more comfortable with a more declarative language, like Haskell or ML; here's an implementation using lists: