# Calculate similarity

Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 02-18-2012, 12:19 PM
Sultarazi
Calculate similarity
Hello

I have this assignment and I do not ask you to solve it for me. What I only need is to explain it for me because seriously I spent plenty of times to just recognize what does the tasks mean and I could not.

Task 2: Calculate similarity using the following formula:
{█( 0,&ei(command)≠ ej(command)@(2×longest substring ofei(target) and ej(target) )/(lenght of ei(target)+lenght of ej(target)),&otherwise)┤

where e(command) and e(target) represent the command and target of test action e, respectively. For any i and j, s0(i, j) is in the range [0, 1]. s0(i, j)=0 if and only if the two test actions have no common substring in their targets, and s0 (i,j)=1 if and only if they have the same target. For example, s0(i, j)=10/16 =0.625 for test actions ei = “clickAndWait link=abc” and ej = “clickAndWait link=def” because the total length of targets is 16 and the common substring of targets is “link=”.

Task3: Save each similarity between ei and ej in a matrix
>>>>and I have the matrix in my sheet...

Thank you very much
• 02-18-2012, 02:56 PM
Norm
Re: Calculate similarity
When you get the design / algorithm for solving your problem, post it and ask your questions about how to code it in java.
• 02-18-2012, 03:29 PM
Sultarazi
Re: Calculate similarity

{ 2×longest substring of ei(target) and ej(target) / lenght of ei(target) +lenght of ej(target) } otherwise ei(command) ≠ ej(command)

where e(command) and e(target) represent the command and target of test action e, respectively. For any i and j, s0(i, j) is in the range
[0, 1]. s0(i, j)=0 if and only if the two test actions have no common substring in their targets, and s0 (i,j)=1 if and only if they have the
same target. For example, s0(i, j)=10/16 =0.625 for test actions ei = “clickAndWait link=abc” and ej = “clickAndWait link=def” because the total length of targets is 16 and the common substring of targets is “link=”.

this is the formula for the task 2.

• 02-18-2012, 03:48 PM
Norm
Re: Calculate similarity
Do you have any specific java programming questions?
• 02-18-2012, 04:16 PM
Sultarazi
Re: Calculate similarity
YES ,

How can I calculate the similarity for matrices " in file "
• 02-18-2012, 04:19 PM
Norm
Re: Calculate similarity
That is the design that you need to make. There are no java classes or methods to do that.
What are the steps the program should do to solve this?
First thing would be to read the file.
Then what?
• 02-18-2012, 04:23 PM
Sultarazi
Re: Calculate similarity
2. Calculate the similarity in the file.
3. Save each similarity in the matrix.
• 02-18-2012, 04:26 PM
Norm
Re: Calculate similarity
Those are very high level steps. Now break those steps down into a list of much smaller, simpler steps to do the job.
There are no classes will that will do any of those steps.
• 02-18-2012, 04:34 PM
Sultarazi
Re: Calculate similarity
I really confused what to use or what is the specific classes or methods to be honest !! plus I am learning the Java " beginner "
• 02-18-2012, 04:39 PM
Norm
Re: Calculate similarity
After you get a design for the program then you can worry about what classes to use. We can help you there.
Take the first step you listed: Read the file.
What will the file contain?
Where will its contents be stored in the program? Will you define a class to hold the data from each line of the file?
• 02-18-2012, 04:43 PM
Sultarazi
Re: Calculate similarity
It contains columns and rows of String.
It will be stored in an array of String.
• 02-18-2012, 04:49 PM
Norm
Re: Calculate similarity
Look at using the Scanner class to read the file in as Strings. Write a loop to store each String as it is read into an array.
• 02-18-2012, 05:07 PM
Sultarazi
Re: Calculate similarity
ok here is what I got

First of all, I create file then try {hasNextLine()} and catch {} ... and make the String[ ] to store the lines on it.
• 02-18-2012, 06:31 PM
Norm
Re: Calculate similarity
Now write the code and test that it is working as you want.
An easy way to format an array for printing is to use the Arrays class's toString() method.
• 02-19-2012, 09:34 AM
Sultarazi
Re: Calculate similarity
Code:

```import java.io.*; public class apples {         public static void main(String[] args) throws FileNotFoundException, IOException {               String[][] fileContents = new String[4][41];      BufferedReader br = new BufferedReader(new FileReader("/Users/salateno/Desktop/test.txt"));  String line;  while ((line = br.readLine()) != null)  {   fileContents[3][40] = line;     System.out.println("  " +  line );  }     } }```
here is the file now in the String[][] line

is there any advice to make more efficient than this please I would appreciate it to tell me...
• 02-19-2012, 11:31 AM
DarrylBurke
Re: Calculate similarity
Quote:

here is the file now in the String[][] line
Not if you assign every line to fileContents[3][40], it isn't.

db
• 02-19-2012, 12:47 PM
Sultarazi
Re: Calculate similarity
so, you are saying if I use the ArrayList<string> would work....!!!!

Code:

```                 ArrayList<String> fileData = new ArrayList<String>();                 try{                                               BufferedReader fileReader = new BufferedReader(new FileReader("the path"));                         String line = "";                                                 while ( (line = fileReader.readLine()) != null) {                                 fileData.add(line);                         }                 }catch (Exception e) {                         System.out.println("Error");                         e.printStackTrace();                 }         } }```
• 02-19-2012, 02:31 PM
Norm
Re: Calculate similarity
Quote:

the ArrayList<string> would work
After you read the file in and save it in an arraylist, print out the contents of the arraylist to see if it contains the file.
• 02-19-2012, 02:38 PM
Sultarazi
Re: Calculate similarity
Code:

```public static void main(String[] args) throws Exception {       ArrayList<String> fileData = new ArrayList<String>();                 try{                                                 BufferedReader fileReader = new BufferedReader(new FileReader("/Users/salateno/Desktop/test.txt"));                         String line = "";                                                 while ( (line = fileReader.readLine()) != null) {                                 fileData.add(line);                                 System.out.println("" + line);                         }                 }catch (Exception e) {                         System.out.println("Error");                         e.printStackTrace();                 }         } }```

Yes it contains the contents of the file now..But I am wondering now if I can use it to the second task..Also,I was trying to use the split() to make "tap" between each element but it does not work...it gave me java.lang.nullpointer...
• 02-19-2012, 02:39 PM
Norm
Re: Calculate similarity
Quote:

.it gave me java.lang.nullpointer...
Please show the full text of the error message and the code that caused it.
You need to find what variable has the null value and then backtrack in the code to see why that variable does not have a valid value.
Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last