-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
83 lines (67 loc) · 2.75 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.example.vijay.sentimentanalysis_ondevice;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
public class MainActivity extends AppCompatActivity {
TextView sentimentText, sentimentLabel;
ProgressBar prgbar;
Context context;
private SentimentClassifier sentimentClassifier;
Collection<String> sentimentLabels;
String senText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sentimentText = (TextView)findViewById(R.id.sentimentText);
sentimentLabel = (TextView)findViewById(R.id.sentimentLabel);
prgbar = (ProgressBar)findViewById(R.id.progressBar);
prgbar.setVisibility(View.INVISIBLE);
context = this.getApplicationContext();
senText = "Worthless to watch it"; /*Negative*/
// senText = "Worth to watch it"; /*Positive*/
sentimentText.setText(senText);
try {
sentimentClassifier = new SentimentClassifier(context);
} catch (IOException e) {
e.printStackTrace();
}
Runnable runnable = new Runnable() {
@Override
public void run() {
prgbar.setVisibility(View.VISIBLE);
try {
sentimentClassifier.makeParagraphVectors();
prgbar.post(new Runnable() {
@Override
public void run() {
prgbar.setVisibility(View.INVISIBLE);
// try {
// sentimentClassifier.checkUnlabeledData();
// } catch (IOException e) {
// e.printStackTrace();
// }
String text ="";
sentimentLabels = sentimentClassifier.checkUnlabeledData(senText);
Iterator<String> itr = sentimentLabels.iterator();
while(itr.hasNext()){
text += itr.next();
text += "";
}
sentimentLabel.setText(text);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
};
new Thread(runnable).start();
}
}