-
Notifications
You must be signed in to change notification settings - Fork 3
Keywords with context input #513
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
Changes from all commits
ff443be
dcb1e08
be46b4d
2f1db7c
034423b
2d2a930
79b7ca8
dc1264f
6138d7b
60a331d
89981df
cef25d6
d6615fc
12cb61a
328861f
636c4bd
f2e53be
1ef9b39
a4556e2
583992d
5b51fb5
38c17fd
e307f5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,6 +402,48 @@ def test_store(): | |
| } | ||
|
|
||
|
|
||
| def test_update_context(): | ||
| """Test update_context().""" | ||
| from tripper import HUME, OWL, Namespace | ||
| from tripper.datadoc import get_context | ||
| from tripper.datadoc.dataset import update_context | ||
|
|
||
| EX = Namespace("http://example.com/") | ||
| sources = { | ||
| "@context": { | ||
| "ex": str(EX), | ||
| "hume": str(HUME), | ||
| }, | ||
| "@graph": [ | ||
| { | ||
| # Instances are not added to context | ||
| "@id": "ex:instr", | ||
| "@type": "hume:Device", | ||
| }, | ||
| { | ||
| # Not added to context, since there is no @type | ||
| "@id": "ex:instr2", | ||
| }, | ||
| { | ||
| "@id": "ex:MyDevice", | ||
| "skos:prefLabel": "MyDevice", | ||
| "subClassOf": "hume:Device", | ||
| }, | ||
| ], | ||
| } | ||
| context = get_context(default_theme=None) | ||
| update_context(sources, context) | ||
| c = context.get_context_dict() | ||
| assert "instr" not in c | ||
| assert "instr2" not in c | ||
| assert "MyDevice" in c | ||
| assert c["MyDevice"] == {"@id": EX.MyDevice, "@type": OWL.Class} | ||
| assert c["Device"] == {"@id": HUME.Device, "@type": OWL.Class} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should have som check on what happens if there is mismatch between previously added context and updated_context.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not prioritised for now. Added a TODO in test_dataset.py |
||
|
|
||
| # TODO: add tests for what happens if there is mismatch between | ||
| # previously added context and updated_context... | ||
|
|
||
|
|
||
| def test_infer_restriction_types(): | ||
| """Test infer_restriction_types().""" | ||
| from tripper import DCTERMS, HUME, RDFS, Namespace | ||
|
|
@@ -426,7 +468,7 @@ def test_infer_restriction_types(): | |
| "http://example.org#A": { | ||
| DCTERMS.creator: "some", | ||
| DCTERMS.hasPart: "value", | ||
| DCTERMS.issued: "value", | ||
| # DCTERMS.issued: "value", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this commented out?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because The value restriction for dcterms:hasPart should probably also be removed. That will be addressed in upcoming PRs. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -452,7 +494,7 @@ def test_infer_restriction_types(): | |
| "@id": "ex:MyDevice", | ||
| # "@type": "owl:Class", | ||
| "subClassOf": HUME.Device, | ||
| "hasPart": HUME.MeasuringInstrument, | ||
| "hasPart": [HUME.MeasuringInstrument, "ex:MyDevice"], | ||
francescalb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ], | ||
| } | ||
|
|
@@ -577,6 +619,13 @@ def test_update_restrictions(): | |
| "@type": HUME.Device, | ||
| "isDefinedBy": HUME.MeasuringInstrument, | ||
| }, | ||
| { | ||
| # An individial relating to two classes and an individual. | ||
| # Should be converted to an existential restriction. | ||
| "@id": "ex:instr3", | ||
| "@type": HUME.Device, | ||
| "hasPart": [HUME.MeasuringInstrument, "MyDevice", "ex:instr"], | ||
| }, | ||
|
Comment on lines
+622
to
+628
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For completeness we should have individual relating to one individual and individual related to a list of individuals
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a TODO about this in test_dataset.py. Will be addressed in the next PR that focuses on the update_restrictions() funtions. |
||
| { | ||
| # A class relating to a class. | ||
| # Should be converted to an existential restriction. | ||
|
|
@@ -586,63 +635,68 @@ def test_update_restrictions(): | |
| "@id": "ex:MyDevice", | ||
| # "@type": "owl:Class", | ||
| "subClassOf": HUME.Device, | ||
| "label": "MyDevice", | ||
| "hasPart": HUME.MeasuringInstrument, | ||
| }, | ||
| { | ||
| # A class relating to two classes | ||
| "@id": "ex:MyDevice2", | ||
| "@type": "owl:Class", | ||
| "subClassOf": HUME.Device, | ||
| "label": "MyDevice2", | ||
| "hasPart": [HUME.MeasuringInstrument, "MyDevice"], | ||
| }, | ||
| # TODO: for completeness, add tests for individual | ||
| # relating to one individual and individual related to a | ||
| # list of individuals | ||
| ], | ||
| } | ||
| r6 = deepcopy(d6) | ||
| update_restrictions(r6, ctx) | ||
| assert r6 == { | ||
| "@context": { | ||
| "MeasuringInstrument": { | ||
| "@id": "https://w3id.org/emmo/hume#MeasuringInstrument", | ||
| "@type": "owl:Class", | ||
| } | ||
| }, | ||
| "@graph": [ | ||
| { | ||
| "@id": "ex:instr", | ||
| "@type": "https://w3id.org/emmo/hume#Device", | ||
| "isDefinedBy": "https://w3id.org/emmo/hume#MeasuringSystem", | ||
| }, | ||
| res6 = {d["@id"]: d for d in r6["@graph"]} | ||
| assert res6["ex:instr"] == { | ||
| "@id": "ex:instr", | ||
| "@type": "https://w3id.org/emmo/hume#Device", | ||
| "isDefinedBy": "https://w3id.org/emmo/hume#MeasuringSystem", | ||
| } | ||
| assert res6["ex:instr2"] == { | ||
| "@id": "ex:instr2", | ||
| "@type": [ | ||
| "https://w3id.org/emmo/hume#Device", | ||
| { | ||
| "@id": "ex:instr2", | ||
| "@type": [ | ||
| "https://w3id.org/emmo/hume#Device", | ||
| { | ||
| "@type": "owl:Restriction", | ||
| "owl:onProperty": { | ||
| "@id": ( | ||
| "http://www.w3.org/2000/01/rdf-schema#" | ||
| "isDefinedBy" | ||
| ) | ||
| }, | ||
| "owl:someValuesFrom": { | ||
| "@id": ( | ||
| "https://w3id.org/emmo/hume#MeasuringInstrument" | ||
| ) | ||
| }, | ||
| }, | ||
| ], | ||
| "@type": "owl:Restriction", | ||
| "owl:onProperty": { | ||
| "@id": "http://www.w3.org/2000/01/rdf-schema#isDefinedBy", | ||
| }, | ||
| "owl:someValuesFrom": { | ||
| "@id": "https://w3id.org/emmo/hume#MeasuringInstrument", | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
| assert res6["ex:instr3"] == { | ||
| # WRONG! Should be converted to restrictions | ||
| "@id": "ex:instr3", | ||
|
Comment on lines
+678
to
+679
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be fixed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, working on this in PR #514 |
||
| "@type": "https://w3id.org/emmo/hume#Device", | ||
| "hasPart": [ | ||
| "https://w3id.org/emmo/hume#MeasuringInstrument", | ||
| "MyDevice", | ||
| "ex:instr", | ||
| ], | ||
| } | ||
| assert res6["ex:MyDevice"] == { | ||
| "@id": "ex:MyDevice", | ||
| "subClassOf": [ | ||
| "https://w3id.org/emmo/hume#Device", | ||
| { | ||
| "@id": "ex:MyDevice", | ||
| "subClassOf": [ | ||
| "https://w3id.org/emmo/hume#Device", | ||
| { | ||
| "@type": "owl:Restriction", | ||
| "owl:onProperty": { | ||
| "@id": "http://purl.org/dc/terms/hasPart" | ||
| }, | ||
| "owl:someValuesFrom": { | ||
| "@id": ( | ||
| "https://w3id.org/emmo/hume#MeasuringInstrument" | ||
| ) | ||
| }, | ||
| }, | ||
| ], | ||
| "@type": "owl:Restriction", | ||
| "owl:onProperty": {"@id": "http://purl.org/dc/terms/hasPart"}, | ||
| "owl:someValuesFrom": { | ||
| "@id": "https://w3id.org/emmo/hume#MeasuringInstrument" | ||
| }, | ||
| }, | ||
| ], | ||
| "label": "MyDevice", | ||
| } | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.