den*_*nny 5 java nlp maven google-natural-language
我正在尝试使用Google自然语言处理API。我使用Maven添加库并添加GOOGLE_APPLICATION_CREDENTIALS
as环境变量,该环境变量具有包含我的服务帐户密钥的JSON文件的路径。
这给了我一个错误; Could not find TLS ALPN provider; no working netty-tcnative, Conscrypt, or Jetty NPN/ALPN available
try (LanguageServiceClient language = LanguageServiceClient.create()) {
// The text to analyze
String text = "Hello, world!";
Document doc = Document.newBuilder()
.setContent(text).setType(Type.PLAIN_TEXT).build();
// Detects the sentiment of the text
Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();
System.out.printf("Text: %s%n", text);
System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude());
}catch(Exception e){
System.out.println("Gevindu Error "+ e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
小智 0
没有太多数据可以确定正确答案,但就我而言,错误是因为我使用的是 java 版本 1.8,我将编译属性更改为 1.9,错误消失了:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
<optimize>true</optimize>
<debug>true</debug>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
655 次 |
最近记录: |