-
Notifications
You must be signed in to change notification settings - Fork 617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Node with interfaces returned as a parent class #2839
Comments
Could you please rephrase the scenario again you are currently in? I think that, after writing down a few assumptions in my own words, I am on the wrong track. |
Hi, sorry for my lack of clarity. Yes we are having the inheritance chain, it goes as follow: public interface D {}
public class C {}
public class B extends C implements D {}
public class A extends B {} The problem occurs when using neo4jTemplate with cutsom query. MATCH path=(p:Pathway{stId:$stId})-[:hasEvent*]->(rle:ReactionLikeEvent)
WHERE SINGLE(x IN NODES(path) WHERE (x:Pathway) AND x.hasDiagram)
MATCH (rle)-[:input|output|catalystActivity|physicalEntity|regulatedBy|regulator*]->(pe:EntityWithAccessionedSequence)
WITH DISTINCT pe
MATCH (pe)-[hm:hasModifiedResidue]->(tm:TranslationalModification)
RETURN DISTINCT pe, collect(hm), collect(tm) so it basically returns a node, plus some additional attributes of the node from the database. Either spring-data-neo4j doesn't support node definition implementing interfaces, or we configured them wrong (maybe we need to annotate the interfaces with That is not a problem by itself, however, that leads to a situation where none of the NodeDescription in the haystack are a "perfect match" for the node received from the database. Therefore, This makes that the first node among the inheritance chain in the haystack that have a This problem was noticed because we are using interfaces, but I think it would arise anytime you have nodes in the database having more labels than those described in the SDN model. The little snippet I provided in the issue description should fix this issue I believe, as indeed, among those having the lowest In our specific case,
A perfect match being of course [0, 6] in this situation, the closest to being perfect would be the I think another implementaiton that could lead to similar outcomes would be to replace int labelDifference = 0;
List<String> matchingLabels = new ArrayList<>();
for (String staticLabel : staticLabels) {
if (labels.contains(staticLabel)) {
matchingLabels.add(staticLabel);
labelDifference--;
} else {
labelDifference++;
}
}
But these are just proposals, you might find better and cleaner solution. I hope this clarified a bit our problem, and thanks for your support |
Just to keep you informed, by adding the However, the 2nd strategy is still invalid for inheritance chains if they are labels in the database that are not defined in SDN. |
I have an issue where I have defined some @node with interfaces so that I can fetch a group of Nodes which are unrelated in terms of inheritance.
Because of this, my nodes are having labels that the NodeDescriptionStore is not aware of, since it doesn't resolve interface as Labels.
Because of that, none of the haystack definitions are a perfect match for the result labels, which is absolutely fine in theory .
spring-data-neo4j/src/main/java/org/springframework/data/neo4j/core/mapping/NodeDescriptionStore.java
Lines 134 to 138 in 1dc29c1
Since none of them is a perfect match, it then try to pick the
mostMatchingNodeDescription
and that is where the problem lies I believe:spring-data-neo4j/src/main/java/org/springframework/data/neo4j/core/mapping/NodeDescriptionStore.java
Lines 140 to 155 in 1dc29c1
Indeed, with the current implementation, if
A
extendsB
andB
extendsC
but the record node labels are [
A
,B
,C
,D
], then even thoughA
is the most "concrete" class,A
,B
andC
node description will all have anunmatchedLabelCount
of 0.Therefore, the NodeDescription being picked in the end is the one that was first in the haystack, not the one with the most matching labels.
I would suggest something like
This way, if there is a tie in terms of "unmatchness", we pick the one with the best "matchness", aka, the one with the biggest amount of matching labels
Thanks for all the support you already provided to Reactome team,
Best regards,
Eliot
The text was updated successfully, but these errors were encountered: