Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,21 +11,44 @@ nlp = spacy.load("en_core_web_sm")
|
|
11 |
cues = pd.read_excel('link_cues.xlsx')
|
12 |
list_causalmarkers = cues['causal_markers']
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def contains_words_or_phrases(words_list, sentence):
|
15 |
"""
|
16 |
Check if any word or phrase from words_list is present in the sentence.
|
17 |
-
|
18 |
:param words_list: List of words or phrases to check
|
19 |
:param sentence: The input sentence where to look for words or phrases
|
20 |
-
:return:
|
21 |
"""
|
22 |
-
#
|
23 |
-
|
|
|
24 |
|
25 |
-
#
|
26 |
for word_or_phrase in words_list:
|
27 |
-
#
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
return True # Return True immediately if any word or phrase is found
|
30 |
|
31 |
return False # Return False if none of the words or phrases are found
|
|
|
11 |
cues = pd.read_excel('link_cues.xlsx')
|
12 |
list_causalmarkers = cues['causal_markers']
|
13 |
|
14 |
+
# def contains_words_or_phrases(words_list, sentence):
|
15 |
+
# """
|
16 |
+
# Check if any word or phrase from words_list is present in the sentence.
|
17 |
+
|
18 |
+
# :param words_list: List of words or phrases to check
|
19 |
+
# :param sentence: The input sentence where to look for words or phrases
|
20 |
+
# :return: Entities if any word or phrase is found, otherwise None
|
21 |
+
# """
|
22 |
+
# # Normalize the sentence to lower case to make the search case insensitive
|
23 |
+
# normalized_sentence = sentence.lower()
|
24 |
+
|
25 |
+
# # Check each word or phrase in the list
|
26 |
+
# for word_or_phrase in words_list:
|
27 |
+
# # Check if the word or phrase is in the normalized sentence
|
28 |
+
# if word_or_phrase.lower() in normalized_sentence:
|
29 |
+
# return True # Return True immediately if any word or phrase is found
|
30 |
+
|
31 |
+
# return False # Return False if none of the words or phrases are found
|
32 |
+
|
33 |
def contains_words_or_phrases(words_list, sentence):
|
34 |
"""
|
35 |
Check if any word or phrase from words_list is present in the sentence.
|
|
|
36 |
:param words_list: List of words or phrases to check
|
37 |
:param sentence: The input sentence where to look for words or phrases
|
38 |
+
:return: True if any word or phrase is found, otherwise False
|
39 |
"""
|
40 |
+
# Process the sentence with spaCy to obtain the lemmatized form of each token
|
41 |
+
processed_sentence = nlp(sentence.lower())
|
42 |
+
lemmatized_sentence = " ".join(token.lemma_ for token in processed_sentence)
|
43 |
|
44 |
+
# Process each word or phrase for lemmatization
|
45 |
for word_or_phrase in words_list:
|
46 |
+
# Process and create a lemma string for the word or phrase
|
47 |
+
processed_word_or_phrase = nlp(word_or_phrase.lower())
|
48 |
+
lemmatized_word_or_phrase = " ".join(token.lemma_ for token in processed_word_or_phrase)
|
49 |
+
|
50 |
+
# Check if the lemmatized word or phrase is in the lemmatized sentence
|
51 |
+
if lemmatized_word_or_phrase in lemmatized_sentence:
|
52 |
return True # Return True immediately if any word or phrase is found
|
53 |
|
54 |
return False # Return False if none of the words or phrases are found
|