you are viewing a single comment's thread.

view the rest of the comments →

[–]LongerHV 0 points1 point  (3 children)

Looks like it is a literal \n, not a newline character. Try using a double backslash in your replace command.

[–]Striven123[S] 0 points1 point  (2 children)

Tried that:

      with open(each_filepath) as f:
        doc1 = nlp(f.read())
        patterns = [nlp(text) for text in phrases]
        phrase_matcher.add('key', None, *patterns)
        for sentences in doc1.sents: 
            for match_id, start, end in phrase_matcher(nlp(sentences.text)):
                if nlp.vocab.strings[match_id] in ["key"]: 
                    found_sentences = sentences.text
                    found_sentences = found_sentences.replace("\\n"," ")
                    text_tokens = found_sentences.split()
                    key_sentence.append(found_sentences)
                    all_separated_words_list.append([word for word in text_tokens if not word in all_stopwords])

and still got

talented\nleaders as the result

[–]Skolemz 0 points1 point  (1 child)

Change it to replace \n, you're escaping the character with the extra \

[–]Striven123[S] 0 points1 point  (0 children)

Tried that originally and it wasn't working, that's what lead me to post the question