对于Cloud Natural Language API的身份验证,我设置了一个指向JSON文件的环境变量。还有其他方法可以执行此操作或对API进行身份验证吗?
到目前为止,我这样称呼API:
public boolean calculateTopics(UpdateWorker updateWorker, String language, List<String> api, List<String> corr, String savePath, boolean feedback) throws InvocationTargetException, IOException, InterruptedException, URISyntaxException, GateException {
Map<String, Object> apis = startAPI(api, textList, language);
}
public Map<String, Object> startAPI(List<String> selectedAPI, List<String> text, String language) throws InvocationTargetException, IOException, InterruptedException, URISyntaxException, GateException {
API apiExtract;
apiExtract = new GoogleAPI(LanguageServiceClient.create());
googleValues = apiExtract.getEntities(text, language);
}
public Map<String, Object> getEntities(List<String> textArray, String language) {
for(String textString : textArray) {
analyze(textString, language);
ent.addAll(entities);
}
public List<Entity> analyze(String text, String textL) throws IOException {
if (textL.equals("english")) {
textLanguage = "en";
} else {
textLanguage = "de";
}
Document doc = Document.newBuilder()
.setLanguage(textLanguage).setContent(text).setType(Type.PLAIN_TEXT).build();
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder()
.setDocument(doc)
.setEncodingType(EncodingType.UTF16).build();
AnalyzeEntitiesResponse response = entityAPI.analyzeEntities(request);
entities = response.getEntitiesList();
return entities;
}