1 of 21

Ontology testing �in eXtreme Design��

Fiorela Ciroku

PhD student, cycle XXXV, University of Bologna

fiorela.ciroku2@unibo.it

2 of 21

Outline

  • User stories
  • Competency question verification tests
  • Inference verification tests
  • Error provocation tests

3 of 21

User stories

A user story is a set of sentences which describe by example the kind of facts that the knowledge graph is required to encode.

User stories may be described by:

  • priority level
  • title (to express possible dependencies of a story to others)
  • identifier (to express possible dependencies of a story to others)

4 of 21

Persona���Carolina is a music historian with a passion for the Baroque. She is a researcher and collaborates with the International Museum and the Music Library of Bologna.

Goal���Carolina has to prepare a conference for the anniversary of the birth of the composer Giacomo Antonio Perti and she needs to collect some information about his career.

Scenario��In order to accomplish her goal first Carolina must find the scores that constitute her primary sources. Thus, Carolina should find the places where these compositions were played for the first time how many musicians were involved, how many musical instruments, the names of the musicians. Carolina is also interested in the singers involved and the choir. Carolina has to find written evidence that says how these Masses were received. Carolina is also interested in finding out in which tonality the compositions were written.

5 of 21

User stories�Carolina – Competency Questions

1. Where was a musical composition performed?

- In which buildings was a musical composition performed?

2. Where was a musical composition performed for the first time?

- In which buildings was a musical composition performed for the first time?

3. Which performers (musicians, singers) have performed a musical composition?

- Which performers (musicians, singers) have performed a musical composition for the first time?�

6 of 21

Testing in XD

  • Competency Question Verification allows to verify if the ontology can answer the competency questions that have been collected during the requirement collection.�
  • Error Provocation allows to verify how the ontology acts when it is fed random or incorrect data. �
  • Inference Verification allows to verify that the inference mechanisms are in place, to ensure the correct fulfillment of the inference requirement.

7 of 21

Competency question verification�Select a requirement!

Where was a musical composition performed?

8 of 21

Understanding the requirement�Competency question verification test

9 of 21

Where did the prefixes come from?�Competency question verification test

10 of 21

Define test case�Competency question verification test

@prefix owlunit: <https://w3id.org/OWLunit/ontology/> .

@prefix td: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/toy-dataset/> .

@prefix tc: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/test-case/> .

@prefix mp: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/musical-performance.owl> .

tc:CQ1.ttl a owlunit:CompetencyQuestionVerification ;

owlunit:hasCompetencyQuestion "Where was a musical composition performed?" ;

owlunit:hasSPARQLUnitTest ” " ;

owlunit:hasInputData td: ;

owlunit:hasInputTestDataCategory owlunit:ToyDataset ;

owlunit:hasExpectedResult “ ";

owlunit:testsOntology mp: .

11 of 21

Natural language to SPARQL�Competency question verification test

First step: Translate the competency question from natural language to SPARQL query.

Where was a musical composition performed?

PREFIX mp: <https://w3id.org/polifonia/ON/musical-performance/>

PREFIX core: <https://w3id.org/polifonia/ON/core/>

SELECT DISTINCT ?place

WHERE {

?musicalComposition mp:isInvolvedInMusicalPerformance ?performance .

?performance core:hasPlace ?place }

12 of 21

Add test data

Creating a toy dataset, from either real or made-up data!

@prefix td: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/toy-dataset/> .

@prefix mp: <https://w3id.org/polifonia/ON/musical-performance/> .

@prefix core: <https://w3id.org/polifonia/ON/core/> .

td:Toxicity mp:isInvolvedInMusicalPerformance td:SystemOfADown-FirenzeRocks2017 .

td:SystemOfADown-FirenzeRocks2017 core:hasPlace td:Florence .

13 of 21

Determine expected results

- Depending on the test data, determine what output would be correct.

- For example, specify the data with testAnnotationSchema:hasExpectedResult property.

