Results 1 to 11 of 11
  1. #1
    jessie is offline Member
    Join Date
    Nov 2010
    Posts
    29
    Rep Power
    0

    Default pattern matching with two arrays

    hi,

    i have an issue with comparing two array lists. array a1 has the content of a set of 500 articles. array a2 has a set of noun phrases.
    i need to check each element of a2 with each element of a1.
    because i want to check in how many articles does the elements of a2(noun phrases) occur.

    pls help...


    regards
    jessie

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default

    How To Ask Questions The Smart Way

    What is your issue? What have you tried? Where are you stuck? Be specific.

  3. #3
    jessie is offline Member
    Join Date
    Nov 2010
    Posts
    29
    Rep Power
    0

    Default

    hi,

    i can't find a way of counting the number of articles that the noun phrases occur. i have 500 articles in a list. i need this to know the document frequnecy of a noun phrase.. im new to java..pls help..

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by jessie View Post
    hi,

    i can't find a way of counting the number of articles that the noun phrases occur. i have 500 articles in a list. i need this to know the document frequnecy of a noun phrase.. im new to java..pls help..
    The String.indexOf( ... ) method can find a substring in a String (optionally starting the search from a certain position).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    jessie is offline Member
    Join Date
    Nov 2010
    Posts
    29
    Rep Power
    0

    Default

    thanks..but i have a code like this.
    Java Code:
    int counti=0;
                            for (int i=0;i<laststring.size();i++) {
    			for (int j=0;j<content1.size(); j++) {
    				if(content1.get(j).contains(laststring.get(i))){
    
    					//System.out.println("equals..:"+laststring.get(i));
                                    
    
                                    }
                                    
    				}
                            
                              
    			}
    can u tell me how i can get the count of articles in which the noun phrases occur? content1 has the text of articles and laststring has the noun phrases.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default

    How would you do this with just one article text String and one noun phrase?

  7. #7
    jessie is offline Member
    Join Date
    Nov 2010
    Posts
    29
    Rep Power
    0

    Default

    if the noun phrase appears in the article the count would be one, bcos im getting only the article count..

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by KevinWorkman View Post
    How would you do this with just one article text String and one noun phrase?
    What Kevin says; I hate it when someone tries to 'knit' his code together and crafts long lists of code, zigzag-ing all over the pages, containing loops, conditional statements and, oh shudder, legions of boolean flags, only to end up giving an incorrect answer. I don't want to dig through such jungles. Use a lot of small simple, self contained methods instead.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default

    Quote Originally Posted by jessie View Post
    if the noun phrase appears in the article the count would be one, bcos im getting only the article count..
    Huh? I don't think that's what I asked. Forget your assignment for a second.

    Pretend you have one String that contains some text, and another String that contains a word to search for in that text. How would you count the number of times the word appears in the text?

    Write a method that does that, and we'll go from there.

  10. #10
    jessie is offline Member
    Join Date
    Nov 2010
    Posts
    29
    Rep Power
    0

    Default

    Java Code:
    String text= "Unions representing Health Service Executive staff have voiced disappointment at progress made at today's talks on controversial proposals to shed 5,000 jobs at the agency by the end of the year."
    
    String searchtext = "Health"
    int count =0;
    
    if(text.contains(searchtext)){
     count++;
    }
    System.out.println(count);

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,017
    Rep Power
    10

    Default

    What happens if you use "at" as the searchtext? Check out Jos's posts for a helpful hint.

Similar Threads

  1. Replies: 0
    Last Post: 06-29-2010, 09:16 PM
  2. String matching a pattern
    By vividcooper in forum New To Java
    Replies: 7
    Last Post: 01-07-2010, 11:30 PM
  3. Replies: 1
    Last Post: 10-27-2009, 08:33 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
  •