【发布时间】:2014-06-24 19:51:46
【问题描述】:
我试图在我的 rexster 图形数据库中计算 TF_IDF。这是我得到的:
假设我有一个图,它由一组表示术语的顶点 T 和一组表示文档的顶点 D 组成。
在 T 中的术语和 D 中的文档之间存在边 E。每条边都有一个词频 tf。
例如。 (伪代码):
#x, y, and z are arbitrary IDs.
T(x) - E(y) -> D(z)
E(y).tf = 20
T(x).outE()
=> A set of edges.
T(x).outE().inV()
=> A list of Documents, a subset of D
当我尝试执行以下操作时,如何编写一个计算 TF_IDF 的 Germlin 脚本?
- 答:给定一个词t,计算每个与t直接相关的Document的TF_IDF。
- B:给定一组术语Ts,计算
Ts.outE().inV()中每个文档的TF_IDF与Ts中每个适用术语相关的总和。
到目前为止我所拥有的:
#I know this does not work
term = g.v(404)
term.outE().inV().as('docs').path().
groupBy{it.last()}{
it.findAll{it instanceof Edge}.
collect{it.getProperty('frequency')} #I would actually like to use augmented frequency (aka frequency_of_t_in_document / max_frequency_of_any_t_in_document)
}.collect{d,tf-> [d,
tf * ??log(??g.V.has('isDocument') / docs.count() ?? ) ??
]}
#I feel I am close, but I can't quite make this work.
【问题讨论】:
标签: graph-databases gremlin tf-idf