2017-03-19 3 views
0

J'essaie de mettre à jour un plugin apoc pour Gephi, afin que je puisse envoyer des poids de Neo4j à Gephi. Ceci est la version originale of the plugin. Quelle était ma façon de penser que je pourrais facilement réorganiserUtilisation de la propriété Neo4j Java API Conteneur

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

à quelque chose comme ça, où je changerais la relation est en cours d'analyse, et d'ajouter un poids à revenir

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

Maintenant, le problème se produit que je Je suis un Noob JAVA et je n'ai aucune idée de comment interagir avec les types de données JAVA. J'ai trouvé ce documentation on property container, où je l'ai trouvé la méthode getProperty(String key) et j'ai essayé de l'utiliser, comme ci-dessus mais on m'a donné l'erreur suivante

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

Je pense que cela est un problème JAVA de base, mais je ne sais pas comment déboguer ce . J'ai également essayé String weight = r.getProperty(weight); mais j'ai eu la même erreur. Aide appréciée

Répondre

2

Essayez plutôt Object weight = r.getProperty("weight"); La documentation indique getProperty renvoie Objet.

Une chaîne est un objet. Mais un objet n'est pas (nécessairement) une chaîne.