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

Added test for example at CBD definition. Fixes #1914. #1915

Merged
merged 6 commits into from
May 13, 2022

Conversation

asejal
Copy link
Contributor

@asejal asejal commented May 12, 2022

Fixes #1914

Summary of changes

We have added a test for the example at the definition for Concise Bounded Definition here. It has been converted to turtle format for uniformity.

For the given RDF graph as input:
WhatsApp Image 2022-05-12 at 11 40 03 PM

Expected output for CBD of http://example.com/aReallyGreatBook corresponds to the following subgraph:
WhatsApp Image 2022-05-12 at 11 41 52 PM

The test passes.
In collaboration with @ms1901.

@asejal
Copy link
Contributor Author

asejal commented May 12, 2022

pre-commit.ci autofix

@coveralls
Copy link

coveralls commented May 12, 2022

Coverage Status

Coverage remained the same at 88.248% when pulling ce07700 on asejal:master into 5e5dcea on RDFLib:master.

Comment on lines 113 to 114
# add example from Concise Bounded Description definition at https://www.w3.org/Submission/CBD/#example
g.parse(
Copy link
Member

Choose a reason for hiding this comment

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

This should be in a separate test function.

Comment on lines 116 to 172
PREFIX ex: <http://ex/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>

ex:aBookCritic ex:dislikes ex:anotherGreatBook ;
ex:likes ex:aReallyGreatBook .

[ a rdf:Statement ;
rdf:object "image/jpeg" ;
rdf:predicate dc:format ;
rdf:subject foaf:Image ;
rdfs:isDefinedBy ex:image-formats.rdf
] .

foaf:mbox a owl:InverseFunctionalProperty , rdf:Property .

[ a rdf:Statement ;
rdf:object "application/pdf" ;
rdf:predicate dc:format ;
rdf:subject ex:aReallyGreatBook ;
rdfs:isDefinedBy ex:book-formats.rdf
] .

ex:aReallyGreatBook rdfs:seeAlso ex:anotherGreatBook ;
dc:contributor [ a foaf:Person ;
foaf:name "Jane Doe"
] ;
dc:creator [ a foaf:Person ;
foaf:img ex:john.jpg ;
foaf:mbox "[email protected]" ;
foaf:name "John Doe" ;
foaf:phone <tel:+1-999-555-1234>
] ;
dc:format "application/pdf" ;
dc:language "en" ;
dc:publisher "Examples-R-Us" ;
dc:rights "Copyright (C) 2004 Examples-R-Us. All rights reserved." ;
dc:title "A Really Great Book" ;
dct:issued "2004-01-19"^^xsd:date .

ex:anotherGreatBook rdfs:seeAlso ex:aReallyGreatBook ;
dc:creator "June Doe ([email protected])" ;
dc:format "application/pdf" ;
dc:language "en" ;
dc:publisher "Examples-R-Us" ;
dc:rights "Copyright (C) 2004 Examples-R-Us. All rights reserved." ;
dc:title "Another Great Book" ;
dct:issued "2004-05-03"^^xsd:date .

ex:john.jpg a foaf:Image ;
dc:extent "1234" ;
dc:format "image/jpeg" .
Copy link
Member

@aucampia aucampia May 12, 2022

Choose a reason for hiding this comment

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

I would prefer this rather go into a file in test/data/spec/cbd/example_graph.rdf as RDF XML (i.e. identical to what is here) and then place the "concise bounded description of http://example.com/aReallyGreatBook" in test/data/spec/cbd/example_graph_cbd.rdf

Comment on lines 177 to 179
assert len(g.cbd(EX.aReallyGreatBook)) == (
21
), "cbd() for aReallyGreatBook should return 21 triples"
Copy link
Member

Choose a reason for hiding this comment

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

This is not sufficent, this should check that the resulting graph from Graph.cbd is isomorphic to and identical to (when discarding triples) the graph given in https://www.w3.org/Submission/CBD/#example

To do this you can use

GraphHelper.assert_isomorphic and GraphHelper.assert_sets_equals(..., exclude_blanks=True) for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review.
We have completed the above requirements. We have created a separate function for testing the CBD example along with all the above mentioned asserts, and also added two separate data files.

Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

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

Thank you very much for having a look at this @asejal - though please see the feedback.

@asejal
Copy link
Contributor Author

asejal commented May 12, 2022

pre-commit.ci autofix

Comment on lines 9 to 10
EXAMPLE_GRAPH_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph.rdf"])
EXAMPLE_GRAPH_CBD_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph_cbd.rdf"])
Copy link
Member

Choose a reason for hiding this comment

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

This is causing some failure:

  test/test_graph/test_graph_cbd.py:9: error: No overload variant of "join" matches argument type "List[object]"  [call-overload]
  test/test_graph/test_graph_cbd.py:9: note: Possible overload variants:
  test/test_graph/test_graph_cbd.py:9: note:     def join(__a, Union[str, PathLike[str]], *paths: Union[str, PathLike[str]]) -> str
  test/test_graph/test_graph_cbd.py:9: note:     def join(__a, Union[bytes, PathLike[bytes]], *paths: Union[bytes, PathLike[bytes]]) -> bytes
  test/test_graph/test_graph_cbd.py:10: error: No overload variant of "join" matches argument type "List[object]"  [call-overload]
  test/test_graph/test_graph_cbd.py:10: note: Possible overload variants:
  test/test_graph/test_graph_cbd.py:10: note:     def join(__a, Union[str, PathLike[str]], *paths: Union[str, PathLike[str]]) -> str
  test/test_graph/test_graph_cbd.py:10: note:     def join(__a, Union[bytes, PathLike[bytes]], *paths: Union[bytes, PathLike[bytes]]) -> bytes
  Found 2 errors in 1 file (checked 299 source files)

The following should work:

Suggested change
EXAMPLE_GRAPH_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph.rdf"])
EXAMPLE_GRAPH_CBD_FILE_PATH = os.path.join(*[TEST_DATA_DIR, "spec", "cbd", "example_graph_cbd.rdf"])
EXAMPLE_GRAPH_FILE_PATH = TEST_DATA_DIR / "spec" / "cbd" / "example_graph.rdf"
EXAMPLE_GRAPH_CBD_FILE_PATH = TEST_DATA_DIR / "spec" / "cbd" / "example_graph_cbd.rdf"

Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

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

Looks very good now, just some issue with the Paths.

@@ -109,3 +122,21 @@ def testCbdReified(get_graph):
)

