Improve the algorithm of regrouping GumTree results.
This commit is contained in:
@@ -118,25 +118,31 @@ public class HierarchicalRegrouper {
|
|||||||
sortSubActions(actSet);
|
sortSubActions(actSet);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if ((action instanceof Update && !(act instanceof Addition))
|
if (isPossibileSubAction(action, act)) {
|
||||||
|| (action instanceof Delete && act instanceof Delete)
|
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2
|
||||||
|| (action instanceof Insert && (act instanceof Insert))) {
|
addToActionSets(actionSet, parentAct, actSet.getSubActions());
|
||||||
int startPosition = act.getPosition();
|
|
||||||
int length = act.getLength();
|
|
||||||
int startPosition2 = action.getPosition();
|
|
||||||
int length2 = action.getLength();
|
|
||||||
|
|
||||||
if (!(startPosition2 >= startPosition && startPosition + length <= startPosition2 + length2)) {
|
|
||||||
// when act is not the sub-set of action.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startPosition2 + length2
|
|
||||||
addToActionSets(actionSet, parentAct, actSet.getSubActions());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPossibileSubAction(Action parent, Action child) {
|
||||||
|
if ((parent instanceof Update && !(child instanceof Addition))
|
||||||
|
|| (parent instanceof Delete && child instanceof Delete)
|
||||||
|
|| (parent instanceof Insert && (child instanceof Insert))) {
|
||||||
|
int startPosition = child.getPosition();
|
||||||
|
int length = child.getLength();
|
||||||
|
int startPosition2 = parent.getPosition();
|
||||||
|
int length2 = parent.getLength();
|
||||||
|
|
||||||
|
if (!(startPosition2 >= startPosition && startPosition + length <= startPosition2 + length2)) {
|
||||||
|
// when act is not the sub-set of action.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void sortSubActions(HierarchicalActionSet actionSet) {
|
private void sortSubActions(HierarchicalActionSet actionSet) {
|
||||||
ListSorter<HierarchicalActionSet> sorter = new ListSorter<HierarchicalActionSet>(actionSet.getSubActions());
|
ListSorter<HierarchicalActionSet> sorter = new ListSorter<HierarchicalActionSet>(actionSet.getSubActions());
|
||||||
List<HierarchicalActionSet> subActions = sorter.sortAscending();
|
List<HierarchicalActionSet> subActions = sorter.sortAscending();
|
||||||
@@ -160,27 +166,16 @@ public class HierarchicalRegrouper {
|
|||||||
sortSubActions(actionSet);
|
sortSubActions(actionSet);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if ((action instanceof Update && !(act instanceof Addition))
|
if (isPossibileSubAction(action, act)) {
|
||||||
|| (action instanceof Delete && act instanceof Delete)
|
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startP + length2
|
||||||
|| (action instanceof Insert && (act instanceof Insert))) {
|
List<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
|
||||||
int startPosition = act.getPosition();
|
if (subActionSets.size() > 0) {
|
||||||
int length = act.getLength();
|
boolean added = addToAactionSet(act, parentAct, subActionSets);
|
||||||
int startPosition2 = action.getPosition();
|
if (added) {
|
||||||
int length2 = action.getLength();
|
return true;
|
||||||
|
} else {
|
||||||
if (!(startPosition2 >= startPosition && startPosition + length <= startPosition2 + length2)) {
|
continue;
|
||||||
// when act is not the sub-set of action.
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// SubAction range: startPosition2 <= startPosition && startPosition + length <= startP + length2
|
|
||||||
List<HierarchicalActionSet> subActionSets = actionSet.getSubActions();
|
|
||||||
if (subActionSets.size() > 0) {
|
|
||||||
boolean added = addToAactionSet(act, parentAct, subActionSets);
|
|
||||||
if (added) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user