Results 1 to 3 of 3
Thread: how to write main program?
- 07-28-2012, 01:22 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 2
- Rep Power
- 0
how to write main program?
ublic class JaroWinkler
{
private String compOne;
private String compTwo;
private String theMatchA = "";
private String theMatchB = "";
private int mRange = -1;
public JaroWinkler()
{
}
public JaroWinkler(String s1, String s2)
{
compOne = s1;
compTwo = s2;
}
public double getSimilarity(String s1, String s2)
{
compOne = s1;
compTwo = s2;
mRange = Math.max(compOne.length(), compTwo.length()) / 2 - 1;
double res = -1;
int m = getMatch();
int t = 0;
if (getMissMatch(compTwo,compOne) > 0)
{
t = (getMissMatch(compOne,compTwo) / getMissMatch(compTwo,compOne));
}
int l1 = compOne.length();
int l2 = compTwo.length();
double f = 0.3333;
double mt = (double)(m-t)/m;
double jw = f * ((double)m/l1+(double)m/l2+(double)mt);
res = jw + getCommonPrefix(compOne,compTwo) * (0.1*(1.0 - jw));
return res;
}
private int getMatch()
{
theMatchA = "";
theMatchB = "";
int matches = 0;
for (int i = 0; i < compOne.length(); i++)
{
//Look backward
int counter = 0;
while(counter <= mRange && i >= 0 && counter <= i)
{
{
matches++;
theMatchA = theMatchA + compOne.charAt(i);
theMatchB = theMatchB + compTwo.charAt(i);
}
counter++;
}
//Look forward
counter = 1;
while(counter <= mRange && i < compTwo.length() && counter + i < compTwo.length())
{
if (compOne.charAt(i) == compTwo.charAt(i + counter))
{
matches++;
theMatchA = theMatchA + compOne.charAt(i);
theMatchB = theMatchB + compTwo.charAt(i);
}
counter++;
}
}
return matches;
}
private int getMissMatch(String s1, String s2)
{
int transPositions = 0;
for (int i = 0; i < theMatchA.length(); i++)
{
//Look Backward
int counter = 0;
while(counter <= mRange && i >= 0 && counter <= i)
{
if (theMatchA.charAt(i) == theMatchB.charAt(i - counter) && counter > 0)
{
transPositions++;
}
counter++;
}
//Look forward
counter = 1;
while(counter <= mRange && i < theMatchB.length() && (counter + i) < theMatchB.length())
{
if (theMatchA.charAt(i) == theMatchB.charAt(i + counter) && counter > 0)
{
transPositions++;
}
counter++;
}
}
return transPositions;
}
private int getCommonPrefix(String compOne, String compTwo)
{
int cp = 0;
for (int i = 0; i < 4; i++)
{
if (compOne.charAt(i) == compTwo.charAt(i)) cp++;
}
return cp;
}
}
- 07-28-2012, 01:53 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: how to write main program?
Just add a public static void main(String[] args) method to your class and voila.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-28-2012, 05:14 PM #3
Re: how to write main program?
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Need a Help to write a program like write a word for the given number
By manideep.d132 in forum New To JavaReplies: 7Last Post: 11-30-2011, 06:58 PM -
Write a program..??
By QSilver in forum New To JavaReplies: 7Last Post: 02-21-2011, 02:20 PM -
Trying to write my own program : /
By jdicerch in forum New To JavaReplies: 50Last Post: 09-26-2010, 01:44 AM -
Why can't we write main without String args[]
By shailender in forum New To JavaReplies: 4Last Post: 11-05-2008, 10:58 AM -
How to write a Main to test this...
By Zombie_Leg! in forum New To JavaReplies: 9Last Post: 09-27-2008, 02:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks