如何识别段落中每个句子的情绪

How to identify sentiment for each sentence of paragraph

import pandas as pd
import numpy as np
df = pd.read_csv("./email1.csv")
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split
from sklearn.svm import LinearSVC
from sklearn.metrics import classification_report
X = df['emails']

tfids = TfidfVectorizer(max_features=10000,ngram_range=(1,2))
X = tfids.fit_transform(X)
y = df['sentiment']
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=0)
clf = LinearSVC()
clf.fit(X_train,y_train)
y_pred = clf.predict(X_test)
print(classification_report(y_test,y_pred))

x = """The patient presents to clinic for initial evaluation of some pain and swelling to the left foot. On the day of injury a metal bar fell directly on the top of his left foot striking above the steel toed area of his boot. He had some pain, swelling and bruising early on but this has gotten better. However, the patient continues to have some soreness on the ball of his foot and points to the seconcbdista: metatarsal region. He states that it feels a little like a stone bruise. He has continued hs regglar duties without problems and is able to wear a regular shoe."""
vec = tfids.transform([x])
a = clf.predict(vec)
if a==0:
    print("Negative communication")
else:
    print("Positive communication")

有什么方法可以识别每个句子的情绪。例如:“He had some pain, swelling and blues early for but this has got better”,这是一个积极的句子。

如果我没理解错的话,您只需将段落按点拆分即可,例如:

for sentence in x.split("."):
    vec = tfids.transform([sentence])
    a = clf.predict(vec)
    print(f'Sentiment analysis for "{sentence}":')
    if a==0:
        print("Negative communication")
    else:
        print("Positive communication")