Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2008, 09:47 AM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
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....
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-18-2008, 09:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-18-2008, 11:19 AM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-18-2008, 11:29 AM
Member
 
Join Date: Jul 2008
Posts: 48
jurka is on a distinguished road
yeah if no pattern then you need compare one city with other full list char by char.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-18-2008, 11:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
May be if you think in a grate way, you can come across with your won algorithm to do it in easy way.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-18-2008, 12:14 PM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
ya we have compared character by character..and we are not geting..i wanted to send you code..but here..can we send code??
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-18-2008, 12:27 PM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
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);
}
}
}
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-18-2008, 12:28 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Sure, send the code you have done upto now. We can look at and give an idea.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-18-2008, 12:29 PM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
i have sent the code..here we are comparing one by one with the list which is in the database
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-18-2008, 03:40 PM
Member
 
Join Date: Jul 2008
Posts: 31
skaspersen is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-21-2008, 08:34 AM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
but it should compared with the given wrong city name right..where it will compare...?can you suggest me some source code
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 07-21-2008, 03:42 PM
Member
 
Join Date: Jul 2008
Posts: 31
skaspersen is on a distinguished road
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; }
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 07-22-2008, 09:37 AM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
thanks 4 the code..we will try it
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 07-29-2008, 09:35 AM
Member
 
Join Date: Jul 2008
Posts: 33
jack239 is on a distinguished road
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-
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 08-01-2008, 04:49 PM
Member
 
Join Date: Jul 2008
Posts: 19
suprabha is on a distinguished road
we have not tested that code..after testing i will surely send you back.thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 dimensional Lists gapper New To Java 4 01-20-2008 11:01 AM
Tudu Lists 2.1 JavaBean Java Announcements 0 08-10-2007 06:39 PM
Compare lists JavaNoob New To Java 2 08-08-2007 05:11 PM
how to compare 2 vector lists? oregon New To Java 2 07-25-2007 10:25 PM
Tudu Lists 2.0 JavaBean Java Announcements 0 07-11-2007 05:32 PM


All times are GMT +3. The time now is 04:24 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org