Я новичок в обработке, и я пытаюсь создать интерактивную инфографику, в которой цвет фона изменяется в зависимости от того, содержит ли последнее последнее сообщение о событии положительные или отрицательные слова. Для положительного твита фон будет желтым, а для отрицательного твита он будет красным.Как изменить цвет фона в обработке, в зависимости от того, имеет ли твит положительное или отрицательное настроение?
У меня есть проект, который показывает последние твиты, в которых упоминается «wembley» (событие) в консоли.
Я придерживаюсь того, как я могу найти положительные и отрицательные слова в тексте, напечатанном в данных консоли.
Чтобы попытаться сделать это, я установить массив строк, чтобы перечислить все положительные и отрицательные слова, которые я хочу, чтобы вызвать изменение цвета фона:
String [] positiveWords = new String[6];
{
positiveWords [0] = "great";
positiveWords [1] = "love";
positiveWords [2] = "amazing";
positiveWords [3] = "fun";
positiveWords [4] = "brilliant";
positiveWords [5] = "good";
}
String [] negativeWords = new String[4];
{
negativeWords [0] = "bad";
negativeWords [1] = "hate";
negativeWords [2] = "terrible";
negativeWords [3] = "boring";
}
Затем я поставил, если заявление в недействительной ничьей()
if (console.log = positiveWords) {
background (0, 100, 100);
}
if (console.log = negativeWords) {
background (255, 0, 0);
}
это возвращает ошибку «ожидающей LPAREN, нашел„консоль“
Я пытался найти ответ с помощью поиска эв где-то в течение нескольких дней, но я в недоумении! Любая помощь будет очень высоко оценена! Большое спасибо.
Полный исходный код здесь:
import com.temboo.core.*;
import com.temboo.Library.Twitter.Search.*;
//string array to identify positive words
String [] positiveWords = new String[6];
{
positiveWords [0] = "great";
positiveWords [1] = "love";
positiveWords [2] = "amazing";
positiveWords [3] = "fun";
positiveWords [4] = "brilliant";
positiveWords [5] = "good";
}
//string array to identify negative words
String [] negativeWords = new String[4];
{
negativeWords [0] = "bad";
negativeWords [1] = "hate";
negativeWords [2] = "terrible";
negativeWords [3] = "boring";
}
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("userName", "appName", "******");
// The name of your Temboo Twitter Profile
String twitterProfile = "Twittersearch1";
// Declare font and text strings
PFont fontTweet, fontInstructions;
String searchText, tweetText, instructionText;
// Create a JSON object to store the search results
JSONObject searchResults;
void setup() {
size(700, 350);
// Set a search term and instructions
searchText = "wembley";
instructionText = "Press any key to load a new tweet about '"+searchText+"'";
// Display initial tweet
runTweetsChoreo(); // Run the Tweets Choreo function
getTweetFromJSON(); // Parse the JSON response
displayText(); // Display the response
}
void draw() {
if (keyPressed) {
runTweetsChoreo(); // Run the Tweets Choreo function
getTweetFromJSON(); // Parse the JSON response
displayText(); // Display the response
}
//if statements to change the background color
if (tweetsResults = positiveWords) {
background (0, 100, 100);
}
if (tweetsResults = negativeWords) {
background (255, 0, 0);
}
}
void runTweetsChoreo() {
// Create the Choreo object using your Temboo session
Tweets tweetsChoreo = new Tweets(session);
// Set Profile
tweetsChoreo.setCredential(twitterProfile);
// Set inputs
tweetsChoreo.setQuery(searchText);
// Run the Choreo and store the results
TweetsResultSet tweetsResults = tweetsChoreo.run();
// Store results in a JSON object
searchResults = parseJSONObject(tweetsResults.getResponse());
}
void getTweetFromJSON() {
JSONArray statuses = searchResults.getJSONArray("statuses"); // Create a JSON array of the Twitter statuses in the object
JSONObject tweet = statuses.getJSONObject(0); // Grab the first tweet and put it in a JSON object
tweetText = tweet.getString("text"); // Pull the tweet text from tweet JSON object
}
void displayText() {
println(tweetText); // Print tweet to console
}
if (console.log = positiveWords) должно быть, если (console.log == positiveWords), поскольку вы выполняете сравнение, а не задание. Но вы можете сделать сравнение журнала таким образом, так или иначе, так что это немой пункт. Но если (tweetsResults = positiveWords) должно быть, если (tweetsResults == positiveWords) по тем же причинам. –
Также, где вы определяете твитыРезультаты?и positiveWords - массив, вы не можете сравнивать его с этим. –