This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // method to loop through results trying to find a number | |
| private int getNumberFromResult(ArrayList<String> results) { | |
| for (String str : results) { | |
| if (getIntNumberFromText(str) != -1) { | |
| return getIntNumberFromText(str); | |
| } | |
| } | |
| return -1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | |
| super.onActivityResult(requestCode, resultCode, data); | |
| if (resultCode == RESULT_OK && data != null) { | |
| switch (requestCode) { | |
| case 10: | |
| case 20: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| firstNumTextView.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); | |
| intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); | |
| intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH); | |
| startActivityForResult(intent, 10); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="com.anas.voicecommandcalculator"> | |
| <uses-permission android:name="android.permission.RECORD_AUDIO" /> | |
| <application | |
| android:allowBackup="true" | |
| android:icon="@mipmap/ic_launcher" | |
| android:label="@string/app_name" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.anas.voicerecognitioncalculator; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.widget.TextView; | |
| public class MainActivity extends AppCompatActivity { | |
| TextView firstNumTextView; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import twitter | |
| # initialize api instance | |
| twitter_api = twitter.Api(consumer_key='YOUR_CONSUMER_KEY', | |
| consumer_secret='YOUR_CONSUMER_SECRET', | |
| access_token_key='YOUR_ACCESS_TOKEN_KEY', | |
| access_token_secret='YOUR_ACCESS_TOKEN_SECRET') | |
| # test authentication | |
| print(twitter_api.VerifyCredentials()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NBResultLabels = [NBayesClassifier.classify(extract_features(tweet[0])) for tweet in preprocessedTestDataSet] | |
| # get the majority vote | |
| if NBResultLabels.count('positive') > NBResultLabels.count('negative'): | |
| print("Overall Positive Sentiment") | |
| print("Positive Sentiment Percentage = " + str(100*NBResultLabels.count('positive')/len(NBResultLabels)) + "%") | |
| else: | |
| print("Overall Negative Sentiment") | |
| print("Negative Sentiment Percentage = " + str(100*NBResultLabels.count('negative')/len(NBResultLabels)) + "%") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NBayesClassifier = nltk.NaiveBayesClassifier.train(trainingFeatures) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| word_features = buildVocabulary(preprocessedTrainingData) | |
| trainingFeatures = nltk.classify.apply_features(extract_features, preprocessedTrainingData) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def extract_features(tweet): | |
| tweet_words = set(tweet) | |
| features = {} | |
| for word in word_features: | |
| features['contains(%s)' % word] = (word in tweet_words) | |
| return features |