Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java main program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kaladevi
java main program
0 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners


how to write a main program for the following code

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

 }

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
java main program
java main program  how to write a main program for the following code public class JaroWinkler { private String compOne; private String compTwo; private String theMatchA = ""; private String theMatchB
write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
Advertisements
main func - Java Beginners
main func  why do we pass array of strings in main function of java?  Hi Friend, It is used to signify that the user may opt to enter parameters to the java program at command line. Thanks
main() syntax - Java Beginners
main() syntax  Hi, I would like to know the complete structure of the main() in jdk1.5 with sample program. Regards, UsmanAli Shaik,   Hi Friend, Structure of Java program: [package declaration
problem with main - Java Beginners
a problem. when i compile it appears this message: java.lang.NoSuchMethodError: main Exception in thread "main" . Should i put a main in another file? And how can..., This is an applet code and applet doesn't have main method therefore compile it and run
Main function.. - Java Beginners
Main function..  Hi Friend.. public static void main(String args[]) What does it mean...public - static - void - main -(String args[]) Can u plz... return the value when it exits main(): This is the entry point for the application
When is java main method called?
When is java main method called?  When is java main method called? Please explain the main method in Java with the help of code.   In a java class, main(..) method is the first method called by java environment when
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java... that the program recquires a main() method in order to be runned - here is the following code... the GUI as it is more reliable and efficent - the current program that i am working
Main topics in java for IT corporate working?
Main topics in java for IT corporate working?  What are the main and most important topics in java should be mastered that are usually incorporated in IT corporate world
How to eliminate error," Could not find the main class: filecopy.FileCopy. Program will exit." ?
class: filecopy.FileCopy. Program will exit. Exception in thread "main" Java...How to eliminate error," Could not find the main class: filecopy.FileCopy. Program will exit." ?  run: java.lang.NoClassDefFoundError: filecopy
main function in java - Java Interview Questions
main function in java  1....why is function main() define as static in java? 2...drawbacks of using rmi
What are the main disadvantages of Java Server Faces 2.0?
What are the main disadvantages of Java Server Faces 2.0?  What are the main disadvantages of Java Server Faces 2.0
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link... in Java Programming Language. These are Java Main Thread and the Child Thread...How to Differenciate Main Thread and Child Thread in Java  hi
main function defnition in class - Java Beginners
and will subsequently invoke all the other methods required by your program. The main method...main function defnition in class  why do we use public infront of a main function   Hi friend, The main method is similar to the main
Listing the Main Attributes in a JAR File Manifest
Listing the Main Attributes in a JAR File Manifest       Jar Manifest: Jar Manifest file is the main... the information syntax with rule and restrictions. Main Attributes in Jar file
how to solve the nullPointer Exception in main - Java Beginners
how to solve the nullPointer Exception in main  New to Java ,pls help me how fix Null pointer Exception in main: two files , split .java another... main(String[] args) { String actualState; String str1 = "s0;input
What is Public static void main
the rules otherwise your program will not run. Signature of main method in java...[]) //this is most classic signature of main method. Remember the varargs version of java will work in java 1.5 or later version only. Main is the entry point of 
exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
!"); } } for example: javac xxx.java-->comping java xxxx:error :exception in thread main... for compilation and execution of java program. Therefore set the path of one java version...exception in thread main java.lang.unsupportedclassversionerror unsupported
Why we should use string args[] in main method in java?
Why we should use string args[] in main method in java?  we use only string in the main method not any other one.. specify the reason... and tell me each and every meaning of public static void main(String args[])...   
Should a main method be compulsorily declared in all java classes?
Should a main method be compulsorily declared in all java classes?  hi, Should a main method be compulsorily declared in all java classes? thanks... in all java classes. Where as the main method we should be defined only if the source
.jar file keeps giving me " could not find the main class". Program will exit.
.jar file keeps giving me " could not find the main class". Program will exit... click on it, it gives me the message" could not find the main class. Program... netbeans's project properties clearly sets testing2.hihi as my Main class and I have
MAin error
MAin error  Error while running hello program in another dir rather in bin. path is already set. java -version jdk1.6.0_24 no error while compilation but @ d tym of runnin error in main class is generated Exception in thread
main method
main method  What is the argument type of a program's main() method
exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
exception in thread main java.lang.unsupportedclassversionerror unsupported.... java -version java version "1.4.2_06" javac -version java version.... Thanks  my code is class xxx { public static void main(String
Accessing non-static members through the main method in Java.
Accessing non-static members through the main method in Java.  ... methods. If it is so, an obvious question arises as to how can the main() method in Java has access to non-static members (variables or methods) even though
java program for
java program for   java program for printing documents,images and cards
 

 

 

DMCA.com