JournalVoter extends AbstractSimilarityVoter { @Override public Vote vote(DocumentProtos.DocumentMetadata doc1, DocumentProtos.DocumentMetadata doc2) { String issn1 = extractIssn(doc1); String issn2 = extractIssn(doc2); if (issn1 != null && !issn1.isEmpty() && issn1.equals(issn2)) { return new Vote(Vote.VoteStatus.PROBABILITY, 1.0f); } String journal1 = extractJournal(doc1); String journal2 = extractJournal(doc2); if (journal1 == null || journal2 == null) { return new Vote(Vote.VoteStatus.ABSTAIN); } journal1 = StringTools.normalize(journal1); journal2 = StringTools.normalize(journal2); SimilarityCalculator calculator = new EditDistanceSimilarity(approveLevel, disapproveLevel); float similarity = calculator.calculateSimilarity(journal1, journal2); if (similarity > 0) { return new Vote(Vote.VoteStatus.PROBABILITY, similarity); } else { return new Vote(Vote.VoteStatus.NOT_EQUALS); } }  @Override Vote vote(DocumentProtos.DocumentMetadata doc1, DocumentProtos.DocumentMetadata doc2); void setDisapproveLevel(float disapproveLevel); void setApproveLevel(float approveLevel);  }
@Test public void testSameJournals() { DocumentProtos.DocumentMetadata doc1 = MockDocumentMetadataFactory.createDocumentMetadata("Ala ma kota", "12341234", "Koko Journal"); DocumentProtos.DocumentMetadata doc2 = MockDocumentMetadataFactory.createDocumentMetadata("Ala ma kota", "", "Koko Journal"); DocumentProtos.DocumentMetadata doc3 = MockDocumentMetadataFactory.createDocumentMetadata("Ala ma kota", "1234-1234", "New Jojko Journal"); DocumentProtos.DocumentMetadata doc4 = MockDocumentMetadataFactory.createDocumentMetadata("Ala ma kota", "", "JamboBambo"); DocumentProtos.DocumentMetadata doc5 = MockDocumentMetadataFactory.createDocumentMetadata("Ala ma kota", "4444-4444", "New Jojko Journal"); vote = journalVoter.vote(doc1, doc2); Assert.assertEquals(vote.getStatus(), Vote.VoteStatus.PROBABILITY); Assert.assertTrue(vote.getProbability() > 0.5); vote = journalVoter.vote(doc1, doc3); Assert.assertEquals(vote.getStatus(), Vote.VoteStatus.PROBABILITY); Assert.assertTrue(vote.getProbability() < 0.5); vote = journalVoter.vote(doc1, doc4); Assert.assertEquals(vote.getStatus(), Vote.VoteStatus.NOT_EQUALS); vote = journalVoter.vote(doc1, doc5); Assert.assertEquals(vote.getStatus(), Vote.VoteStatus.PROBABILITY); Assert.assertTrue(vote.getProbability() < 0.5); vote = journalVoter.vote(doc3, doc5); Assert.assertEquals(vote.getStatus(), Vote.VoteStatus.PROBABILITY); Assert.assertTrue(vote.getProbability() > 0.5); }