从 excel 中执行文本情感分析和关键短语提取并存储在 Azure Blob 存储中

Perform Text Sentiment analysis and Keyphrase extraction from excel and store in Azure Blob storage

我想对以 excel 格式存储的文本数据执行情感分析和关键短语提取。情绪和提取的关键短语也需要附加到相同的 excel,最后的 excel 需要存储在 Azure blob 存储中。最后这需要做成一个烧瓶应用程序。如果有人可以帮助我,我将不胜感激。提前致谢..

你的问题范围太广了,我写个简单的demo给你。

只需尝试使用以下代码从 .csv 中读取数据并使用情感分析,然后写回 .csv 并上传到 blob,您唯一需要做的就是将代码与您的 flask 应用集成:

from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
from azure.storage import blob
from azure.storage.blob import BlobClient
import pandas as pd

region = ''
key = ''

excelFilePath = "<local file path>/test.csv"

storageConnStr = '<storage conn str>'
containerName = '<container name>'
destBlob = 'test-upload.csv'

csv = pd.read_csv(excelFilePath,'rb')
data =csv['text']
documents = data.array

blob = BlobClient.from_connection_string(storageConnStr,containerName,destBlob)
credential = AzureKeyCredential(key)
text_analytics_client = TextAnalyticsClient(endpoint="https://"+ region +".api.cognitive.microsoft.com/", credential=credential)

response = text_analytics_client.analyze_sentiment(documents, language="en")

sentiments = [res.sentiment for res in response ]
csv.insert(1, "sentiment", sentiments)
csv.to_csv(excelFilePath, index=False)

blob.upload_blob(open(excelFilePath,'rb').read())

结果:

我的.csv:

运行之后:

并且已经上传到存储: