Extracting keyphrases from text document
To extract keyphrases from a text document you must use RESTFull services.
RESTFull
Method description for sending training file | |
---|---|
Method |
POST |
URL |
Take the URL below as a sample. |
Body |
TrainingDocument object.
|
JAVA sample
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import com.google.gson.Gson;
import com.openkm.bean.SummarizationDocument;
import com.openkm.config.Config;
import com.openkm.config.auth.CustomUser;
import com.openkm.util.PrincipalUtils;
import com.openkm.util.RestClient;
InputStream is = null;
try {
is = new FileInputStream("/home/openkm/test/trainingFile.txt");
String content = IOUtils.toString(is, StandardCharsets.UTF_8);
SummarizationDocument sd = new SummarizationDocument();
sd.setBody(content);
sd.setForceToLowerCase(true);
RestClient rc = new RestClient();
Gson gson = new Gson();
String json = gson.toJson(td);
String response = rc.post("http://localhost:8080/keas/rest/summarization/keywords", json, RestClient.FORMAT_JSON);
String[] keywords = new Gson().fromJson(response, String[].class);
for (String keyword : keywords) {
System.out.println("keyword:" + keyword);
}
} finally {
IOUtils.closeQuietly(is);
}