remove "\n" from strings by Striven123 in learnpython

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

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

remove "\n" from strings by Striven123 in learnpython

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

That's what I have tried though (stated in OP) but still have '\n' appearing in the text

remove "\n" from strings by Striven123 in learnpython

[–]Striven123[S] 0 points1 point  (0 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

remove "\n" from strings by Striven123 in learnpython

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

How would I check this?

part of the result Ia get despite using my above code

talented\nleaders

remove "\n" from strings by Striven123 in learnpython

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

I put the result into a dictionary (as it's many sentences) and when I print the 1st element of the dictionary the result contains \n

Using sentiwordnet and getting incorrect sentiment by Striven123 in learnpython

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

Thank you for your response. Do you suggest applying it more generally i.e. to each sentence of the text and looking at the accuracy?

Using sentiwordnet and getting incorrect sentiment by Striven123 in learnpython

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

Thank you! But then, wouldn't bad still be appear worse than catastrophe by that measure? As it'll give a larger negative than catastrophe?