memScore Java™ example

Example code explores the capabilities of memScore.

// Create a member rowlist to hold input member rows
MemRowList inpRowList = new MemRowList();

// MemHead models the database table mpi_memhead.
MemHead  memHead = new MemHead(0);

// Set the identifiers of the member to be scored
MemDate memDate = new MemDate(memHead);
memDate.setAttrCode("BIRTHDT");
memDate.setDateVal("1989-09-30");

MemAttr memSex = new MemAttr(memHead);
memSex.setAttrCode("SEX");
memSex.setAttrVal("M");

MemName memName = new MemName(memHead);
memName.setAttrCode("LGLNAME");
memName.setOnmFirst("Michael");
memName.setOnmLast("de Test");

// Add member info into MemRowList.
inpRowList.addRow(memHead);
inpRowList.addRow(memDate);
inpRowList.addRow(memSex);
inpRowList.addRow(memName);

// MemHead for the second member to score.
MemHead  memHead2 = new MemHead(0);

// Set the identifiers of the member to be scored
MemDate memDate2 = new MemDate(memHead2);
memDate2.setAttrCode("BIRTHDT");
memDate2.setDateVal("1998-09-30"); //transpose the 8 and 9

MemAttr memSex2 = new MemAttr(memHead2);
memSex2.setAttrCode("SEX");
memSex2.setAttrVal("M");

MemName memName2 = new MemName(memHead2);
memName2.setAttrCode("LGLNAME");
memName2.setOnmFirst("Michael");
memName2.setOnmLast("de Test");

// Add member info into MemRowList.
inpRowList.addRow(memHead2);
inpRowList.addRow(memDate2);
inpRowList.addRow(memSex2);
inpRowList.addRow(memName2);

// MemHead for the third member to score.
MemHead memHead3 = new MemHead(0);

// Set the identifiers of the member to be scored
MemDate memDate3 = new MemDate(memHead3);
memDate3.setAttrCode("BIRTHDT");
memDate3.setDateVal("1989-09-30");

MemAttr memSex3 = new MemAttr(memHead3);
memSex3.setAttrCode("SEX");
memSex3.setAttrVal("M");

MemName memName3 = new MemName(memHead3);
memName3.setAttrCode("LGLNAME");
memName3.setOnmFirst("Michael");
memName3.setOnmLast("de Test");

// Add member info into MemRowList.
inpRowList.addRow(memHead3);
inpRowList.addRow(memDate3);
inpRowList.addRow(memSex3);
inpRowList.addRow(memName3);

logRowList(inpRowList);

// Create output Row List
MemRowList outRowList = new MemRowList();

// Create MemScore interaction object
IxnMemScore ixnMemScore = new IxnMemScore(ctx);
ixnMemScore.setEntType("id");

// Execute the scoring
if (!ixnMemScore.execute(inpRowList, outRowList))
{
   err("Unable to score Members - " + ixnMemScore.getErrCode() + ": " + 
ixnMemScore.getErrText());
}

// Extract the scores
assertEquals(outRowList.size(), 3);
      
short lastScore = -1;
RowIterator rowIter = outRowList.rows();

while (rowIter.hasMoreRows())
{
   MemRow memRow = (MemRow) rowIter.nextRow();
   assertTrue(memRow instanceof MemHead);
   MemHead memHead4 = (MemHead) memRow;
   assertTrue(memHead4.getMatchScore() > lastScore);
   lastScore = memHead4.getMatchScore();
}