-2

So i have a text file (tagged.txt) full of different sentences. What I am looking to do is read this text file into Java, and extract specific words from this file.

e.g

Sentence : I went to the shop to buy a new pair of trainers

If the sentence has the words shop, buy, or trainers in it, I would like that sentence to equal an opinion.

I have created a list of the words in a text file (words.txt), in which I would like to stream against the tagged.txt file.

I just wanted to know if there is a way of implementing this in Java.

  • Could you please show us what you have already tried? –  Mar 24 '14 at 14:16
  • Check the answer in this link http://stackoverflow.com/questions/5091057/how-to-find-a-whole-word-in-a-string-in-java – Jay Mar 24 '14 at 14:24

1 Answers1

0
  • Read the words from words.txt and store in an array and sort it using Arrays.sort(arr).
  • Read the lines from tagged.txt line by line and store it in a String. Then you could use split() to split the line into different words and store the words in an array.
  • Then loop through the words of the line, and use the array's binarysearch method to search through the words from the words array.
anirudh
  • 4,116
  • 2
  • 20
  • 35
  • Because, only if you sort the words, you can use binary search on the array of words, which is an efficient way to search for words in an array. – anirudh Mar 24 '14 at 14:35