0

I am trying to update a apoc plugin for Gephi, so that I can send weights from Neo4j to Gephi. This is the original version of the plugin. What was my thinking that I could easily rearrange

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

to something like this, where I would change how relationship is being parsed, and add a weight to return

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

Now the problem occurs that I am a JAVA noob and have no idea how to interact with JAVA data types. I found this documentation on property container, where i found the getProperty(String key) method and I tried to use it, like above but got the next error

/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");

I think this is some basic JAVA problem, but I have no idea how to debug this. I also tried String weight = r.getProperty(weight); but got the same error. Help appreciated

4

1 回答 1

2

而是尝试Object weight = r.getProperty("weight");文档说getProperty返回对象。

字符串是一个对象。但是一个对象(不一定)不是一个字符串。

于 2017-03-19T14:00:05.467 回答