@@ -23,7 +23,7 @@ function print_annotation(Annotation $annotation)
23
23
{
24
24
$ info = $ annotation ->info ();
25
25
if (isset ($ info ['language ' ])) {
26
- print " language: " . $ info ['language ' ] . "\n" ;
26
+ printf ( ' language: %s ' . PHP_EOL , $ info ['language ' ]) ;
27
27
}
28
28
29
29
if (isset ($ info ['documentSentiment ' ])) {
@@ -32,25 +32,35 @@ function print_annotation(Annotation $annotation)
32
32
if ($ polarity < 0 ) {
33
33
$ magnitude = -$ magnitude ;
34
34
}
35
- print " sentiment: " . $ magnitude . "\n" ;
35
+ printf ( ' sentiment: %s ' . PHP_EOL , $ magnitude) ;
36
36
}
37
37
38
38
if (isset ($ info ['sentences ' ])) {
39
- print " sentences: \n" ;
39
+ print ' sentences: ' . PHP_EOL ;
40
40
foreach ($ info ['sentences ' ] as $ sentence ) {
41
- print " " . $ sentence ['text ' ]['beginOffset ' ] . ": " .
42
- $ sentence ['text ' ]['content ' ] . "\n" ;
41
+ printf (' %s: %s ' . PHP_EOL ,
42
+ $ sentence ['text ' ]['beginOffset ' ],
43
+ $ sentence ['text ' ]['content ' ]);
44
+ }
45
+ }
46
+
47
+ if (isset ($ info ['tokens ' ])) {
48
+ print 'tokens: ' . PHP_EOL ;
49
+ foreach ($ info ['tokens ' ] as $ token ) {
50
+ printf (' %s: %s ' . PHP_EOL ,
51
+ $ token ['lemma ' ],
52
+ $ token ['partOfSpeech ' ]['tag ' ]);
43
53
}
44
54
}
45
55
46
56
if (isset ($ info ['entities ' ])) {
47
- print " entities: \n" ;
57
+ print ' entities: ' . PHP_EOL ;
48
58
foreach ($ info ['entities ' ] as $ entity ) {
49
- print " " . $ entity ['name ' ];
59
+ printf ( ' %s ' , $ entity ['name ' ]) ;
50
60
if (isset ($ entity ['metadata ' ]['wikipedia_url ' ])) {
51
- print " : " . $ entity ['metadata ' ]['wikipedia_url ' ];
61
+ printf ( ' : %s ' , $ entity ['metadata ' ]['wikipedia_url ' ]) ;
52
62
}
53
- print "\n" ;
63
+ print PHP_EOL ;
54
64
}
55
65
}
56
66
}
0 commit comments