@Test public void testAddOne() { Link link = new Link("1", "2", LinkStatus.ASSERTED, LinkKind.SAME, 1.0); linkdb.assertLink(link); Collection<Link> links = linkdb.getAllLinks(); assertEquals(links.size(), 1); assertTrue(links.contains(link)); links = linkdb.getAllLinksFor("1"); assertEquals(links.size(), 1); assertTrue(links.contains(link)); links = linkdb.getAllLinksFor("2"); assertEquals(links.size(), 1); assertTrue(links.contains(link)); }
/** * Shuts down the controller, releasing all resources. */ public void close() throws IOException { processor.close(); linkdb.close(); }
public void batchDone() { linkdb.commit(); records += last_batch_size; lastRecord = System.currentTimeMillis(); }
@Test public void emptyTest() { assertEquals(linkdb.getAllLinks().size(), 0); assertEquals(linkdb.getAllLinksFor("1").size(), 0); }
public boolean isEmpty() { return golddb.getAllLinks().isEmpty(); }
public void link(String id1, String id2, double confidence) throws IOException { boolean correct = true; // does this provide new information, or do we know it already? Link inferredlink = null; if (linkdb != null) inferredlink = linkdb.inferLink(id1, id2); // record it if (console != null) { if (inferredlink == null) { correct = console.yesorno(); confidence = 1.0; // the user told us, which is as certain as it gets } else { correct = inferredlink.getKind() == LinkKind.SAME; confidence = inferredlink.getConfidence(); } } // note that we also write inferred links, because the test file // listener does not do inference writer.write(id1, id2, correct, confidence); out.flush(); // make sure we preserve the data if (linkdb != null && inferredlink == null) { Link link = new Link(id1, id2, LinkStatus.ASSERTED, correct ? LinkKind.SAME : LinkKind.DIFFERENT, 1.0); linkdb.assertLink(link); } }
@Test public void testOverride2() { Link l1 = new Link("1", "2", LinkStatus.ASSERTED, LinkKind.DIFFERENT, 1.0); linkdb.assertLink(l1); Record r1 = makeRecord("id", "1"); Record r2 = makeRecord("id", "2"); listener.startProcessing(); listener.batchReady(1); listener.matches(r1, r2, 1.0); listener.batchDone(); listener.endProcessing(); Collection<Link> all = linkdb.getAllLinks(); assertEquals(1, all.size()); TestUtils.verifySame(new Link("1", "2", LinkStatus.ASSERTED, LinkKind.DIFFERENT, 1.0), all.iterator().next()); }
Collection<Link> oldlinks = linkdb.getAllLinksFor(getIdentity(current)); linkdb.assertLink(l);
private Link link(String id1, String id2, LinkKind kind) { Link link = new Link(id1, id2, LinkStatus.ASSERTED, kind, 1.0); linkdb.assertLink(link); return link; }
@Test public void testGetAllLinksForEmpty() { assertTrue(linkdb.getAllLinksFor("nonexistentid").isEmpty()); }
public void batchReady(int size) { linkdb.validateConnection(); }
public void endProcessing() { int correctfound = dukedb.getAllLinks().size(); // only correct ones here for (Link link : golddb.getAllLinks()) { if (link.getKind() == LinkKind.SAME) correct++; System.out.println("===== GOLDDB ======================================"); System.out.println(golddb); for (Link link : golddb.getAllLinks()) System.out.println(link); System.out.println(); for (Link link : dukedb.getAllLinks()) System.out.println(link);
public synchronized void matches(Record r1, Record r2, double confidence) { String id1 = getid(r1); String id2 = getid(r2); Link link = golddb.inferLink(id1, id2); if (link == null) { unknown++; // we don't know if this one is right or not if (debug && !showmatches) PrintMatchListener.show(r1, r2, confidence, "\nNOT IN TEST FILE", props, pretty); } else if (link.getKind() == LinkKind.SAME) // no counting now; we do that when we're done dukedb.assertLink(new Link(id1, id2, LinkStatus.INFERRED, LinkKind.SAME, confidence)); else if (link.getKind() == LinkKind.DIFFERENT) { wrongfound++; // we found it, but it's not right if (debug && !showmatches) PrintMatchListener.show(r1, r2, confidence, "\nINCORRECT", props, pretty); } else { unknown++; // we don't know if this one is right or not if (debug && !showmatches) PrintMatchListener.show(r1, r2, confidence, "\nUNKNOWN LINK TYPE", props, pretty); } }
@Test public void testOverride() { Link l1 = new Link("1", "2", LinkStatus.ASSERTED, LinkKind.SAME, 1.0); linkdb.assertLink(l1); Record r1 = makeRecord("id", "1"); Record r2 = makeRecord("id", "2"); listener.startProcessing(); listener.batchReady(1); listener.matches(r1, r2, 1.0); listener.batchDone(); listener.endProcessing(); Collection<Link> all = linkdb.getAllLinks(); assertEquals(1, all.size()); TestUtils.verifySame(new Link("1", "2", LinkStatus.ASSERTED, LinkKind.SAME, 1.0), all.iterator().next()); }
Collection<Link> oldlinks = linkdb.getAllLinksFor(getIdentity(current)); linkdb.assertLink(l);
/** * Loads a test file into an in-memory link database. * @since 1.2 */ public static void loadTestFile(Reader input, LinkDatabase linkdb) throws IOException { CSVReader reader = new CSVReader(input); String[] row = reader.next(); while (row != null) { if (row.length != 4) throw new DukeException("Wrong test file format, row had " + row.length + " values, should be 4"); LinkKind kind = row[0].equals("+") ? LinkKind.SAME : LinkKind.DIFFERENT; String id1 = row[1]; String id2 = row[2]; if (id1.compareTo(id2) < 0) { String tmp = id1; id1 = id2; id2 = tmp; } double conf = Double.valueOf(row[3]); linkdb.assertLink(new Link(id1, id2, LinkStatus.ASSERTED, kind, conf)); row = reader.next(); } reader.close(); }
public synchronized void noMatchFor(Record r) { // we missed all of the correct links for this record (if any). // count, and tell the user. for (Link link : golddb.getAllLinksFor(getid(r))) { if (link.getKind() != LinkKind.SAME) continue; // it's a bad link, so never mind missed++; Record r1 = database.findRecordById(link.getID1()); Record r2 = database.findRecordById(link.getID2()); if (r1 != null && r2 != null) { if (debug && !showmatches) PrintMatchListener.show(r1, r2, processor.compare(r1, r2), "\nNOT FOUND", props, pretty); } else if (debug && !showmatches) { System.out.println("\nIDENTITIES IN TEST FILE NOT FOUND IN DATA"); System.out.println("ID1: " + link.getID1() + " -> " + r1); System.out.println("ID2: " + link.getID2() + " -> " + r2); } } }
public void batchReady(int size) { linkdb.validateConnection(); }
@Test public void testAddIdempotent() { Link link = new Link("1", "2", LinkStatus.ASSERTED, LinkKind.SAME, 1.0); linkdb.assertLink(link); link = new Link("2", "1", LinkStatus.ASSERTED, LinkKind.SAME, 1.0); linkdb.assertLink(link); Collection<Link> links = linkdb.getAllLinks(); assertEquals(links.size(), 1); assertTrue(links.contains(link)); links = linkdb.getAllLinksFor("1"); assertEquals(links.size(), 1); assertTrue(links.contains(link)); links = linkdb.getAllLinksFor("2"); assertEquals(links.size(), 1); assertTrue(links.contains(link)); }