Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

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

    here are the tasks:

    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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  3. #3
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

    for task 2:

    { 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.

    I really do not know what to do with that....and task1 asks about to (read file).

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: Calculate similarity

    Do you have any specific java programming questions?

  5. #5
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

    YES ,

    How can I calculate the similarity for matrices " in file "

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  7. #7
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

    1. Read the file.
    2. Calculate the similarity in the file.
    3. Save each similarity in the matrix.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  9. #9
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

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

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  11. #11
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

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

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  13. #13
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

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

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  15. #15
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

    Java 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...

  16. #16
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Calculate similarity

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

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

  17. #17
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

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

    Java 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();
                    }
            }
    }

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

  19. #19
    Sultarazi is offline Member
    Join Date
    Feb 2012
    Posts
    14
    Rep Power
    0

    Default Re: Calculate similarity

    Java 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...

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

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

Page 1 of 2 12 LastLast

Similar Threads

  1. find perceptual similarity between two images
    By soheilz92 in forum Advanced Java
    Replies: 2
    Last Post: 09-13-2011, 11:14 PM
  2. cosine similarity in search engine
    By panny in forum New To Java
    Replies: 4
    Last Post: 03-21-2011, 03:03 PM
  3. Replies: 0
    Last Post: 03-01-2011, 01:48 PM
  4. is Cosine Similarity the Default Similarity in Lucene?
    By sethu.iit@gmail.com in forum Lucene
    Replies: 0
    Last Post: 06-30-2010, 10:49 AM
  5. Similarity
    By John Atsh in forum Lucene
    Replies: 0
    Last Post: 03-23-2009, 02:44 PM

Posting Permissions

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