I am trying to do a keyword search in a sentence with swift.
for example given
keywords = ["black", "bag", "love", "filled"]
Sentence1 = "There is a black bag in a house filled with love"
Sentence2 = "We are in a shop. There is a black bag on the counter"
Sentence3 = " The ocean is beautiful and lovely today"
I want to search each sentence for the all the keywords and return sentences that contains all the keywords and the ones that does not. So output should
Sentence1 : 4 keywords Sentence2 : 3 keywords Sentence3 : none
this is my attempt to solve this
var RawSentences = ["There is a black bag in a house filled with love", "We are in a shop. There is a black bag on the counter", " The ocean is beautiful and lovely today"]
var keywords = ["black", "bag", "love", "filled"]
for item in RawSentences {
var matchkeywords: [String] = []
for kword in keywords{
if item.range(of:kword) != nil {
print("Yes!!!! \(kword) is in \(generatedString)")
matchkeywords.append(kword)
}
}
print("There are \(String(matchkeywords.count)) keyword in \(item)")
}
What is the best way to implement this in swift?