- Expected results can be specified as a JSON serialization or using this vocabulary.

{ \"head\":

{ \"vars\": [ \"place\" ] } ,

\"results\": { \"bindings\":

[ { \"place\": { \"type\": \"uri\" , \"value\": \"https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/toy-dataset/Florence\" } } ] } }

JSON serialization

14 of 21

Define test case�Competency question verification test

@prefix owlunit: <https://w3id.org/OWLunit/ontology/> .

@prefix td: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/toy-dataset/> .

@prefix tc: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/test-case/> .

@prefix mp: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/musical-performance.owl> .

tc:CQ1.ttl a owlunit:CompetencyQuestionVerification ;

owlunit:hasCompetencyQuestion "Where was a musical composition performed?" ;

owlunit:hasSPARQLUnitTest "PREFIX mp: <https://w3id.org/polifonia/ON/musical-performance/> PREFIX core: <https://w3id.org/polifonia/ON/core/> SELECT DISTINCT ?place WHERE {?composition mp:isInvolvedInMusicalPerformance ?performance . ?performance core:hasPlace ?place }" ;

owlunit:hasInputData td:TD1.ttl ;

owlunit:hasInputTestDataCategory owlunit:ToyDataset ;

owlunit:hasExpectedResult "{ \"head\": { \"vars\": [ \"place\" ] } , \"results\": { \"bindings\": [ { \"place\": { \"type\": \"uri\" , \"value\": \"https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/toy-dataset/Florence\" } } ] } }";

owlunit:testsOntology mp: .

15 of 21

Inference verification test

@prefix owlunit: <https://w3id.org/OWLunit/ontology/> .

@prefix mp: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/musical-performance.owl> .

@prefix tc: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/inference/test-case/> .

@prefix td: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/inference/toy-dataset/> .

tc:iv1.ttl a owlunit:InferenceVerification ;

owlunit:hasInputData ex:TD2.ttl ;

owlunit:hasSPARQLUnitTest " PREFIX core: <https://w3id.org/polifonia/ON/core/> ASK {td:SystemOfADown-FirenzeRocks2017 a mp:MusicalPerformance}" ;

owlunit:hasReasoner owlunit:HermiT ;

owlunit:hasExpectedResult true ;

owlunit:testsOntology mp: .

16 of 21

Error provocation test

@prefix owlunit: <https://w3id.org/OWLunit/ontology/> .

@prefix mp: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/musical-performance.owl> .

@prefix tc: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/error/test-case/> .

@prefix td: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/error/toy-dataset/> .

tc:ep1.ttl a owlunit:ErrorProvocation ;

owlunit:hasInputData td:epdata.ttl ;

owlunit:testsOntology mp: .

@prefix td: <https://raw.githubusercontent.com/polifonia-project/musical-performance/main/test/competency-question/toy-dataset/> .

@prefix mp: <https://w3id.org/polifonia/ON/musical-performance/> .

@prefix core: <https://w3id.org/polifonia/ON/core/> .

td:Florence a core:Place .

td:Toxicity mp:isInvolvedInMusicalPerformance td:Florence .

td:SystemOfADown-FirenzeRocks2017 core:hasPlace td:Florence .

17 of 21

Executing the test case�Competency question verification test

java -jar OWLUnit-0.3.2.jar –c https://github.com/polifonia-project/musical-performance-ontology/blob/main/test/competency-question/test-case/CQ1.ttl

18 of 21

Executing the test case�Competency question verification test

19 of 21

Exercise�

Requirement:

When was a recording produced?

- Translate the competency question to a SPARQL query.�- Create a toy dataset for the test case.�- Create an expected result file.�- Create a unit test case for the competency question.�- Create an inference verification test case.�- Create an error provocation test case.

20 of 21

Exercise�

Sources:

- Graffoo diagram�- Relevant ontology owl files: � - Musical performace ontology� - Core ontology

21 of 21

Grazie!