tibonto / aeon

The Academic Event Ontology (AEON) can be used to represent information regarding academic events.
https://tibonto.github.io/aeon/
Creative Commons Attribution 4.0 International
14 stars 4 forks source link

create test-workflow to check the parsing of the mapping JSON #78

Closed StroemPhi closed 3 years ago

StroemPhi commented 3 years ago

We need an automatic test that'll check if the JSON in the aeon:maps_to annotation property can be correctly parsed into a Python dict. The following code should run in the test without errors:

'''code to test if the JSON in the aeon:maps_to annotation property is correct'''

# open a graph
graph = rdflib.Graph()
# load some data
graph.parse('C:/Users/StroemertP/AEON/aeon/aeon.ttl', format="ttl")  
# query for mapping dictionary in aeon:mapsTo
qres = graph.query(
    """
    PREFIX aeon: <https://github.com/tibonto/aeon#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>

    SELECT DISTINCT ?aeon_property ?maps_to ?aeon_property_domain ?rdfs_label ?WikidataURI ?WikidataLabel

    WHERE {
            ?aeon_property aeon:AEON_0000026 ?maps_to.
            {?aeon_property rdf:type owl:ObjectProperty.} UNION             
            {?aeon_property rdf:type owl:DatatypeProperty.}
            OPTIONAL {?aeon_property rdfs:domain ?aeon_property_domain.}
            OPTIONAL {?aeon_property rdfs:label ?rdfs_label.}
           }

    """)

print("the graph has %s statements\n" % len(qres))

for printout in qres:
    printout_dict = printout.asdict()
    #print (printout_dict)

    # get the annotated aeon property
    aeon_property = str(printout_dict.get('aeon_property'))
    # cut off base URI
    aeon_property = aeon_property.replace("https://github.com/tibonto/aeon#","")

    # get the mappings from annotation property maps_to
    maps_to = json.loads(str(printout_dict.get('maps_to')))
    # print mapping dictionary
    print(maps_to)
    print ('\n')
StroemPhi commented 3 years ago

@andrecastro0o is this what you need?

andrecastro0o commented 3 years ago

should be a good to start from

andrecastro0o commented 3 years ago

@StroemPhi checkout branch issue78_tests branch

Is a simple pytest approach to testing the maps_to json, based on the code you posted here.

We can use the same scheme to test other components of the ontology.

See if you can run the tests in your system from the instructions in the new RADME Section: Development

andrecastro0o commented 3 years ago

If I get a bit of time I would like to integrate it with github actions so that the tests are run prior to each merge request.

StroemPhi commented 3 years ago

Thank you @andrecastro0o! It works but I get the following warning

StroemertP@NB-W8P15450 MINGW64 ~/AEON/aeon (issue78_tests)
$ pytest
============================= test session starts =============================
platform win32 -- Python 3.8.2, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: C:\Users\StroemertP\AEON\aeon, configfile: pytest.ini, testpaths: tests
collected 2 items

tests/test_ontology.py::test_test PASSED                                 [ 50%]
tests/test_ontology.py::test_maps_to_property PASSED                     [100%]

============================== warnings summary ===============================
..\..\appdata\local\programs\python\python38-32\lib\site-packages\win32\lib\pywintypes.py:2
  c:\users\stroemertp\appdata\local\programs\python\python38-32\lib\site-packages\win32\lib\pywintypes.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp, sys, os

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================== 2 passed, 1 warning in 7.28s =========================
andrecastro0o commented 3 years ago

@StroemPhi those are not important they are windows warning relating to libraries that the imported libraries use. No reason to worry, but you can always start using Linux, "but can it run Doom?" yes, it can!