[英]ArangoDB AQL FILTER graph for matching edge attributes
I have one words
collection and one word_relations
edge collection. 我有一个
words
集合和一个word_relations
边缘集合。 Words have relationships to other words, like synonym , hasPart , partOf , hasType , typeOf , etc. 这话得换句话说关系,如同义词 ,hasPart,partOf,hasType的typeof等
I am trying to figure out how to FILTER
an AQL graph query so that all paths are followed, but paths with more than one edge contain identical edge attribute of relation_type
. 我试图找出如何
FILTER
使所有路径都遵循一个AQL图形查询,但有一个以上的边缘路径包含相同边缘属性relation_type
。
Eg, I want this result (all returned paths, whether one or many, contain a single relation_type
attribute value): 例如,我想要这个结果(所有返回的路径,无论是一个还是多个,都包含一个
relation_type
属性值):
[
{
"edges": [
{
"_from": "library/parent",
"_to": "library/organism",
"relation_type": "typeOf"
}
],
"vertices": [
{
"_key": "parent",
"word": "parent"
},
{
"_key": "organism",
"word": "organism"
}
]
},
{
"edges": [
{
"_from": "library/parent",
"_to": "library/organism",
"relation_type": "typeOf"
},
{
"_from": "library/organism",
"_to": "library/scheme",
"relation_type": "typeOf"
}
],
"vertices": [
{
"_key": "parent",
"word": "parent"
},
{
"_key": "organism",
"word": "organism"
},
{
"_key": "scheme",
"word": "scheme"
}
]
},
{
"edges": [
{
"_from": "library/parent",
"_to": "library/stepparent",
"relation_type": "hasType"
},
{
"_from": "library/stepparent",
"_to": "library/stepmother",
"relation_type": "hasType"
}
],
"vertices": [
{
"_key": "parent",
"word": "parent"
},
{
"_key": "stepparent",
"word": "stepparent"
},
{
"_key": "stepmother",
"word": "stepmother"
}
]
}
]
NOT this result (the relation_type
attribute value changes within one path): 不是这个结果(
relation_type
属性值在一个路径中改变):
[
{
"edges": [
{
"_from": "library/parent",
"_to": "library/organism",
"relation_type": "typeOf"
}
],
"vertices": [
{
"_key": "parent",
"word": "parent"
},
{
"_key": "organism",
"word": "organism"
}
]
},
{
"edges": [
{
"_from": "library/parent",
"_to": "library/organism",
"relation_type": "typeOf"
},
{
"_from": "library/organism",
"_to": "library/zygote",
"relation_type": "hasCategories"
}
],
"vertices": [
{
"_key": "parent",
"word": "parent"
},
{
"_key": "organism",
"word": "organism"
},
{
"_key": "zygote",
"word": "zygote"
}
]
},
{
"edges": [
{
"_from": "library/parent",
"_to": "library/family_unit",
"relation_type": "memberOf"
},
{
"_from": "library/family_unit",
"_to": "library/sibling",
"relation_type": "hasMembers"
}
],
"vertices": [
{
"_key": "parent",
"word": "parent"
},
{
"_key": "family_unit",
"word": "family unit"
},
{
"_key": "sibling",
"word": "sibling"
}
]
},
]
There are many different kinds of relation_type
attribute values. 有许多不同类型的
relation_type
属性值。 I do not want to filter to a specific value, I don't care what the initial value is, I just want all follow-on attribute values to be the same as the first. 我不想过滤为特定值,我不在乎初始值是什么,我只希望所有后续属性值都与第一个相同。
The AQL to get the second (undesirable) result looks like: 获得第二个(不希望的)结果的AQL看起来像:
FOR v, e, p IN 1..2 OUTBOUND 'words/parent' word_relations
RETURN p
I have tried a few different filters, none of which work: 我尝试了几种不同的过滤器,但都没有用:
0 results: 0结果:
FOR v, e, p IN 1..2 OUTBOUND 'library/parent' library_relations
FILTER p.edges[*].relation_type ALL == p.edges[*].relation_type
RETURN p
Only returns 2 paths, b/c the FILTER
requires the second to exist: 仅返回2条路径,b / c
FILTER
要求第二条路径存在:
FOR v, e, p IN 1..2 OUTBOUND 'library/parent' library_relations
FILTER p.edges[0].relation_type == p.edges[1].relation_type
RETURN p
Thanks for your help! 谢谢你的帮助!
The following could be used for larger values of MAX as well: 以下内容也可以用于较大的MAX值:
FOR v, e, p IN 1..2 OUTBOUND 'library/parent' library_relations
FILTER p.edges[*].relation_type ALL == e.relation_type
RETURN p
Unfortunately, the AQL optimizer is tragically impaired at the moment (see https://github.com/arangodb/arangodb/issues/3979#issuecomment-350686061 ), so most likely you would have to work around its limitation, eg by prepending the above with: 不幸的是,目前AQL优化器已严重受损(请参阅https://github.com/arangodb/arangodb/issues/3979#issuecomment-350686061 ),因此您很可能必须解决其局限性,例如通过在以上:
FOR tmpV, tmpE IN 1..1 OUTBOUND 'library/parent’ library_relations
and then using tmpE.relation_type
instead of e.relation_type
. 然后使用
tmpE.relation_type
而不是e.relation_type
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.