How to return all properties of a node with their name and their value using Cypher

北慕城南 提交于 2019-12-13 18:19:26

问题


I saw here : How can I return all properties for a node using Cypher? that somebody already asked this question, but 1 year ago.

So i need to ask it now : is there a way, today, to return all properties of a node using cypher? i need to do it for a translation system where previous developpers have created it as 1 node per language, with contains all of the properties with their name in the desired language. I need to get it for a Java application.

Example:

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

etc...


回答1:


If you return the node directly from cypher via the http endpoints it will return a map with all property-names and property-values.

 MATCH (n) return n

In Java you'd just go over n.getPropertyKeys().

For your regexp question you should split up your question into two.




回答2:


This is how i finally did:

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;
    }

Where the id parameter is returned by this:

match (t:Translation) return id(t)

I call getTradParameters() with every iterator of my request and then i have a container with the name of all of the parameters of my node.

The Last part is calling this function :

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;
    }

To create my big Cypher request to get all of the properties i need on my node, and then i just need to get the answers and store them in a container, to display it in a table using vaadin.



来源:https://stackoverflow.com/questions/26274135/how-to-return-all-properties-of-a-node-with-their-name-and-their-value-using-cyp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!