@@ -48,7 +48,7 @@ public class AnalyzeIT {
48
48
@ Test public void analyzeEntities_withEntities_returnsLarryPage () throws Exception {
49
49
// Act
50
50
List <Entity > entities =
51
- analyzeApp .analyzeEntities (
51
+ analyzeApp .analyzeEntitiesText (
52
52
"Larry Page, Google's co-founder, once described the 'perfect search engine' as"
53
53
+ " something that 'understands exactly what you mean and gives you back exactly what"
54
54
+ " you want.' Since he spoke those words Google has grown to offer products beyond"
@@ -58,33 +58,76 @@ public class AnalyzeIT {
58
58
// Assert
59
59
assertThat (got ).named ("entity names" ).contains ("Larry Page" );
60
60
}
61
-
62
- @ Test public void analyzeSentiment_returnPositive () throws Exception {
61
+
62
+ @ Test public void analyzeEntities_withEntitiesFile_containsGod () throws Exception {
63
+ // Act
64
+ List <Entity > entities =
65
+ analyzeApp .analyzeEntitiesFile ("gs://cloud-samples-tests/natural-language/gettysburg.txt" );
66
+ List <String > got = entities .stream ().map (e -> e .getName ()).collect (Collectors .toList ());
67
+
68
+ // Assert
69
+ assertThat (got ).named ("entity names" ).contains ("God" );
70
+ }
71
+
72
+ @ Test public void analyzeSentimentText_returnPositive () throws Exception {
63
73
// Act
64
74
Sentiment sentiment =
65
- analyzeApp .analyzeSentiment (
75
+ analyzeApp .analyzeSentimentText (
66
76
"Tom Cruise is one of the finest actors in hollywood and a great star!" );
67
77
68
78
// Assert
69
79
assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (0.0 );
70
80
assertThat ((double )sentiment .getScore ()).isGreaterThan (0.0 );
71
81
}
72
82
83
+ @ Test public void analyzeSentimentFile_returnPositiveFile () throws Exception {
84
+ // Act
85
+ Sentiment sentiment =
86
+ analyzeApp .analyzeSentimentFile ("gs://cloud-samples-tests/natural-language/"
87
+ + "sentiment/bladerunner-pos.txt" );
88
+
89
+ // Assert
90
+ assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (0.0 );
91
+ assertThat ((double )sentiment .getScore ()).isGreaterThan (0.0 );
92
+ }
93
+
73
94
@ Test public void analyzeSentiment_returnNegative () throws Exception {
74
95
// Act
75
96
Sentiment sentiment =
76
- analyzeApp .analyzeSentiment (
97
+ analyzeApp .analyzeSentimentText (
77
98
"That was the worst performance I've seen in awhile." );
78
99
79
100
// Assert
80
101
assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (0.0 );
81
102
assertThat ((double )sentiment .getScore ()).isLessThan (0.0 );
82
103
}
104
+
105
+ @ Test public void analyzeSentiment_returnNegativeFile () throws Exception {
106
+ // Act
107
+ Sentiment sentiment =
108
+ analyzeApp .analyzeSentimentFile ("gs://cloud-samples-tests/natural-language/"
109
+ + "sentiment/bladerunner-neg.txt" );
110
+
111
+ // Assert
112
+ assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (0.0 );
113
+ assertThat ((double )sentiment .getScore ()).isLessThan (0.0 );
114
+ }
115
+
116
+ @ Test public void analyzeSentiment_returnNeutralFile () throws Exception {
117
+ // Act
118
+ Sentiment sentiment =
119
+ analyzeApp .analyzeSentimentFile ("gs://cloud-samples-tests/natural-language/"
120
+ + "sentiment/bladerunner-neutral.txt" );
121
+
122
+ // Assert
123
+ assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (1.0 );
124
+ assertThat ((double )sentiment .getScore ()).isWithin (0.0 );
125
+ }
83
126
84
127
@ Test public void analyzeSyntax_partOfSpeech () throws Exception {
85
128
// Act
86
129
List <Token > token =
87
- analyzeApp .analyzeSyntax (
130
+ analyzeApp .analyzeSyntaxText (
88
131
"President Obama was elected for the second term" );
89
132
90
133
List <Tag > got = token .stream ().map (e -> e .getPartOfSpeech ().getTag ())
@@ -94,4 +137,20 @@ public class AnalyzeIT {
94
137
assertThat (got ).containsExactly (Tag .NOUN , Tag .NOUN , Tag .VERB ,
95
138
Tag .VERB , Tag .ADP , Tag .DET , Tag .ADJ , Tag .NOUN ).inOrder ();
96
139
}
140
+
141
+ @ Test public void analyzeSyntax_partOfSpeechFile () throws Exception {
142
+ // Act
143
+ List <Token > token =
144
+ analyzeApp .analyzeSyntaxFile ("gs://cloud-samples-tests/natural-language/"
145
+ + "sentiment/bladerunner-neutral.txt" );
146
+
147
+ List <Tag > got = token .stream ().map (e -> e .getPartOfSpeech ().getTag ())
148
+ .collect (Collectors .toList ());
149
+
150
+ // Assert
151
+ assertThat (got ).containsExactly (Tag .PRON , Tag .CONJ , Tag .VERB , Tag .CONJ , Tag .VERB ,
152
+ Tag .DET , Tag .NOUN , Tag .PUNCT , Tag .NOUN , Tag .VERB , Tag .ADJ , Tag .PUNCT , Tag .CONJ ,
153
+ Tag .ADV , Tag .PRON , Tag .VERB , Tag .VERB , Tag .VERB , Tag .ADJ , Tag .PUNCT , Tag .DET ,
154
+ Tag .NOUN , Tag .VERB , Tag .ADV , Tag .ADJ ,Tag .PUNCT ).inOrder ();
155
+ }
97
156
}
0 commit comments