Results 1 to 3 of 3
  1. #1
    kalaramar is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default 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;

    }

    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to write main program?

    Just add a public static void main(String[] args) method to your class and voila.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: how to write main program?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Why can't we write main without String args[]
    By shailender in forum New To Java
    Replies: 6
    Last Post: 06-17-2013, 09:28 AM
  2. Replies: 7
    Last Post: 11-30-2011, 06:58 PM
  3. Write a program..??
    By QSilver in forum New To Java
    Replies: 7
    Last Post: 02-21-2011, 02:20 PM
  4. Trying to write my own program : /
    By jdicerch in forum New To Java
    Replies: 50
    Last Post: 09-26-2010, 01:44 AM
  5. How to write a Main to test this...
    By Zombie_Leg! in forum New To Java
    Replies: 9
    Last Post: 09-27-2008, 02:30 PM

Tags for this Thread

Posting Permissions

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