Results 1 to 15 of 15
  1. #1
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default comparision between two lists

    hi all,
    pls suggest me a logic ..we have a text file which contains list of cities with two or more letter missing in city names..and we have to read this using file reader..and it is to compare with the database which contains table with 2 columns.where one column contains normal city names which is taken as key..and another is standard city names..which is taken as values..we are storing it in hash map..den we have to compare list with the hash map one by one and it should return the proper standard city names..we have done the code for proper input..but we could not do it for input with some letters missing..so please provide some suggestion/code....

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Basically you want to compare two strings, which are one is the correct and the other missing some letters.

    Is there any pattern of missing letters. If not you have to do more works actually. You have to build a pattern to compare those two strings with all possibilities. Compare character by character and if something is missing, you have test it with all 26 characters again.

    I hope it's clear to you.

  3. #3
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    there is no pattern for missing letters.....the city name with missing letters should match more than 50% of proper city name which is there in database...

  4. #4
    jurka is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    yeah if no pattern then you need compare one city with other full list char by char.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    May be if you think in a grate way, you can come across with your won algorithm to do it in easy way.

  6. #6
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Question

    ya we have compared character by character..and we are not geting..i wanted to send you code..but here..can we send code??

  7. #7
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;


    public class MapClass3
    {
    public static void main(String args[])throws IOException
    {
    try
    {
    Connection con;
    Ex obj=new Ex();
    List ll1=new ArrayList();
    ll1=obj.getName();


    // System.out.println(ll1);

    con=S1.getConnection();
    PreparedStatement pst=con.prepareStatement("select * from CITYNAME ");
    ResultSet rs=pst.executeQuery();
    HashMap hm = new HashMap();
    String nc=null;
    String sc=null;
    while(rs.next())
    {
    nc=rs.getString("CITY");
    sc=rs.getString("STDCITY");
    hm.put(nc, sc);
    //System.out.print(nc+" ");
    //System.out.println(sc);
    }
    Set set = hm.keySet();
    int length;
    String temp1=null;
    String temp=null;
    int match=0;
    int notMatch=0;
    char[] chr;
    char[] chr1;
    for (Iterator iterator1 = ll1.iterator();iterator1.hasNext();)
    {
    temp1 = (String) iterator1.next();
    //System.out.println(temp1);
    chr1=temp1.toCharArray();
    System.out.println(chr1);



    for (Iterator iterator = set.iterator(); iterator.hasNext();)
    {
    temp = (String) iterator.next();
    //System.out.println(temp);

    chr = temp.toCharArray();
    // System.out.println(chr);

    if(temp1.length()<temp.length())
    {
    length=temp1.length();

    }
    else
    {
    length=temp.length();

    }

    for(int i=0;i<length;i++)
    {

    boolean equals = (chr[i]==chr1[i]);

    if(equals!=true)
    {

    notMatch++;
    }
    else
    {
    match++;

    }
    }

    if(notMatch<match)
    {
    System.out.println(hm.get(temp1));

    }

    }

    /* if(temp.equals(temp1))
    {

    {
    System.out.println("standard city name:"+hm.get(temp1));

    }
    }*/

    }


    }catch(Exception e)
    {
    ExceptionClass g=new ExceptionClass();
    g.displayException(e);
    }
    }
    }

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    i have sent the code..here we are comparing one by one with the list which is in the database

  10. #10
    skaspersen is offline Member
    Join Date
    Jul 2008
    Posts
    31
    Rep Power
    0

    Default

    You could use a spell checker library, eg Jazzy.

    You would then create a dictionary with only the proper names of the Cities in it from the Database.

    Ask the dictionary for suggestions for each item in the list if it only returns a single result use that as the key to get the value from the Hashmap.

    If this is for an assignment the algorithms you need to look up are Phonetic matching Algorithms and The Levenshtein algorithm

    HTH
    Stephen

  11. #11
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    but it should compared with the given wrong city name right..where it will compare...?can you suggest me some source code

  12. #12
    skaspersen is offline Member
    Join Date
    Jul 2008
    Posts
    31
    Rep Power
    0

    Default

    Java Code:
    SpellDictionary dictionary = new SpellDictionaryHashMap();
    HashMap<String,String> hm = new HashMap<String,String>();
    //TODO add city names to dictionary using dictionary.addWord(String); and to hm
    
    public String getStandardCityName(String improperName){
        List possible = dictionary.getSuggestions(improperName,3);
        if(possible.size()==1){
            return hm.get(possible.get(0));
        }
        return null;
    }

  13. #13
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    thanks 4 the code..we will try it

  14. #14
    jack239 is offline Member
    Join Date
    Jul 2008
    Posts
    35
    Rep Power
    0

    Default

    Suprabha plz let us know if it works or not and if you modify anything to make it work then post the sample code for us.
    New to Java/PHP/Javascript development?
    For free help go to- www.techcubetalk.com

  15. #15
    suprabha is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    we have not tested that code..after testing i will surely send you back.thanks.

Similar Threads

  1. 2 dimensional Lists
    By gapper in forum New To Java
    Replies: 4
    Last Post: 01-20-2008, 10:01 AM
  2. Tudu Lists 2.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 08-10-2007, 05:39 PM
  3. Compare lists
    By JavaNoob in forum New To Java
    Replies: 2
    Last Post: 08-08-2007, 04:11 PM
  4. how to compare 2 vector lists?
    By oregon in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 09:25 PM
  5. Tudu Lists 2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-11-2007, 04:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •