【问题标题】:How to return all properties of a node with their name and their value using Cypher如何使用 Cypher 返回节点的所有属性及其名称和值
【发布时间】:2014-10-09 08:49:22
【问题描述】:

我在这里看到:How can I return all properties for a node using Cypher? 有人已经问过这个问题,但 1 年前。

所以我现在需要问一下:今天有没有办法使用密码返回节点的所有属性?我需要为以前的开发人员将其创建为每种语言 1 个节点的翻译系统执行此操作,其中包含所有属性,其名称为所需语言。我需要为 Java 应用程序获取它。

例子:

node FR contains: "Salut_01" : "Bonjour"
node UK contains: "Salut_01" : "Hello"

等等……

【问题讨论】:

    标签: java neo4j cypher


    【解决方案1】:

    如果您通过 http 端点直接从 cypher 返回节点,它将返回一个包含所有属性名称和属性值的映射。

     MATCH (n) return n
    

    在 Java 中,您只需遍历 n.getPropertyKeys()

    对于您的正则表达式问题,您应该将您的问题分成两部分。

    【讨论】:

    • 您的回答似乎不错,但我不知道如何使用 http 端点,我对您在这个问题上的回答也有同样的问题:stackoverflow.com/questions/26175969/… 我在 java 中找到了解决方案,将当我完成所有代码时发布它
    【解决方案2】:

    这就是我最终做到的:

    private IndexedContainer getTradParameters(int id){
            IndexedContainer container = new IndexedContainer();
            container.addContainerProperty("name", String.class, null);
            try {
                Document doc = Jsoup.connect("http://10.0.0.1:7474/db/data/node/"+id+"/").get();
                Elements properties = doc.select("th");
                for(int index = 0; index < properties.size(); index++){
                    String parameter = properties.get(index).text();
                    Item item = container.addItem(index);
                    item.getItemProperty("name").setValue(parameter);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }   
            return container;
        }
    

    id参数由this返回的地方:

    match (t:Translation) return id(t)
    

    我使用请求的每个迭代器调用 getTradParameters(),然后我有一个容器,其中包含我节点的所有参数的名称。

    最后一部分是调用这个函数:

    private String getTradRequest(String pays){
            String request = "match (n:Translation{trad_country:\""+pays+"\"}) return id(n) as id";
            QueryResult <Map<String,Object>>result = engine.query(request, Collections.EMPTY_MAP);
            Iterator<Map<String, Object>> iterator=result.iterator();
            Map<String,Object> row = iterator.next();
            int id = Integer.valueOf(row.get("id").toString());
            try {
                Document doc = Jsoup.connect("http://10.0.0.1:7474/db/data/node/"+id+"/").get();
                Elements properties = doc.select("th");
                for(int index = 0; index < properties.size(); index++){
                    String parameter = properties.get(index).text();
                    request = request + ",n."+parameter;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return request;
        }
    

    创建我的大型 Cypher 请求以获取节点上我需要的所有属性,然后我只需要获取答案并将它们存储在容器中,然后使用 vaadin 将其显示在表中。

    【讨论】:

      猜你喜欢
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-11
      相关资源
      最近更新 更多