Skip to content
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

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

Merged
merged 39 commits into from May 25, 2022

Conversation

gNahcab
Copy link
Contributor

@gNahcab gNahcab commented May 16, 2022

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 irinaschubert and BalduinLandolt and removed request for jnussbaum May 23, 2022 14:17
Copy link

@irinaschubert irinaschubert left a comment

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?

Copy link
Collaborator

@BalduinLandolt BalduinLandolt left a comment

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 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
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
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).

Copy link

@irinaschubert irinaschubert left a comment

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.

knora/dsplib/utils/onto_validate.py Outdated Show resolved Hide resolved
knora/dsplib/utils/onto_validate.py Outdated Show resolved Hide resolved
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
@sonarcloud
Copy link

sonarcloud bot commented May 25, 2022

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.

None yet

4 participants