1

我正在尝试为 Duke 创建一个配置和处理器,以在记录列表中找到完全匹配的内容。我创建了一个基于 ExactMatchComparator 的处理器,但该函数不返回完全匹配。这是处理器、配置和侦听器的设置:

public void setup() {
  //setup
  List<Property> exactMatchProperties = new ArrayList<Property>();

  exactListener = new TestUtils.TestListener();

  ExactComparator exactComparator = new ExactComparator();

  //create properties (columns), with name, comparator, and high-low thresholds. ID property has no comparator or propabilities.

  exactMatchProperties.add(new PropertyImpl("ID"));
  exactMatchProperties.add(new PropertyImpl("NAME", exactComparator, 0.0, 1.0));
  exactMatchProperties.add(new PropertyImpl("EMAIL", exactComparator, 0.0, 1.0));

  //create new configuration implementation
  exactMatchConfig = new ConfigurationImpl();

  //add properties to config
  exactMatchConfig.setProperties(exactMatchProperties);
  exactMatchConfig.setThreshold(1.0);
  exactMatchConfig.setMaybeThreshold(0.0);

  //initialize the processor and add match listener
  exactMatchProcessor = new Processor(exactMatchConfig, true);
  exactMatchProcessor.addMatchListener(exactListener);
  }

这是我要测试的功能:

 public void testExactMatch() {
  Collection<Record> records = new ArrayList<Record>();
  Record rec1 = TestUtils.makeRecord(new String[] { "ID", "1", "NAME", "Jon", "EMAIL", "jon@doe.com" });
  Record rec2 = TestUtils.makeRecord(new String[] { "ID", "1", "NAME", "Jon", "EMAIL", "jon@doe.com" });

  records.add(rec1);
  records.add(rec2);

  exactMatchProcessor.deduplicate(records);
  System.out.println(exactListener.getMatches().size());
}

我正在使用 API,并且我已经阅读了此处提到的关于 SO 的问题,但这些问题是指 XML,而我正在使用 Java 进行测试。

getMatches 不应该为空吗?如何获得找到的重复列表或相反的列表(唯一记录列表,没有重复)?谢谢

4

0 回答 0