I have two vectors containing strings. I want to compare each string of vector1 with each string of vector2 and check how many words are the same in both strings. The code I have only works if the two strings are perfectly similar :
Compare::Compare(vector<string> text1, vector<string> text2, int ratio)
{
text1Size_ = text1.size();
text2Size_ = text2.size();
if(text1Size_ > text2Size_)
{
totalWords_ = text1Size_;
}
else
{
totalWords_ = text2Size_;
}
it = text1.begin();
for(int i = 0; i < text1Size_; i++)
{
it2 = text2.begin();
for(int i = 0; i < text2Size_; i++)
{
if(*it == *it2)
{
cout << "Perfect match";
}
it2++;
}
it++;
}
}
I need to return each similar string if they have at least the ratio of similar words.
Is there a easier way than to parse each string, put each word in an array and compare them?
-EDIT-
By word I mean a written word like "bird". I'll give an example.
Let says I only have one string per vector and I need a 70% ratio of similarities:
string1 : The blue bird.
string2 : The bird.
What I want to do is to check if there is at least 60% of the written words that match in both sentences.
Here I have "The" and "Bird" that match. So I have 2/3 similar words (66.666%). So theses strings will be accepted.
-EDIT 2-
I don't think I can use ".compare()" here since it will check each character and not each written word...