intuit / fuzzy-matcher

A Java library to determine probability of objects being similar.
Apache License 2.0
226 stars 69 forks source link

Though there is matching result but matcher is not returning. #72

Closed ajtiwari99 closed 5 months ago

ajtiwari99 commented 10 months ago

Hi Manish, I am trying to make use of fuzzy-matcher for which i have written one sample test class.( the code is appended below). I am surprised to know the system is not returning match record. I am not able to figure out what wrong has been done.

could you please help? Amarjeet

// Java code start here package test;

import java.util.ArrayList; import java.util.List; import java.util.Map;

import com.intuit.fuzzymatcher.component.MatchService; import com.intuit.fuzzymatcher.domain.Document; import com.intuit.fuzzymatcher.domain.Element; import com.intuit.fuzzymatcher.domain.ElementType; import com.intuit.fuzzymatcher.domain.Match;

public class SampleTest {

public static void main(String[] args) {
    MatchService matchService = new MatchService();
    SampleTest test = new SampleTest();
    Map<Document, List<Match<Document>>> map;

    List<Document> matchDocument = test.loadList();

    Customer searchCust = new Customer();
    searchCust.setId(1);
    searchCust.setfName("Amarjeet");
    searchCust.setmName("Rampher");
    searchCust.setlName("Tiwari");
    searchCust.setAadhar("123456789012");
    //searchCust.setAddress("25 avenue");
    //searchCust.setPan("asdf345ghb");
    Document searchDocument = new Document.Builder(""+searchCust.getId())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(searchCust.getfName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(searchCust.getmName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(searchCust.getlName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(searchCust.getAadhar()).createElement())
            //.addElement(new Element.Builder().setType(ElementType.TEXT).setValue(searchCust.getPan()).createElement())
            .createDocument();

    List<Document> documentList = new ArrayList<>();
    documentList.add(searchDocument);

    map = matchService.applyMatch(matchDocument, documentList);
    System.out.println("Match : " + map);
    Map<String, List<Match<Document>>> result = matchService.applyMatchByDocId(documentList);    
    System.out.println("Match : " + result);

}

public class MatchServiceFactory {

    private MatchService matchService = new MatchService();

    public MatchService getMatchService() {
        return this.matchService;
   }
}

//Load the list 
public List<Document> loadList() {
    Customer cust = new Customer();
    Customer cust1 = new Customer();
    Customer cust2 = new Customer();
    Customer cust3 = new Customer();
    Customer cust4 = new Customer();
    Customer cust5 = new Customer();
    Customer cust6 = new Customer();
    Customer cust7 = new Customer();
    Customer cust8 = new Customer();
    Customer cust9 = new Customer();
    Customer cust10 = new Customer();
    cust.setId(1);
    cust.setfName("Amarjeet");
    cust.setmName("Rampher");
    cust.setlName("Tiwari");
    cust.setAadhar("123456789012");
    cust.setAddress("137 hopkins ave jersey city");
    cust.setPan("adopt8451z");

    cust1.setId(2);
    cust1.setfName("fname2");
    cust1.setmName("mname2");
    cust1.setlName("lname3");
    cust1.setAadhar("12233434");
    cust1.setAddress("25 avenue2");
    cust1.setPan("asdf345ghb2");

    cust2.setId(3);
    cust2.setfName("fname3");
    cust2.setmName("mname3");
    cust2.setlName("lname3");
    cust2.setAadhar("122334343");
    cust2.setAddress("25 avenue3");
    cust2.setPan("asdf345ghb3");    

    Document searchDocument = new Document.Builder(""+cust.getId())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust.getfName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust.getmName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust.getlName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust.getAadhar()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust.getPan()).createElement())
            .createDocument();

    Document searchDocument1 = new Document.Builder(""+cust1.getId())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust1.getfName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust1.getmName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust1.getlName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust1.getAadhar()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust1.getPan()).createElement())

            .createDocument();

    Document searchDocument2 = new Document.Builder(""+cust2.getId())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust2.getfName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust2.getmName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust2.getlName()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust2.getAadhar()).createElement())
            .addElement(new Element.Builder().setType(ElementType.TEXT).setValue(cust2.getPan()).createElement())
            .createDocument();

    List<Document> documentList = new ArrayList<>();
    documentList.add(searchDocument);
    documentList.add(searchDocument1);
    documentList.add(searchDocument2);
    return documentList;
}

}

