Skip to content

Mutation Operator Specification

Tobias John edited this page May 12, 2025 · 9 revisions

Mutation Operator Specification

Mutation operators describe the way the the RDF graph is modified to generate a mutant graph. In general, the operators describe templates with variables that can match at various places in an RDF graph. We allow to use operators implemented as a Kotlin/Java classes and to use custom operators that are parsed from SWRL rules. In one configuration file, operators from multiple classes and multiple files can be imported.

Kotlin classes as Mutation Operators

Mutation Operators are implemented as Kotlin classes. They can be used by naming the module that contains them and their name in the configuration file. The following is such an example:

mutation_operators:
    - module:
        location: org.smolang.robust.mutant.operators
        operators: 
            - className: AddSubclassRelationMutation
            - className: AddObjectPropertyRelationMutation

The user needs to specify a few elements:

  • The module contains information for all operators from one module. Operators from multiple modules can be imported by providing a list of module elements
  • location: the name of the module
  • operators: the operators that should be used from this module. It contains a list of className elements that specify the names of the mutation operators that should be used.

All mutation operators that RDFMutate provides are contained in the List of Predfeined Mutation Operators.

Instructions on how to implement you own mutation operators are provided in the Developer Documentation.

SWRL Rules as Mutation Operators

We use RDF graphs to provide an input format to read custom mutation operators from files. In particular, we use a custom interpretation of SWRL rules as mutation operators. While the standard interpretation of a SWRL rule is to infer additional assertions in the RDF graph, we interpret a SWRL rule as a change of the RDF graph.

You can find many examples of mutation operators expressed using SWRL rules on the Examples page.

Configuration File

The following snippet from a configuration file demonstrates how to read mutation operators from a file:

mutation_operators:
    - resource:
        file: examples/wiki/allFeatures/addRelation.ttl
        syntax: swrl

The user needs to specify a few elements:

  • resource contains all information about importing operators from a file
  • file is the path of the file
  • syntax specifies the syntax that is used to specify the mutation operator. At the moment, RDFMutate supports only swrl. Instructions on how to add a custom format can be found in the Developer Documentation.

All mutation operators from a file are imported. I.e., if the file contains multiple SWRL rules, multiple operators are imported. The user can specify multiple files to import mutation operators in one configuration file by listing multiple resource elements in the mutation_operators element.

Basic Application

We use the standard syntax for SWRL rules and expect them to be provided as an RDF graph. The rules are of the form (body, head). To apply such a rule, a location in the seed graph is identified, where body matches. As body might contain variables, there could be multiple such locations, in which case one is selected randomly. When the mutation operator is applied, the consequences described by the assertions in its head are performed. In the simplest case, this means that the atoms in the head are added to the KG. To express more complex consequences, we use SWRL’s feature of using custom “built-in” atoms.

The consequences in the head are always with respect to the seed graph before the mutation, i.e. they are applied independently of each other. This is especially relevant, when the consequences are conflicting. E.g. consider the case that a node is deleted in the head AND it is used in some triple that is added in the head. In this case, all (old) triples in the seed graph in which the node occurs are deleted BUT the new triple is also added, i.e. the node occurs at this one place in the mutant graph despite it being deleted. In the case that a triple is added and deleted by the same mutation, the graph is not changed. In general, we advice against using rules that can have such conflicting consequences as it might unforeseen or unintended consequences.

SWRL Extensions

We extend the SWRL format to better use it for mutation operators:

  • we allow arbitrary IRIs to be used as properties in property atoms, whereas the SWRL standard only allows object or data properties. This extension allows the user to target arbitrary triples.
  • we define a few new built-ins to be used as atoms to express more complex selections / consequences (see next section)

Built-Ins

The following are all the built-ins that we allow in RDF rules, their number of arguments and their consequences. Examples for rules that use all these built-ins can be found on the Examples page.

IRI #arguments place semantic
owl:NegativePropertyAssertion 3 body relation is not contained in KG
rdfmutate:newNode 1 body argument (must be a variable) is a new node that will be added to the KG
owl:NegativePropertyAssertion 3 head relation is removed from KG
rdfmutate:deleteNode 1 head all triples containing this node are deleted from KG
rdfmutate:replaceWith 2 head the first node is replaced by the second node in all triples

Restrictions

There are some restrictions on the usage of variables. They are necessary to define a finite set of possible values for them, when the operators are executed.

  • variables that occur in an NegativePropertyAssertion atom in the body of the rule need to occur in at least one other atom, i.e., that is not negated, in the body
  • each variable that occurs in the head of the rule must occur in some atom in the body of the rule

If one of the restrictions is violated, a warning is raised.

Clone this wiki locally