@Test public void shouldFindDiff_differentRoot_sameLength_differentLastPart_sc2() throws Exception { final ParseResultDifference difference = diffTool.findDifference(ev_in__Pnon, evin__Nom); final RootDifference rootDifference = difference.getRootDifference(); final List<ParseResultPartDifference> parseResultPartDifferences = difference.getParseResultPartDifferences(); assertThat(rootDifference.getRootStrDiff(), equalTo(Pair.of("ev", "evin"))); assertThat(rootDifference.getLemmaRootStrDiff(), equalTo(Pair.of("ev", "evin"))); assertThat(rootDifference.getPosDiff(), nullValue()); assertThat(rootDifference.getSposDiff(), nullValue()); assertThat(parseResultPartDifferences, hasSize(1)); final ParseResultPartDifference parseResultPartDifference = parseResultPartDifferences.get(0); assertThat(parseResultPartDifference.getParts().getLeft().toString(), equalTo("[ParseResultPart{primaryPos='Noun', secondaryPos='null', suffixes=[A3sg, Pnon, Gen]}]")); assertThat(parseResultPartDifference.getParts().getRight().toString(), equalTo("[ParseResultPart{primaryPos='Noun', secondaryPos='null', suffixes=[A3sg, Pnon, Nom]}]")); }
public ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB) { final ParseResult firstParseResult; final ParseResult secondParseResult; if (Comparators.parseResultOrdering.compare(_parseResultA.getStr(), _parseResultB.getStr()) <= 0) { firstParseResult = _parseResultA; secondParseResult = _parseResultB; } else { firstParseResult = _parseResultB; secondParseResult = _parseResultA; } final RootDifference rootDifference = buildRootDifference(firstParseResult, secondParseResult); final DataDiffUtil<ParseResultPart> diffUtil = new DataDiffUtil<ParseResultPart>(); final List<ParseResultPart> firstParseResultParts = CollectionUtils.isEmpty(firstParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : firstParseResult.getParts(); final List<ParseResultPart> secondParseResultParts = CollectionUtils.isEmpty(secondParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : secondParseResult.getParts(); final LinkedList<DataDiffUtil.Diff<ParseResultPart>> diffs = diffUtil.diff_main(firstParseResultParts, secondParseResultParts); diffUtil.diff_cleanupSemantic(diffs); final ParseResultDifference parseResultDifference = new ParseResultDifference(rootDifference); final int diffsLength = diffs.size(); int i = 0; while (i < diffsLength) { final DataDiffUtil.Diff<ParseResultPart> currentDiff = diffs.get(i); final DataDiffUtil.Diff<ParseResultPart> nextDiff = i + 1 >= diffsLength ? null : diffs.get(i + 1); switch (currentDiff.operation) { case EQUAL: { i++; break; } case INSERT: { final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(null, currentDiff.text); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i++; break; } case DELETE: { List<ParseResultPart> secondPart; if (nextDiff != null && nextDiff.operation.equals(DataDiffUtil.Operation.INSERT)) secondPart = nextDiff.text; else secondPart = null; final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(currentDiff.text, secondPart); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i = i + 2; break; } } } return parseResultDifference; }
ParseResultDiffTool { public ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB) { final ParseResult firstParseResult; final ParseResult secondParseResult; if (Comparators.parseResultOrdering.compare(_parseResultA.getStr(), _parseResultB.getStr()) <= 0) { firstParseResult = _parseResultA; secondParseResult = _parseResultB; } else { firstParseResult = _parseResultB; secondParseResult = _parseResultA; } final RootDifference rootDifference = buildRootDifference(firstParseResult, secondParseResult); final DataDiffUtil<ParseResultPart> diffUtil = new DataDiffUtil<ParseResultPart>(); final List<ParseResultPart> firstParseResultParts = CollectionUtils.isEmpty(firstParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : firstParseResult.getParts(); final List<ParseResultPart> secondParseResultParts = CollectionUtils.isEmpty(secondParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : secondParseResult.getParts(); final LinkedList<DataDiffUtil.Diff<ParseResultPart>> diffs = diffUtil.diff_main(firstParseResultParts, secondParseResultParts); diffUtil.diff_cleanupSemantic(diffs); final ParseResultDifference parseResultDifference = new ParseResultDifference(rootDifference); final int diffsLength = diffs.size(); int i = 0; while (i < diffsLength) { final DataDiffUtil.Diff<ParseResultPart> currentDiff = diffs.get(i); final DataDiffUtil.Diff<ParseResultPart> nextDiff = i + 1 >= diffsLength ? null : diffs.get(i + 1); switch (currentDiff.operation) { case EQUAL: { i++; break; } case INSERT: { final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(null, currentDiff.text); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i++; break; } case DELETE: { List<ParseResultPart> secondPart; if (nextDiff != null && nextDiff.operation.equals(DataDiffUtil.Operation.INSERT)) secondPart = nextDiff.text; else secondPart = null; final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(currentDiff.text, secondPart); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i = i + 2; break; } } } return parseResultDifference; } }
ParseResultDiffTool { public ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB) { final ParseResult firstParseResult; final ParseResult secondParseResult; if (Comparators.parseResultOrdering.compare(_parseResultA.getStr(), _parseResultB.getStr()) <= 0) { firstParseResult = _parseResultA; secondParseResult = _parseResultB; } else { firstParseResult = _parseResultB; secondParseResult = _parseResultA; } final RootDifference rootDifference = buildRootDifference(firstParseResult, secondParseResult); final DataDiffUtil<ParseResultPart> diffUtil = new DataDiffUtil<ParseResultPart>(); final List<ParseResultPart> firstParseResultParts = CollectionUtils.isEmpty(firstParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : firstParseResult.getParts(); final List<ParseResultPart> secondParseResultParts = CollectionUtils.isEmpty(secondParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : secondParseResult.getParts(); final LinkedList<DataDiffUtil.Diff<ParseResultPart>> diffs = diffUtil.diff_main(firstParseResultParts, secondParseResultParts); diffUtil.diff_cleanupSemantic(diffs); final ParseResultDifference parseResultDifference = new ParseResultDifference(rootDifference); final int diffsLength = diffs.size(); int i = 0; while (i < diffsLength) { final DataDiffUtil.Diff<ParseResultPart> currentDiff = diffs.get(i); final DataDiffUtil.Diff<ParseResultPart> nextDiff = i + 1 >= diffsLength ? null : diffs.get(i + 1); switch (currentDiff.operation) { case EQUAL: { i++; break; } case INSERT: { final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(null, currentDiff.text); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i++; break; } case DELETE: { List<ParseResultPart> secondPart; if (nextDiff != null && nextDiff.operation.equals(DataDiffUtil.Operation.INSERT)) secondPart = nextDiff.text; else secondPart = null; final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(currentDiff.text, secondPart); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i = i + 2; break; } } } return parseResultDifference; }  }
ParseResultDiffTool { public ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB) { final ParseResult firstParseResult; final ParseResult secondParseResult; if (Comparators.parseResultOrdering.compare(_parseResultA.getStr(), _parseResultB.getStr()) <= 0) { firstParseResult = _parseResultA; secondParseResult = _parseResultB; } else { firstParseResult = _parseResultB; secondParseResult = _parseResultA; } final RootDifference rootDifference = buildRootDifference(firstParseResult, secondParseResult); final DataDiffUtil<ParseResultPart> diffUtil = new DataDiffUtil<ParseResultPart>(); final List<ParseResultPart> firstParseResultParts = CollectionUtils.isEmpty(firstParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : firstParseResult.getParts(); final List<ParseResultPart> secondParseResultParts = CollectionUtils.isEmpty(secondParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : secondParseResult.getParts(); final LinkedList<DataDiffUtil.Diff<ParseResultPart>> diffs = diffUtil.diff_main(firstParseResultParts, secondParseResultParts); diffUtil.diff_cleanupSemantic(diffs); final ParseResultDifference parseResultDifference = new ParseResultDifference(rootDifference); final int diffsLength = diffs.size(); int i = 0; while (i < diffsLength) { final DataDiffUtil.Diff<ParseResultPart> currentDiff = diffs.get(i); final DataDiffUtil.Diff<ParseResultPart> nextDiff = i + 1 >= diffsLength ? null : diffs.get(i + 1); switch (currentDiff.operation) { case EQUAL: { i++; break; } case INSERT: { final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(null, currentDiff.text); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i++; break; } case DELETE: { List<ParseResultPart> secondPart; if (nextDiff != null && nextDiff.operation.equals(DataDiffUtil.Operation.INSERT)) secondPart = nextDiff.text; else secondPart = null; final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(currentDiff.text, secondPart); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i = i + 2; break; } } } return parseResultDifference; }  ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB); }
ParseResultDiffTool { public ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB) { final ParseResult firstParseResult; final ParseResult secondParseResult; if (Comparators.parseResultOrdering.compare(_parseResultA.getStr(), _parseResultB.getStr()) <= 0) { firstParseResult = _parseResultA; secondParseResult = _parseResultB; } else { firstParseResult = _parseResultB; secondParseResult = _parseResultA; } final RootDifference rootDifference = buildRootDifference(firstParseResult, secondParseResult); final DataDiffUtil<ParseResultPart> diffUtil = new DataDiffUtil<ParseResultPart>(); final List<ParseResultPart> firstParseResultParts = CollectionUtils.isEmpty(firstParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : firstParseResult.getParts(); final List<ParseResultPart> secondParseResultParts = CollectionUtils.isEmpty(secondParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : secondParseResult.getParts(); final LinkedList<DataDiffUtil.Diff<ParseResultPart>> diffs = diffUtil.diff_main(firstParseResultParts, secondParseResultParts); diffUtil.diff_cleanupSemantic(diffs); final ParseResultDifference parseResultDifference = new ParseResultDifference(rootDifference); final int diffsLength = diffs.size(); int i = 0; while (i < diffsLength) { final DataDiffUtil.Diff<ParseResultPart> currentDiff = diffs.get(i); final DataDiffUtil.Diff<ParseResultPart> nextDiff = i + 1 >= diffsLength ? null : diffs.get(i + 1); switch (currentDiff.operation) { case EQUAL: { i++; break; } case INSERT: { final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(null, currentDiff.text); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i++; break; } case DELETE: { List<ParseResultPart> secondPart; if (nextDiff != null && nextDiff.operation.equals(DataDiffUtil.Operation.INSERT)) secondPart = nextDiff.text; else secondPart = null; final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(currentDiff.text, secondPart); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i = i + 2; break; } } } return parseResultDifference; }  ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB);  }