@@ -48,7 +48,7 @@ public class AnalyzeIT {
4848 @ Test public void analyzeEntities_withEntities_returnsLarryPage () throws Exception {
4949 // Act
5050 List <Entity > entities =
51- analyzeApp .analyzeEntities (
51+ analyzeApp .analyzeEntitiesText (
5252 "Larry Page, Google's co-founder, once described the 'perfect search engine' as"
5353 + " something that 'understands exactly what you mean and gives you back exactly what"
5454 + " you want.' Since he spoke those words Google has grown to offer products beyond"
@@ -58,33 +58,76 @@ public class AnalyzeIT {
5858 // Assert
5959 assertThat (got ).named ("entity names" ).contains ("Larry Page" );
6060 }
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 {
6373 // Act
6474 Sentiment sentiment =
65- analyzeApp .analyzeSentiment (
75+ analyzeApp .analyzeSentimentText (
6676 "Tom Cruise is one of the finest actors in hollywood and a great star!" );
6777
6878 // Assert
6979 assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (0.0 );
7080 assertThat ((double )sentiment .getScore ()).isGreaterThan (0.0 );
7181 }
7282
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+
7394 @ Test public void analyzeSentiment_returnNegative () throws Exception {
7495 // Act
7596 Sentiment sentiment =
76- analyzeApp .analyzeSentiment (
97+ analyzeApp .analyzeSentimentText (
7798 "That was the worst performance I've seen in awhile." );
7899
79100 // Assert
80101 assertThat ((double )sentiment .getMagnitude ()).isGreaterThan (0.0 );
81102 assertThat ((double )sentiment .getScore ()).isLessThan (0.0 );
82103 }
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+ }
83126
84127 @ Test public void analyzeSyntax_partOfSpeech () throws Exception {
85128 // Act
86129 List <Token > token =
87- analyzeApp .analyzeSyntax (
130+ analyzeApp .analyzeSyntaxText (
88131 "President Obama was elected for the second term" );
89132
90133 List <Tag > got = token .stream ().map (e -> e .getPartOfSpeech ().getTag ())
@@ -94,4 +137,20 @@ public class AnalyzeIT {
94137 assertThat (got ).containsExactly (Tag .NOUN , Tag .NOUN , Tag .VERB ,
95138 Tag .VERB , Tag .ADP , Tag .DET , Tag .ADJ , Tag .NOUN ).inOrder ();
96139 }
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+ }
97156}
0 commit comments