首页 > 解决方案 > 如何在 Grakn 中使用 Python 客户端计算连接组件

问题描述

我想使用 Python 客户端获取集群(或连接的组件)。我可以用 graql 做到这一点:

compute cluster in [company, c2c], using connected-component, where contains=V86179944;

我也可以使用 Python 运行查询:

query = "compute cluster in [company, c2c], using connected-component, where contains=V86179944;"
with GraknClient(uri="localhost:48555") as client:
    with client.session(keyspace=keyspace) as session:
        with session.transaction().read() as transaction:
            answer_iterator = transaction.query(query)
            # What to do here??          

但是,我不知道如何访问结果。根据python 客户端文档,有两种获取结果的方法:

当我迭代时,我不能使用.map()我得到AttributeError: 'ConceptSet' object has no attribute 'map'

当我尝试collect_concepts时,我得到GraknError: Only use .collect_concepts on ConceptMaps returned by query()

标签: pythonvaticle-typedbvaticle-typeql

解决方案


map()collect_concepts(将在客户端 Python 的下一个版本中删除)是ConceptMapanswer 类型的方法。compute cluster作为查询的结果,您得到的是ConceptSet答案类型。ConceptSet具有在set()集群计算后返回概念 id 集的方法。

在这里,您将找到查询类型及其相应的答案类型,在这里您将找到set()有关ConceptSet.


推荐阅读