deepika deepi wrote:i want to match only when all the words are there from the 2.txt. if it starts from the middle, It should not match. How to perform that?
Help needed!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
deepika deepi wrote:How to match for the string instead of key words directly that match with the sentence?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
deepika deepi wrote:i want to match only when all the words are there from the 2.txt. if it starts from the middle, It should not match. How to perform that?
Help needed!
That's because your Matcher is not checking for whole words.
Personally, I reckon you're way overthinking this. If I was writing a "word matcher", I wouldn't use regexes at all.
How about this?
1. Read in your text.
2. Break it up into words (see String.split()).
3. Put each of the words into a List - let's call it textWords.
3. Read in your "words to find" and put each word into a List (or Set, depending on how you want to do the match) - let's call that one wordsToFind.
4. For each word in wordsToFind, see if textWords contains that word. If it does, remove it from both Lists.
5. Now check if there are any words left in wordsToFind. If there are, then your match failed. Indeed, your match can fail as soon as it discovers a word that is NOT in textWords.
You could get a lot fancier with it, but right now concentrate on solving the problem.
Winston
Do not wait to strike till the iron is hot; but make it hot by striking....
Manoj Kumar Jain wrote:Whenever you get error of "can not find symbol" check if you have declared the variable which is causing the trouble, or the variable that you are using should be in the scope.
from you code I can see that the "word" is declared inside the for loop, thats why this will not be available outside for loop.
deepika deepi wrote:
I have split the sentence using
i am trying to use that word for matching
But getting an error:
IEinitial.java:438: cannot find symbol
symbol : variable word
location: class IEinitial
Matcher matcher1 = pattern1.matcher(word);