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.

public class SummarizationDocument implements Serializable {
    private static final long serialVersionUID = 1L;

    private String body = "";
    private boolean forceToLowerCase = false;

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public boolean isForceToLowerCase() {
        return forceToLowerCase;
    }

    public void setForceToLowerCase(boolean forceToLowerCase) {
        this.forceToLowerCase = forceToLowerCase;
    }

    @Override
	public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("body=").append(body.length());
        sb.append(",forceToLowerCase=").append(forceToLowerCase);
        sb.append("}");
        return sb.toString();
    }
}

 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);
}