在处理sack时您也可以使用布尔运算符or或者and.下面的例子只是测试了使用true或false的最基本的功能。在第一个例子中,在sack中返回的结果是false,因为我们用了一个and运算符,常量false与sack初始的true进行与运算得到的结果就是false.
You can also use the boolean operators or and and when working with a sack. The examples below
just test the basic functionality using constants of true and false. In the first example the result
returned in the sack is false as we used an and operator to and together the sack’s initial value of
true and a constant value of false.
这次我们用or运算符代替了and 运算符,结果如我们所料,就是true.
This time we replace the and operator with an or and the result, as we would expect, is true.
我使用常量来证明我们可以进行布尔运算是有趣的,它或许没那么有用。但是这个功能会更加的有趣,举个例子,如果值来自于顶点的属性。让我们创建一些项点,它们每个都有一个布尔属性。
While proving we can do boolean operations using constants is interesting it is perhaps not that
useful. Where this functionality becomes more interesting is if the values being used come from,
for example, a vertex property. So let’s create a couple of vertices that each have a boolean
property.
我们现在可以使用布尔运算符来写查询了,在我们的sack中生成结果。下面这个例子有一点随心所欲,但是它说明了如何使用布尔运算符。我们从ID是3的顶点开始,用常量true初始化sack,使用and运算符和有happy标签的顶点的happy属性进行与运算。我们得到了路径的结果。它包含了起始顶点,与运算的结果。与运算的结果是true,因为happy顶点的happy属性的值是true.
We can now write a query that uses a boolean operator to generate a result in our sack. The
example below is a bit arbitrary but it shows how the boolean operators can be used. We start at
the vertex with an ID of 3, initialize a sack with the constant true and the use the and operator
against the happy property of the vertex with a label of happy. We return the results in a path,
which will contain the starting vertex and the results of the and operation. The result of the and is
true as the happy vertex has a value of true for its happy property.
如果我们继续查询,但是这次用一个sad顶点,我们期望从与运算中得到的结果是false.
If we repeat the query but this time use the sad vertex, we get the expected result of false from the
and operation.
浙公网安备 33010602011771号