我正在尝试更新Gephi的apoc插件,以便我可以将重量从Neo4j发送到Gephi。这是原始版本of the plugin。什么是我的想法,我可以轻松地重新排列使用Neo4j Java API属性容器
private Map<String, Object> data(PropertyContainer pc, Map<String, Map<String, Object>> colors) {
if (pc instanceof Node) {
Node n = (Node) pc;
String labels = Util.labelString(n);
Map<String, Object> attributes = map("label", caption(n), "TYPE", labels);
attributes.putAll(positions());
attributes.putAll(color(labels,colors));
return map(idStr(n), attributes);
}
if (pc instanceof Relationship) {
Relationship r = (Relationship) pc;
String type = r.getType().name();
Map<String, Object> attributes = map("label", type, "TYPE", type);
attributes.putAll(map("source", idStr(r.getStartNode()), "target", idStr(r.getEndNode()), "directed", true));
attributes.putAll(color(type, colors));
return map(String.valueOf(r.getId()), attributes);
}
return map();
}
到这样的事情,在那里我会怎么改关系正在解析,并添加重量返回
private Map<String, Object> data(PropertyContainer pc, Map<String, Map<String, Object>> colors) {
if (pc instanceof Node) {
Node n = (Node) pc;
String labels = Util.labelString(n);
Map<String, Object> attributes = map("label", caption(n), "TYPE", labels);
attributes.putAll(positions());
attributes.putAll(color(labels,colors));
return map(idStr(n), attributes);
}
if (pc instanceof Relationship) {
Relationship r = (Relationship) pc;
String type = r.getType().name();
String weight = r.getProperty("weight");
Map<String, Object> attributes = map("label", type, "TYPE", type);
attributes.putAll(map("source", idStr(r.getStartNode()), "target", idStr(r.getEndNode()), "directed", false,"weight",weight));
attributes.putAll(color(type, colors));
return map(String.valueOf(r.getId()), attributes);
}
return map();
}
现在出现了问题,我我是一个JAVA noob,并不知道如何与JAVA数据类型进行交互。我发现这个documentation on property container,在那里我找到了getProperty(String key)
方法,我试图使用它,像上面却得到了一个错误
/Users/Hal/Job/neo4j-apoc-procedures/src/main/java/apoc/gephi/Gephi.java:81: error: incompatible types: Object cannot be converted to String String weight = r.getProperty("weight");
我想这是一些基本的Java问题,但我不知道如何调试这。我也试过String weight = r.getProperty(weight);
,但得到了同样的错误。帮助赞赏