-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add query to delete statement #93
Changes from all commits
3c8f23d
c0f5dbc
e619f80
1a66505
a69dc32
e44c843
7615728
4164985
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
"""Tests for utility methods.""" | ||
|
||
|
||
import re | ||
import uuid | ||
from typing import Optional, Union | ||
|
@@ -302,3 +301,68 @@ def test_get_query_for_conditional_get_statements( | |
assert utils.get_query_for_conditional_get_statements( | ||
pkg_data_example.triple | ||
) == strip_string(expected_query) | ||
|
||
|
||
def test_get_query_for_remove_statement( | ||
pkg_data_example: PKGData, statement_representation: str | ||
) -> None: | ||
"""Tests get_query_for_remove_statement method. | ||
|
||
Args: | ||
pkg_data_example: PKG data example. | ||
statement_representation: Statement representation. | ||
""" | ||
statement_node_id = utils.get_statement_node_id(pkg_data_example) | ||
statement_representation = statement_representation.replace( | ||
statement_node_id, "?statement" | ||
) | ||
statement_representation = re.sub( | ||
r'dc:description "[^"]+" ;', "", statement_representation | ||
) | ||
sparql_query = f""" | ||
DELETE {{ | ||
?statement ?p ?o . | ||
?preference ?pp ?op . | ||
}} | ||
WHERE {{ | ||
{statement_representation} | ||
?statement ?p ?o . | ||
OPTIONAL {{ | ||
?preference pav:derivedFrom ?statement . | ||
?preference ?pp ?op . | ||
}} | ||
}} | ||
""" | ||
|
||
assert utils.get_query_for_remove_statement( | ||
pkg_data_example | ||
) == strip_string(sparql_query) | ||
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. Tests for 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. I added a test for |
||
|
||
|
||
def test_get_query_for_remove_preference( | ||
pkg_data_example: PKGData, statement_representation: str | ||
) -> None: | ||
"""Tests get_query_for_remove_preference method.""" | ||
statement_node_id = utils.get_statement_node_id(pkg_data_example) | ||
statement_representation = statement_representation.replace( | ||
statement_node_id, "?statement" | ||
) | ||
statement_representation = re.sub( | ||
r'dc:description "[^"]+" ;', "", statement_representation | ||
) | ||
|
||
sparql_query = f""" | ||
DELETE {{ | ||
?preference ?p ?o . | ||
?subject wi:preference ?preference . | ||
}} | ||
WHERE {{ | ||
{statement_representation} | ||
?subject wi:preference ?preference . | ||
?preference pav:derivedFrom ?statement . | ||
?preference ?p ?o . | ||
}} | ||
""" | ||
assert utils.get_query_for_remove_preference( | ||
pkg_data_example | ||
) == strip_string(sparql_query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description is removed because it not possible that it is the same when asking to remove a statement, especially when using natural language. For example, a user might input "Delete my preference towards Tom Cruise" or " Remove the statements related to Tom Cruise" to remove the statement "I like Tom Cruise."