Document Conversion のおかげで、PDF から変換された HTML ドキュメントで Concept Insights を使用するためのクラスを作成したいと考えています。Git ディレクトリを表示する Eclipse IDE を使用しています。実行すると、応答がありません。きれいに保ちたいのですが、各メソッドが必要な情報を確実に取得できるようにします。とにかく、ここまでのコードです。
package example.servlet;
package com.ibm.watson.developer_cloud.document_conversion.v1;
package com.ibm.watson.developer_cloud.concept_insights.v1;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.watson.developer_cloud.document_conversion.v1.model.Answers;
import com.ibm.watson.developer_cloud.util.CredentialUtils;
/**
* Servlet implementation class SimpleServlet
*/
@WebServlet("/SimpleServlet")
public class SimpleServlet extends HttpServlet {
ConceptInsights service = new ConceptInsights();
DocumentConversion docService = new DocumentConversion(DocumentConversion.VERSION_DATE_2015_12_01);
service.setUsernameAndPassword("username", "password");
Accounts my_accounts = service.getAccountsInfo();
System.out.println(my_accounts);
String my_account_id = my_accounts.getAccounts().get(0).getId();
System.out.println("My account ID: "+ my_account_id);
docService.setUsernameAndPassword("docUsername", "docPassword");
@Override
public void init() throws ServletException {
super.init();
String vcap = System.getProperty("VCAP_SERVICES");
if (vcap == null){
try {
vcap = FileUtils.readFileToString(new File("vcap.txt"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.getWriter().print("Hello World!");
}
}
public void transformDocs(File[] availableDocs){
/* Files.walk(Paths.get("/home/you/Desktop")).forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
Document test = new Document(my_corpus, filePath);
test.setLabel("Test: "+filePath);
}
});
File folder = new File("/Users/you/folder/");
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
if (file.isFile()) {
Document test = new Document(my_corpus, filePath);
test.setLabel("Test: "+filePath);
}
}*/
}
}
public void fixTheInput(){
CredentialUtils.setServices(vcap);
File doc = new File("docs/cpc-scheme-A.pdf");
Answers pdfToHTML = service.convertDocumentToHTML(doc);
System.out.println(pdfToHTML);
Corpus patents1 = new Corpus("evelandments", "PatentsCorpus");
Corpus patents2 = new Corpus("perdermy1ipres6", "patents");
Map<String, Object> params = new HashMap<String, Object>();
params.put(ConceptInsights.LIMIT, 3);
Concepts concepts1 = service.getCorpusRelatedConcepts(patents1, params);
Concepts concepts2 = service.getCorpusRelatedConcepts(patents2, params);
System.out.println(concepts1);
System.out.println(concepts2);
}
public void createTheCorpus(){
Corpus my_corpus = new Corpus(service.getAccountsInfo().getAccounts().get(0).getId(), "CPCScheme");
// add corpus metadata
AccountPermission permission = new AccountPermission();
permission.setAccountId("account_id");
permission.setPermission("ReadWriteAdmin");
List<AccountPermission> accountPermissions = new ArrayList<AccountPermission>();
accountPermissions.add(permission);
my_corpus.setAccountPermissions(accountPermissions);
//
service.createCorpus(my_corpus);
System.out.println("Created corpus: "+ my_corpus.getName());
Document test = new Document(my_corpus, "test.html");
test.setLabel("Test: my first document");
}
}