<commit_before>package services.nlp.dbpediaspotlight;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;

import com.fasterxml.jackson.databind.JsonNode;

import play.libs.Json;

public class DBPediaSpotlightUtil {

	public static JsonNode callDBPediaSpotlight(String input, double confidence){
		Client client = ClientBuilder.newClient();
		String spotlightResult = client.target("http://www.dbpedia-spotlight.com/en/annotate")
        .queryParam("text", input)
        .queryParam("confidence", confidence)
        .request(MediaType.APPLICATION_JSON).get(String.class);
		JsonNode resultNode = Json.parse(spotlightResult);
		client.close();
		return resultNode;
		
	}
}<commit_msg>extended DBPediaSpotlightUtil: no static method anymore but having Client instance and close method, using POST instead of GET for processing bigger texts<commit_after>package services.nlp.dbpediaspotlight;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;

import com.fasterxml.jackson.databind.JsonNode;

import play.libs.Json;

public class DBPediaSpotlightUtil {

	private Client client;
	private static final String URL = "http://www.dbpedia-spotlight.com/en/annotate";
	
	public DBPediaSpotlightUtil() {
		this.client = ClientBuilder.newClient();
	}
	
	
	public static JsonNode callDBPediaSpotlightOnce(String input, double confidence){
		try{
			Client client = ClientBuilder.newClient();
			input = removeSpecialChars(input);
			String spotlightResult = client.target(URL)
	        .queryParam("text", input)
	        .queryParam("confidence", confidence)
	        .request(MediaType.APPLICATION_JSON).get(String.class);
			JsonNode resultNode = Json.parse(spotlightResult);
			client.close();
			return resultNode;

		}catch(Exception e){
			System.err.println("Exception for following input: " +input + "\n" +e);
		}
		return Json.newObject();
	}
	
	public JsonNode callDBPediaSpotlight(String input, double confidence){
		try{
			input = removeSpecialChars(input);
			Form form = new Form();
	        form.param("confidence", String.valueOf(confidence));
	        form.param("text", input);
	        String spotlightResult =  client.target(URL)
	                .request()
	                .accept(MediaType.APPLICATION_JSON)
	                .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED), String.class);
	        JsonNode resultNode = Json.parse(spotlightResult);
	        return resultNode;
		
		}catch(Exception e){
			System.err.println("Exception for following input: " +input + "\n" +e);
		}
		return Json.newObject();
		}
	
	public static String removeSpecialChars(String input){
		String[] specialChars = new String[]{"{", "}", "
", "", ""};
		for (String specialChar : specialChars) {
			input = input.replace(specialChar, "");
		}
		return input;
	}
	

	
	public void close(){
		this.client.close();
	}
}
{'fraction_non_alphanumeric': 0.11936339522546419, 'fraction_numerical': 0.0, 'mean_word_length': 3.986776859504132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485255', 'n_tokens_mistral': 992, 'n_tokens_neox': 879, 'n_words': 192}