package org.gcube.nlphub.legacy;

import java.util.HashMap;
import java.util.Set;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;


public class NerEntity {
	private int startIndex, endIndex;
	private HashMap<String, String> properties = null;
	
	/**
	 * Class constructor
	 * @param startIndex the start index of the matching annotation 
	 * @param endIndex the end index of the matching annotation
	 */
	public NerEntity(int startIndex, int endIndex) {
		this.startIndex = startIndex;
		this.endIndex = endIndex;
		properties = new HashMap<>();
	}
	
	/**
	 * Add an additional property (property is a couple {name, value})
	 * @param name
	 * @param value
	 */
	public void addProperty(String name, String value) {
		properties.put(name, value);
	}

	/**
	 * Build a proper JsonObject 
	 * @return JsonObject
	 */
	public JsonObject toJson() {
		JsonObject json = new JsonObject();
		
		// build the "indices" array
		JsonArray indices = new JsonArray();
		indices.add(startIndex);
		indices.add(endIndex);
		json.add("indices", indices);
		
		// add additional properties (if any)
		Set<String> names = properties.keySet();
		for(String n : names) {
			json.addProperty(n, properties.get(n));
		}
		
		return json;
	}
	
	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public HashMap<String, String> getProperties() {
		return properties;
	}

	public void setProperties(HashMap<String, String> properties) {
		this.properties = properties;
	}
	
	/*
	public static void main(String[] args) {
		NerEntity ne = new NerEntity(11, 22);
		ne.addProperty("type", "scalar");
		ne.addProperty("unit", "hour");
		System.out.println(ne.toJson().toString());
	}*/
	
}
