FiorelaCiroku / XD-Testing

This repository is created to keep track on the progress of an automated test management using Github Actions. The testing methodology is based on the eXtreme Design ontology modelling methodology.
2 stars 2 forks source link

Syntax checking #88

Closed FiorelaCiroku closed 2 years ago

FiorelaCiroku commented 2 years ago

Is your feature request related to a problem? Please describe.

Deal with syntax errors by integrating validators/checkers for JSON, SPARQL and natural language.

Describe the solution you'd like

For the competency questions, the action should match a pattern where the ID of the competency question and the competency questions can be retrieved separately.

For the SPARQL query, the action should identify the ID of the query and then validate the query.

For the expected results, the action should identify the ID of the Json file and validate the syntax.

Describe alternatives you've considered

We do not provide this feature.

Additional context

Having these validators part of the workflow reduces the possibility of having failed tests because of syntax errors.

FiorelaCiroku commented 2 years ago

The pattern check for the competency question is: grep -i '[CQ][0-9][0-9]*:\s' filename The pattern check for the SPARQL query is: grep -i '[SQ][0-9][0-9]*:\s' filename The pattern check for the expected results is: grep -i '[ER][0-9][0-9]*:\s' filename

The format should be:

CQ1: Who composed a musical piece?

SQ1: SELECT ?composer WHERE {?composer x:isComposerOf ?musicalPiece. ?musicalPiece a x:MusicalPiece. }

ER1: { \"head\": { \"vars\": [ \"composer\" ] } , \"results\": { \"bindings\": [ { \"composer\": { \"type\": \"uri\" , \"value\": \"https://w3id.org/OWLunit/composer/Puccini\" } } ] } }

FiorelaCiroku commented 2 years ago

To retrieve the ID and the content of the CQ/SQ/ER, we can use the following command:

requirements=$(grep -i '[CQ][0-9][0-9]*:\s' cq.txt)
echo "$requirements" > "requirements.txt"
while read line; do
  echo "${line//[!0-9]/}"
  if [[ $line =~ :(.+) ]]; then
    input=${BASH_REMATCH[1]}
    echo "$input"
  else
    echo "Unable to parse string $line"
  fi
done <requirements.txt
FiorelaCiroku commented 2 years ago

JSON validation: https://github.com/marketplace/actions/validate-json There is already a GitHub action that validates JSON files by using ajv, fast JSON schema validator, to perform the validation. It requires a schema file and a json file to validate.

FiorelaCiroku commented 2 years ago

RDF validation: https://github.com/marketplace/actions/validate-rdf-with-jena Expected results can also be expressed in RDF based on this vocabulary. The validation of the expected results is done using the GitHub action "Validate rdf with Jena".

- uses: vemonet/jena-riot-action@v3.14
  with:
    input: my_file.ttl
FiorelaCiroku commented 2 years ago

For the validation of SPARQL, there is no built action that can fulfil the task. The alternative that I am considering is using the SPARQL Validator. The solution consists on making an HTTP POST request to the website, pasting the parameter that is the SPARQL query that we want to validate and then retrieving the results. Currently, this alternative has not been successful since the response I get from the server is the complete HTML page, without the result of the validation. The reason why it was not successful is because the website doesn't provide an API. Another reason to not try with this alternative it is because we would be dependable on a single website for the validation.

FiorelaCiroku commented 2 years ago

Update: For the validation of the SPARQL query before running the test case, we have developed a python script that can be found here and is based on the rdflib module. The script is able to prepare the query and validate the syntax. The function take the SPARQL query as a parameter. It also comes equipped with PREFIXES.

FIX: Deal with temporary urls as prefixes!