我正在使用BatchInserter实例来获取和设置节点的属性。 我的数据在某些属性中有多个值。
property value ======== ========= synonym animal synonym mammalian我想将这些值放在同一节点的同一属性中。
我使用以下代码片段来读取和设置值:
String[] values = {"animal", "mammalian"}; for (int i = 0; i < values.length(); i++) { Map<String, Object> nodeProps = db.getNodeProperties(0); // Node 0 properties nodeProps.put("synonym", values[i]); db.setNodeProperties(0, nodeProps); }在第一次迭代属性中, synonym获得值animal 。 在第二次迭代中,属性被 mammalian值覆盖 。
我的问题是:如何获取之前的值,添加新的值并将属性设置为节点,以便我可以在图形中获得synonym=['animal', 'mammalian'] ?
I am using the BatchInserter instance to get and set properties for nodes. My data have multiple values in some properties.
property value ======== ========= synonym animal synonym mammalianI want to put this values, in the same property in the same node.
I have used the following code snippet to read and set values:
String[] values = {"animal", "mammalian"}; for (int i = 0; i < values.length(); i++) { Map<String, Object> nodeProps = db.getNodeProperties(0); // Node 0 properties nodeProps.put("synonym", values[i]); db.setNodeProperties(0, nodeProps); }In the first iteration property synonym gets value animal. In the second iteration, the property is overridden by the value mammalian.
My question is: How can I get the previous value(s), add the new one and set the property to the node so I can get synonym=['animal', 'mammalian'] in graph?
最满意答案
如果要在节点/关系属性上具有多个值,则需要使用数组。 所以你在属性synonyms有一个String[]作为值:
修改现有财产:
String[] values = {"animal", "mammalian"}; Map<String, Object> nodeProps = db.getNodeProperties(0); String[] existingValues = nodeProps.get("synonym"); // using org.apache.commons.lang.ArrayUtils from Apache Commons Lang: String[] amendedValues = ArrayUtils.addAll(existingValues, values); nodeProps.put("synonym", amendedValues); db.setNodeProperties(0, nodeProps);If you want to have multiple values on a node/relationship property you need to use arrays. So you have on property synonyms with a String[] as value:
To amend an existing property:
String[] values = {"animal", "mammalian"}; Map<String, Object> nodeProps = db.getNodeProperties(0); String[] existingValues = nodeProps.get("synonym"); // using org.apache.commons.lang.ArrayUtils from Apache Commons Lang: String[] amendedValues = ArrayUtils.addAll(existingValues, values); nodeProps.put("synonym", amendedValues); db.setNodeProperties(0, nodeProps);更多推荐
发布评论