Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for "non-matching root node" bug #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions input_xml/w1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a>text</a>
1 change: 1 addition & 0 deletions input_xml/w2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<b>text</b>
29 changes: 15 additions & 14 deletions src/main/java/prioritised_xml_collation/AbstractSegmenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public List<Segment> calculateSegmentation(Score[][] editTable, List<XMLToken> t
Boolean stateChange = lastCell.match != currentCell.match;
if (stateChange) {
System.out.println(lastCell.match + ", " + currentCell.match);
addCelltoSuperwitness(currentCell, tokensA, tokensB, lastX, lastY, superwitness);
addLastCellToSuperwitness(lastCell, tokensA, tokensB, x, y, superwitness);
// System.out.println(String.format("%d %d %d %d", lastX, lastY, x, y));
// change the pointer
lastY = y;
Expand All @@ -31,18 +31,23 @@ public List<Segment> calculateSegmentation(Score[][] editTable, List<XMLToken> t
}
}
// process the final cell in de EditGraphTable (additions/omissions at the beginning of the witnesses
Score currentCell = editTable[0][0];
addCelltoSuperwitness(currentCell, tokensA, tokensB, lastX, lastY, superwitness);
// Score currentCell = editTable[0][0];
addLastCellToSuperwitness(lastCell, tokensA, tokensB, 0, 0, superwitness);
// System.out.println(String.format("%d %d %d %d", lastX, lastY, 0, 0));
return superwitness;
}

private void addCelltoSuperwitness(Score currentCell, List<XMLToken> tokensA, List<XMLToken> tokensB, int lastX, int lastY, List<Segment> superwitness) {
int x = currentCell.x;
int y = currentCell.y;
List<XMLToken> segmentTokensA = tokensA.subList(x, lastX);
List<XMLToken> segmentTokensB = tokensB.subList(y, lastY);
if (currentCell.match == Boolean.TRUE) {
private void addLastCellToSuperwitness(Score lastCell, List<XMLToken> tokensA, List<XMLToken> tokensB, int currentX, int currentY, List<Segment> superwitness) {
int lastX = lastCell.x;
int lastY = lastCell.y;
List<XMLToken> segmentTokensA = tokensA.subList(currentX, lastX);
List<XMLToken> segmentTokensB = tokensB.subList(currentY, lastY);
if (lastCell.match) {
// aligned
Segment segment = new Segment(segmentTokensA, segmentTokensB, Score.Type.aligned);
superwitness.add(0, segment);
}
else {
// if currentCell has tokens of type "match", look at lastcell
// if lastCell is addition/omission/replacement stateChange occured and a new segment can be made
// if cell contains tokens from both witnesses its a replacement
Expand All @@ -64,10 +69,6 @@ else if (segmentTokensB.isEmpty()) {
superwitness.add(0, segment);
}
}
// aligned
else {
Segment segment = new Segment(segmentTokensA, segmentTokensB, Score.Type.aligned);
superwitness.add(0, segment);
}

}
}
Loading