method = AbstractMethod("public void METHOD_1 ( ) { }")
method
method.applyEditOperation(InsertOperation(1, "static"))
method
method = AbstractMethod("public static void METHOD_1 ( ) { }")
method
method.applyEditOperation(DeleteOperation(1))
method
method = AbstractMethod("public void METHOD_1 ( ) { }")
method
method.applyEditOperation(ReplaceOperation(0, "private"))
method
Principles of CompoundOperations
Type
Each CompoundOperation
has a type, which is one of the following:
InsertOperation
-- indicates that no tokens are removed and at least one token is addedDeleteOperation
-- indicates that at least one token is removed and no tokens are addedReplaceOperation
-- indicates one of the following:- no tokens are removed or added
- at least one token is removed and at least one token is added
Loose Compatibility
A squence of EditOperations is said to be loosely compatible if, when the operations are applied to an AbstractMethod
directly after one another, the AbstractMethod
is modified in one contiguous section. A CompoundOperation
is loose when it consists of EditOperations that are loosely compatible with one another. Note that the order in which the EditOperations are applied matters. Take the following examples, which both utilize the same EditOperations:
method = AbstractMethod("A B C D")
method.applyEditOperations([
DeleteOperation(1),
DeleteOperation(0)
])
method
The two operations that were applied are loosely compatible because they modified (deleted) a contiguous section of tokens ['A', 'B']
.
method = AbstractMethod("A B C D")
method.applyEditOperations([
DeleteOperation(0),
DeleteOperation(1)
])
method
In this case, even though the same two operations were applied, the operations are not loosely compatible. The first operation deleted the token 'A'
, and the second token deleted the token 'C'
. Since these tokens were not contiguous, the applied operations are not loosely compatible.
Strict compatibility
A sequence of EditOperations is said to be strictly compatible if it is loosely compatible and all the operations are of the same type. A CompoundOperation
is strict when it consists of EditOperations which are strictly compatible with one another.
These operations are strictly compatible:
DeleteOperation(1)
DeleteOperation(1)
These operations are not strictly compatible, even though they are loosely compatible:
DeleteOperation(1)
InsertOperation(1, "foo")
Creating CompoundOperations
CompoundOperations are created from a sequence of EditOperations. The easiest way to do this is by using the utility functions getCondensedBasic
, getCondensedLoose
, and getCondensedStrict
found in the CondenseEditOperations
module. However, you can also create them manually by repeatedly adding EditOperations or by providing a machine string.
Adding EditOperations
Using machine strings
Machine strings are tokenized representations of CompoundOperations used for training a HephaestusModel
.
compoundOp = CompoundOperation(DeleteOperation(2))
compoundOp.addLoose(ReplaceOperation(2, "return"))
compoundOp.addLoose(InsertOperation(3, "VAR_1"))
compoundOp.addLoose(InsertOperation(4, ";"))
compoundOp
generalMachineString = compoundOp.getMachineString("general")
generalMachineString
CompoundOperation.FromMachineString(generalMachineString)
typedMachineString = compoundOp.getMachineString("typed")
typedMachineString
CompoundOperation.FromMachineString(typedMachineString)