0
これでコードが文字列配列内の単語を見つけることができましたが、ユーザー入力から最も肯定的な単語を取得する必要がありますユーザー入力からの最も負の単語です。だから私は恐ろしいゾーンに接続すると、恐ろしい1.25とゾーンが2.66ですので、恐ろしいが最も負の単語であり、ゾーンは最も肯定的な単語ですが、コードがどのように設定されているのですか?正しい単語を最もポジティブに、単語をポストネガティブとして印刷できることを確認してください。したがって、ユーザー入力の平均が印刷されます。私は並列配列をしようとしたが、私はそれらを避けたい。他の問題は、ユーザーがキーctrl zまたはctrl dを使用するまで、複数の入力を取ることができます。 (私は彼らがEclipseの一部であると言われましたが、私はそれらをどのように使用するかわかりません) 進め方についてのご意見ありがとうございます。最大値と最小値をユーザー入力から取り出し、JavaのEclipseで表示しようとしています
出力:
Please type one line of review and when you are done press either Ctr D or Ctr Z
dreadful zone
dreadful zone
The average is negative at 1.9583333333333333
Incomplete assignment
public class MovieReviewSentimentAnalysis {
static Scanner userInput = new Scanner(System.in);
public static void main(String[] args) {
// TODO: complete me
//make own arrays to pass by value
//movieReviewComments = the text
String[] movieReviewComments = new String[8529];
//movieReviewScores = numeric values, avoid lit. values
int[] movieReviewScores = new int[8529];
String userComment = "";
MovieReviewReader.readMovieReviews("movie_reviews.txt", movieReviewComments, movieReviewScores); //string, string array, and int array
System.out.println("Please type one line of review and when you are done press either Ctr D or Ctr Z");
userComment = userInput.nextLine();
System.out.println(userComment);
// String[] words = userComment.split("\\s+");
String[] words2 = userComment.split("[\\W]"); //splits at "\W", or non-word characters
double singularUserWordTotal = 0;
double wordTotal = 0;
double totalSumOfUserCommentWords = 0;
double highestWordScore = 20;
double lowestWordScoreTotal = 0;
int locationOfWordInUserInput = 0;
String userInputWord = "";
// int itemCount = words.length;
for (int i = 0; i < words2.length; i++)
{
userInputWord = words2[i];
singularUserWordTotal = wordCount(userInputWord, movieReviewComments, movieReviewScores);
wordTotal += singularUserWordTotal;
totalSumOfUserCommentWords = wordTotal/words2.length;
// locationOfWordInUserInput = i;
// if(singularUserWordTotal > highestWordScore)
// {
// singularUserWordTotal = highestWordScore;
// }
// if(singularUserWordTotal < highestWordScore)
// {
// singularUserWordTotal = highestWordScore;
// lowestWordScoreTotal = singularUserWordTotal;
// }
}
displayScores(totalSumOfUserCommentWords);
// System.out.println(reviewFile);
System.out.println("Incomplete assignment");
userInput.close();
}
public static double wordCount(String userInputWord, String[] movieReviewComments, int[] movieReviewScores)
{
double storeScore = 0;
double totalSumOfReviewScores = 0;
double numOfTimesWordAppears = 0;
for (int i=0; i < (movieReviewComments.length); i++)
{
if (movieReviewComments[i].contains(userInputWord))
//PUNCTUATION IS A PROBLEM (if it's at the end of the user input then it's fine though)
{
storeScore = movieReviewScores[i];
totalSumOfReviewScores += storeScore;
numOfTimesWordAppears++;
//System.out.println("Found");
//What if the word doesn't appear in the text file?????
}else if (!movieReviewComments[i].contains(userInputWord))
{
numOfTimesWordAppears += 0;
}
// else
// System.out.println("You dun goofed"); //delete after fixing problem
}
double wordScoreAverage = totalSumOfReviewScores/numOfTimesWordAppears;
return wordScoreAverage;
}
public static double displayScores(double userCommentTotal)
{
if(userCommentTotal > 2.01)
{
System.out.println("The average is positive at " + userCommentTotal);
}else if(userCommentTotal < 2.01 && userCommentTotal > 1.99)
{
System.out.println("The average is neutral at " + userCommentTotal);
}else
System.out.println("The average is negative at " + userCommentTotal);
return userCommentTotal;
}
二次元配列を使用してください。配列の最初の列がワードを保持し、配列の2番目の列が数値のワードを保持できるようにします。 – DevilsHnd