C# 使用控制台应用程序进行情绪分析
我面临一个问题。我正在使用Aylian API进行情绪分析。当我运行这段代码时,我将得到一个中性值0.99823C# 使用控制台应用程序进行情绪分析,c#,C#,我面临一个问题。我正在使用Aylian API进行情绪分析。当我运行这段代码时,我将得到一个中性值0.99823 static void Main(string[] args) { Client client = new Client("ID", "Key"); string filename = "tweet.txt"; // Declare the file name string inputString = System.IO.F
static void Main(string[] args)
{
Client client = new Client("ID", "Key");
string filename = "tweet.txt"; // Declare the file name
string inputString = System.IO.File.ReadAllText(filename); // Read all text in File to String.
Sentiment sentiment = client.Sentiment(text: inputString);
Console.WriteLine("The Tweets are : " + sentiment.Polarity + " " + sentiment.PolarityConfidence);
Console.WriteLine(sentiment.Subjectivity + " " + sentiment.SubjectivityConfidence+"\n");
Console.WriteLine("Press ENTER to close...");
Console.ReadLine();
}
但是,当我运行第二个代码从另一个控制台应用程序调用该方法时,它总是显示正1。有人知道为什么吗
var proc = Process.Start(@"C:\\ConsoleApplication1");
proc.WaitForExit();
var exitCode = proc.ExitCode;
您正在从流程中获取退出代码,这通常表示成功/失败,0通常表示流程成功结束,其他任何内容通常表示出现问题,尽管您的应用程序的创建者可能会返回他们想要的任何内容 如果希望从实际应用程序中获取输出,则应通过执行以下操作来读取流程中的标准输出:
var proc = new Process();
proc.StartInfo.FileName = @"C:\\ConsoleApplication1";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.OutputDataReceived += Proc_OutputDataReceived;
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();
private static void Proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}
也许你在读两个不同的tweet.txt文件。我在读同一个txt.txt文件。无论我在其中输入什么文本,结果都将始终为正1。退出代码不是您输出到屏幕的值,您需要读取标准输出以获得您的值。在这种情况下,我如何获得所需的输出?实际结果假定为:(中性0.99997.1)。在实现了你的代码之后,我不断地得到(积极的1主观的1)