Skip to content

fix(onto validation): correctly identify circular dependencies (DEV-769) - #192

Merged
jnussbaum merged 39 commits into
mainfrom
wip/dev-769-onto-validation-circular
May 25, 2022
Merged

jnussbaum merged 39 commits into
mainfrom
wip/dev-769-onto-validation-circular

Conversation

@gNahcab

@gNahcab gNahcab commented May 16, 2022

Copy link
Copy Markdown
Contributor

resolves DEV-769

@gNahcab
gNahcab requested a review from jnussbaum May 16, 2022 13:12
@gNahcab gNahcab self-assigned this May 16, 2022
@jnussbaum
jnussbaum marked this pull request as ready for review May 16, 2022 13:41
@jnussbaum
jnussbaum requested review from BalduinLandolt and irinaschubert and removed request for jnussbaum May 23, 2022 14:17

@irinaschubert irinaschubert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, there are already tests that test the expected behaviour, right?

@BalduinLandolt BalduinLandolt left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice!

I second Irina that this should be tested. If it already is, even better! Otherwise it would be good to have a couple of unit tests for the circular dependency method.

One thing though: I think the PR title could be a bit more descriptive (as this is used for the changelog, so it should be understandable for someone who doesn't know the code). Rather than naming the function that is improved, it should mention the functionality that is improved.

Comment thread knora/dsplib/utils/onto_validate.py Outdated
Comment on lines +121 to +138
# transform the dependencies into a graph structure
graph = nx.MultiDiGraph()
for start, cards in dependencies.items():
for edge, targets in cards.items():
for target in targets:
graph.add_edge(start, target, edge)

# check circles if they have all '0-1' or '0-n'
errors: set[str] = set()
circles = list(nx.simple_cycles(graph))
for circle in circles:
for index, resource in enumerate(circle):
target = circle[(index+1) % len(circle)]
for property, targets in dependencies[resource].items():
if target in targets:
prop = property
if cardinalities[resource][prop] not in ['0-1', '0-n']:
errors.add(f'Resource "{resource}", property "{prop}"')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is a really neat solution for the problem, congratulations!

@jnussbaum jnussbaum changed the title fix: improve onto-validation-circular(DEV-769) fix(onto validation): correctly identify circular dependencies (DEV-769) May 24, 2022
@jnussbaum jnussbaum assigned jnussbaum and unassigned gNahcab May 24, 2022
@jnussbaum

Copy link
Copy Markdown
Collaborator

I added tests, and refactored the code to make it better testable.
For the test: First I wanted to take the existing test-onto.json, and inject circularity into it inside the testing method. But then, I realised that this gets easily broken if someone modifies the test onto. So it's better to have a separate circular onto saved as JSON file (this way it is reusable).

@irinaschubert irinaschubert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. It is a good idea to do it in a separate ontology. This keeps things clean and tidy.

Comment thread knora/dsplib/utils/onto_validate.py Outdated
Comment thread knora/dsplib/utils/onto_validate.py Outdated
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jnussbaum
jnussbaum merged commit ed35902 into main May 25, 2022
@jnussbaum
jnussbaum deleted the wip/dev-769-onto-validation-circular branch May 25, 2022 19:10
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.

4 participants