Fix bug conflating new items

This commit is contained in:
Antonin Delpeuch 2018-03-19 08:57:40 +00:00
parent 112f3f9308
commit 6e4dfe67af
7 changed files with 22 additions and 14 deletions

View File

@ -108,13 +108,13 @@ public class NewItemLibrary {
} }
Recon recon = cell.recon; Recon recon = cell.recon;
if (Recon.Judgment.New.equals(recon.judgment) && !reset if (Recon.Judgment.New.equals(recon.judgment) && !reset
&& map.containsKey(recon.judgmentHistoryEntry)) { && map.containsKey(recon.id)) {
recon.judgment = Recon.Judgment.Matched; recon.judgment = Recon.Judgment.Matched;
recon.match = new ReconCandidate(map.get(recon.judgmentHistoryEntry), cell.value.toString(), recon.match = new ReconCandidate(map.get(recon.id), cell.value.toString(),
new String[0], 100); new String[0], 100);
impactedColumns.add(i); impactedColumns.add(i);
} else if (Recon.Judgment.Matched.equals(recon.judgment) && reset } else if (Recon.Judgment.Matched.equals(recon.judgment) && reset
&& map.containsKey(recon.judgmentHistoryEntry)) { && map.containsKey(recon.id)) {
recon.judgment = Recon.Judgment.New; recon.judgment = Recon.Judgment.New;
recon.match = null; recon.match = null;
impactedColumns.add(i); impactedColumns.add(i);

View File

@ -94,10 +94,10 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
/** /**
* Returns the integer used internally in OpenRefine to identify the new item. * Returns the integer used internally in OpenRefine to identify the new item.
* *
* @return the judgment history entry id of the reconciled cell * @return the reconciliation id of the reconciled cell
*/ */
public long getReconInternalId() { public long getReconInternalId() {
return getRecon().judgmentHistoryEntry; return getRecon().id;
} }
/** /**

View File

@ -83,6 +83,6 @@ public class NewItemLibraryTest extends RefineTest {
private void isNewTo(long id, Cell cell) { private void isNewTo(long id, Cell cell) {
assertEquals(Recon.Judgment.New, cell.recon.judgment); assertEquals(Recon.Judgment.New, cell.recon.judgment);
assertEquals(id, cell.recon.judgmentHistoryEntry); assertEquals(id, cell.recon.id);
} }
} }

View File

@ -53,8 +53,8 @@ import com.google.refine.tests.RefineTest;
public class QuickStatementsExporterTest extends RefineTest { public class QuickStatementsExporterTest extends RefineTest {
private QuickStatementsExporter exporter = new QuickStatementsExporter(); private QuickStatementsExporter exporter = new QuickStatementsExporter();
private ItemIdValue newIdA = TestingData.makeNewItemIdValue(1234L, "new item A"); private ItemIdValue newIdA = TestingData.newIdA;
private ItemIdValue newIdB = TestingData.makeNewItemIdValue(5678L, "new item B"); private ItemIdValue newIdB = TestingData.newIdB;
private ItemIdValue qid1 = Datamodel.makeWikidataItemIdValue("Q1377"); private ItemIdValue qid1 = Datamodel.makeWikidataItemIdValue("Q1377");
private ItemIdValue qid2 = Datamodel.makeWikidataItemIdValue("Q865528"); private ItemIdValue qid2 = Datamodel.makeWikidataItemIdValue("Q865528");

View File

@ -101,7 +101,7 @@ public class ReconEntityIdValueTest {
// just checking this is symmetrical // just checking this is symmetrical
assertEquals(existingItem, Datamodel.makeWikidataItemIdValue("Q42")); assertEquals(existingItem, Datamodel.makeWikidataItemIdValue("Q42"));
// new cell equality relies on the judgmentHistoryEntry parameter // new item equality relies on the cell's recon id
assertEquals(newItem, sameNewItem); assertEquals(newItem, sameNewItem);
assertNotEquals(newItem, differentNewItem); assertNotEquals(newItem, differentNewItem);
// and on datatype // and on datatype
@ -116,7 +116,7 @@ public class ReconEntityIdValueTest {
@Test @Test
public void testGetRecon() { public void testGetRecon() {
assertEquals(newItem.getReconInternalId(), newItem.getRecon().judgmentHistoryEntry); assertEquals(newItem.getReconInternalId(), newItem.getRecon().id);
} }
@Test @Test

View File

@ -67,9 +67,17 @@ public class TestingData {
public static ItemIdValue existingId = Datamodel.makeWikidataItemIdValue("Q43"); public static ItemIdValue existingId = Datamodel.makeWikidataItemIdValue("Q43");
protected static PropertyIdValue pid = Datamodel.makeWikidataPropertyIdValue("P38"); protected static PropertyIdValue pid = Datamodel.makeWikidataPropertyIdValue("P38");
public static class ReconStub extends Recon {
public ReconStub(long id, long judgmentHistoryEntry) {
super(id, judgmentHistoryEntry);
}
}
public static Recon makeNewItemRecon(long judgementId) { public static Recon makeNewItemRecon(long id) {
Recon recon = Recon.makeWikidataRecon(judgementId); Recon recon = new ReconStub(id, 382398L); // we keep the same judgment id because it is ignored
recon.identifierSpace = "http://www.wikidata.org/entity/";
recon.schemaSpace = "http://www.wikidata.org/prop/direct/";
recon.judgment = Recon.Judgment.New; recon.judgment = Recon.Judgment.New;
return recon; return recon;
} }

View File

@ -42,8 +42,8 @@ public abstract class UpdateSchedulerTest {
protected ItemIdValue existingIdA = Datamodel.makeWikidataItemIdValue("Q43"); protected ItemIdValue existingIdA = Datamodel.makeWikidataItemIdValue("Q43");
protected ItemIdValue existingIdB = Datamodel.makeWikidataItemIdValue("Q538"); protected ItemIdValue existingIdB = Datamodel.makeWikidataItemIdValue("Q538");
protected ItemIdValue newIdA = TestingData.makeNewItemIdValue(1234L, "new item A"); protected ItemIdValue newIdA = TestingData.newIdA;
protected ItemIdValue newIdB = TestingData.makeNewItemIdValue(5678L, "new item B"); protected ItemIdValue newIdB = TestingData.newIdB;
protected Statement sAtoB = TestingData.generateStatement(existingIdA, existingIdB); protected Statement sAtoB = TestingData.generateStatement(existingIdA, existingIdB);
protected Statement sBtoA = TestingData.generateStatement(existingIdB, existingIdA); protected Statement sBtoA = TestingData.generateStatement(existingIdB, existingIdA);