assert len(g.cbd(EX.R6)) == (3 + 5 + 5), "cbd() for R6 should return 12 triples"


def testCbdExample():
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def testCbdExample():
def test_cbd_example():

Function names should conform to PEP8[ref]:

https://peps.python.org/pep-0008/#function-and-variable-names

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

@asejal
Copy link
Contributor Author

asejal commented May 12, 2022

pre-commit.ci autofix

Copy link
Member

@aucampia aucampia left a comment

Choose a reason for hiding this comment

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

Thanks @asejal - very happy to have this in place.

@aucampia aucampia requested a review from a team May 12, 2022 21:10
@aucampia aucampia added the review wanted This indicates that the PR is ready for review label May 12, 2022
@aucampia
Copy link
Member

Will wait for some more feedback but as this is just adding a test I think it is fine with one review, so I will merge it tomorrow unless there is more feedback.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

lgtm

@asejal
Copy link
Contributor Author

asejal commented May 13, 2022

Hi @aucampia, since the pull request has been approved will it be possible for you to merge it? Thanks.

@aucampia aucampia merged commit e5f3f1f into RDFLib:master May 13, 2022
@ghost ghost removed the review wanted This indicates that the PR is ready for review label Jun 4, 2022
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.

Include Concise Bounded Description example in the tests for Graph.cbd
3 participants