class Customer{
    int id;
    String fName;
    String mName;
    String lName;
    String address;
    String pan;
    String aadhar;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getfName() {
        return fName;
    }
    public void setfName(String fName) {
        this.fName = fName;
    }
    public String getmName() {
        return mName;
    }
    public void setmName(String mName) {
        this.mName = mName;
    }
    public String getlName() {
        return lName;
    }
    public void setlName(String lName) {
        this.lName = lName;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getPan() {
        return pan;
    }
    public void setPan(String pan) {
        this.pan = pan;
    }
    public String getAadhar() {
        return aadhar;
    }
    public void setAadhar(String aadhar) {
        this.aadhar = aadhar;
    }
}

// Java code ends here

manishobhatia commented 10 months ago

Hi,

I ran your test, and looks like you are running 2 different API's

Just wanted to make sure you are seeing the same results as I am so we can debug this issue.

manishobhatia commented 10 months ago

For reference, I had to modify your example so I could run it without reference to external objects.

here is what I am running


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.intuit.fuzzymatcher.component.MatchService;
import com.intuit.fuzzymatcher.domain.Document;
import com.intuit.fuzzymatcher.domain.Element;
import com.intuit.fuzzymatcher.domain.ElementType;
import com.intuit.fuzzymatcher.domain.Match;

public class SampleTest {

    public static void main(String[] args) {
        MatchService matchService = new MatchService();
        SampleTest test = new SampleTest();
        Map<Document, List<Match<Document>>> map;

        List<Document> matchDocument = test.loadList();

//        Customer searchCust = new Customer();
//        searchCust.setId(1);
//        searchCust.setfName("Amarjeet");
//        searchCust.setmName("Rampher");
//        searchCust.setlName("Tiwari");
//        searchCust.setAadhar("123456789012");
        //searchCust.setAddress("25 avenue");
        //searchCust.setPan("asdf345ghb");
        Document searchDocument = new Document.Builder(""+1)
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("Amarjeet").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("Rampher").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("Tiwari").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("123456789012").createElement())
                //.addElement(new Element.Builder().setType(ElementType.TEXT).setValue(searchCust.getPan()).createElement())
                .createDocument();

        List<Document> documentList = new ArrayList<>();
        documentList.add(searchDocument);

        map = matchService.applyMatch(matchDocument, documentList);
        System.out.println("Match : " + map);
        Map<String, List<Match<Document>>> result = matchService.applyMatchByDocId(documentList);
        System.out.println("Match : " + result);

    }

    public class MatchServiceFactory {

        private MatchService matchService = new MatchService();

        public MatchService getMatchService() {
            return this.matchService;
        }
    }

    //Load the list
    public List<Document> loadList() {
//        Customer cust = new Customer();
//        Customer cust1 = new Customer();
//        Customer cust2 = new Customer();
//        Customer cust3 = new Customer();
//        Customer cust4 = new Customer();
//        Customer cust5 = new Customer();
//        Customer cust6 = new Customer();
//        Customer cust7 = new Customer();
//        Customer cust8 = new Customer();
//        Customer cust9 = new Customer();
//        Customer cust10 = new Customer();
//        cust.setId(1);
//        cust.setfName("Amarjeet");
//        cust.setmName("Rampher");
//        cust.setlName("Tiwari");
//        cust.setAadhar("123456789012");
//        cust.setAddress("137 hopkins ave jersey city");
//        cust.setPan("adopt8451z");
//
//        cust1.setId(2);
//        cust1.setfName("fname2");
//        cust1.setmName("mname2");
//        cust1.setlName("lname3");
//        cust1.setAadhar("12233434");
//        cust1.setAddress("25 avenue2");
//        cust1.setPan("asdf345ghb2");
//
//        cust2.setId(3);
//        cust2.setfName("fname3");
//        cust2.setmName("mname3");
//        cust2.setlName("lname3");
//        cust2.setAadhar("122334343");
//        cust2.setAddress("25 avenue3");
//        cust2.setPan("asdf345ghb3");

        Document searchDocument = new Document.Builder(""+1)
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("Amarjeet").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("Rampher").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("Tiwari").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("123456789012").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("adopt8451z").createElement())
                .createDocument();

        Document searchDocument1 = new Document.Builder(""+2)
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("fname2").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("mname2").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("lname3").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("12233434").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("asdf345ghb2").createElement())

                .createDocument();

        Document searchDocument2 = new Document.Builder(""+3)
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("fname3").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("mname3").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("lname3").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("122334343").createElement())
                .addElement(new Element.Builder().setType(ElementType.TEXT).setValue("asdf345ghb3").createElement())
                .createDocument();

        List<Document> documentList = new ArrayList<>();
        documentList.add(searchDocument);
        documentList.add(searchDocument1);
        documentList.add(searchDocument2);
        return documentList;
    }
}
manishobhatia commented 5 months ago

closing , please feel free to open, if your issue is not resolved