1. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## 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  Reply With Quote

2. ## 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.  Reply With Quote

3. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## 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.  Reply With Quote

4. ## Re: Calculate similarity

Do you have any specific java programming questions?  Reply With Quote

5. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## Re: Calculate similarity

YES ,

How can I calculate the similarity for matrices " in file "  Reply With Quote

6. ## 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?  Reply With Quote

7. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## Re: Calculate similarity

2. Calculate the similarity in the file.
3. Save each similarity in the matrix.  Reply With Quote

8. ## 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.  Reply With Quote

9. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## 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 "  Reply With Quote

10. ## 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?  Reply With Quote

11. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## Re: Calculate similarity

It contains columns and rows of String.
It will be stored in an array of String.  Reply With Quote

12. ## 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.  Reply With Quote

13. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## 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.  Reply With Quote

14. ## 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.  Reply With Quote

15. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## Re: Calculate similarity

Java Code:
```import java.io.*;

public class apples {

public static void main(String[] args) throws FileNotFoundException, IOException {

String[][] fileContents = new String;

String line;

while ((line = br.readLine()) != null)
{
fileContents = 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...  Reply With Quote

16. ## Re: Calculate similarity

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

db  Reply With Quote

17. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## Re: Calculate similarity

so, you are saying if I use the ArrayList<string> would work....!!!!

Java Code:
```
ArrayList<String> fileData = new ArrayList<String>();
try{

String line = "";

}
}catch (Exception e) {
System.out.println("Error");
e.printStackTrace();
}
}
}```  Reply With Quote

18. ## Re: Calculate similarity

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.  Reply With Quote

19. Member Join Date
Feb 2012
Posts
14
Rep Power
0

## Re: Calculate similarity

Java Code:
```public static void main(String[] args) throws Exception {

ArrayList<String> fileData = new ArrayList<String>();
try{

String 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...  Reply With Quote

20. ## Re: Calculate similarity

.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.  Reply With Quote

#### Posting Permissions

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