Skip to content

Fixes #519: Knowledge Gap bug with semi-duplicate triples#594

Merged
Sophietje merged 3 commits intomasterfrom
519-fix-knowledge-gap-bug
Jan 31, 2025
Merged

Fixes #519: Knowledge Gap bug with semi-duplicate triples#594
Sophietje merged 3 commits intomasterfrom
519-fix-knowledge-gap-bug

Conversation

@Sophietje
Copy link
Collaborator

There's a bug in getKnowledgeGaps() where a gap is returned with two nearly-identical triples, e.g.: ?id hasCountry ?country and ?id hasCountry Ireland. We only want to keep the ?id hasCountry Ireland in this case and ignore the triple with the additional variable.

Copy link
Collaborator

@bnouwt bnouwt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Sophietje, thanks for the changes 👍 I finished the review. Please do not consider the comments to be very important and feel free to choose to ignore them. I think it is useful to just mention most things that come up during a review although not all of them are equally relevant 😄

for (Entry<RuleNode, Set<Match>> entry : someAntecedentNeighbors.entrySet()) {
for (Match m : entry.getValue()) {
if (m.getMatchingPatterns().keySet().contains(tp)) {
if (m.getMatchingPatterns().containsValue(tp)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sophietje Do you remember why this change was necessary? Because the removed line and the added line do not check the same thing. I vaguely remember looking at this together, but do not remember the reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite remember. If I change it back to keySet(), the testKnowledgeGapNoMatchingVars() exits with the knowledge gap: [?iq hasImage ?image, ?iq type ImperialFaberge, ?iq madeIn ?country, ?iq madeBy ?company] whereas we originally defined the expected knowledge gap to be: [?id madeIn Russia, ?id commissionedBy Alexander III, ?id madeBy House of Fabergé]

private static TripleMatchType getTripleMatchType(TriplePattern existingTriple, TriplePattern newTriple) {
Map<TripleNode, TripleNode> matches = existingTriple.findMatches(newTriple);
if (matches == null) {
return TripleMatchType.ADD_TRIPLE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always try to have only a single return statement per method, because this increases readability in many cases. Not a necessary change, just want to mention it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific case I think I disagree. I'd prefer a clear return thus indicating end of this method for an (easy) case if it's at the beginning of a method, as opposed to needing to read the rest of the method to see whether anything else happens. I do agree that the return later on is less neat and I'll fix that.

private AskKnowledgeInteraction askKI;
private Set<Rule> ruleSet;

@BeforeEach
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice you are executing this setup() method @BeforeEach test method. Is that necessary? Because it makes the test quite a bit slower, I think. Or is it because some method create additional Knowledge Interactions that you do want lying around for subsequent tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly that second part, this way it's clear which KIs are supposed to be part of which test case, not adding any unnnecessary clutter.

@Sophietje Sophietje merged commit 50d163c into master Jan 31, 2025
2 checks passed
@Sophietje Sophietje deleted the 519-fix-knowledge-gap-bug branch January 31, 2025 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix bug in knowledge gap detection algorithm.

2 participants