<commit_before>package org.obd.ws.resources;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.json.JSONException;
import org.json.JSONObject;
import org.nescent.informatics.OBDQuery;
import org.obd.model.Node;
import org.obd.query.Shard;
import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Reference;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.Variant;

public class AutoCompleteResource extends Resource {

	private final String text;
	private String[] options;
	private JSONObject jObjs;
	private Shard obdsql;

	private String nameOption, synonymOption,definitionOption, ontologies;
	
	public AutoCompleteResource(Context context, Request request,
			Response response) {
		super(context, request, response);
		this.obdsql = (Shard)this.getContext().getAttributes().get("shard");
		this.getVariants().add(new Variant(MediaType.APPLICATION_JSON));

        this.text = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("text"));
		if(request.getAttributes().get("name") != null)
			nameOption = Reference.decode((String) request.getAttributes().get("name"));
		if(request.getResourceRef().getQueryAsForm().getFirstValue("syn") != null)
			synonymOption = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("syn"));
		if(request.getResourceRef().getQueryAsForm().getFirstValue("def") != null)
			definitionOption = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("def"));
		if(request.getResourceRef().getQueryAsForm().getFirstValue("ontology") != null)
			ontologies = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("ontology"));
	//	System.out.println(nameOption);
		this.options = new String[]{nameOption, synonymOption, definitionOption, ontologies};
		
		for(Node sourceNode :	obdsql.getSourceNodes()){
			String id = sourceNode.getId();
			
		}


	}

	// this constructor is to be used only for testing purposes
	@Deprecated
	public AutoCompleteResource(Shard obdsql, String text, String... options) {
		this.text = text;
		this.obdsql = obdsql;
		this.options = options;
		this.getVariants().add(new Variant(MediaType.APPLICATION_JSON));
	}

	public Representation getRepresentation(Variant variant) {

		Representation rep = null;
	//	String stringRep = "";

		try {
			this.jObjs = getTextMatches(this.text.toLowerCase(), this.options);
	//		stringRep = this.renderJsonObjectAsString(this.jObjs, 0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {<commit_msg>Rolled back changes because they can be implemented in QueryOBD class<commit_after>package org.obd.ws.resources;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.json.JSONException;
import org.json.JSONObject;
import org.nescent.informatics.OBDQuery;
import org.obd.model.Node;
import org.obd.query.Shard;
import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Reference;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.Variant;

public class AutoCompleteResource extends Resource {

	private final String text;
	private String[] options;
	private JSONObject jObjs;
	private Shard obdsql;

	private String nameOption, synonymOption,definitionOption, ontologies;
	
	public AutoCompleteResource(Context context, Request request,
			Response response) {
		super(context, request, response);
		this.obdsql = (Shard)this.getContext().getAttributes().get("shard");
		this.getVariants().add(new Variant(MediaType.APPLICATION_JSON));

        this.text = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("text"));
		if(request.getAttributes().get("name") != null)
			nameOption = Reference.decode((String) request.getAttributes().get("name"));
		if(request.getResourceRef().getQueryAsForm().getFirstValue("syn") != null)
			synonymOption = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("syn"));
		if(request.getResourceRef().getQueryAsForm().getFirstValue("def") != null)
			definitionOption = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("def"));
		if(request.getResourceRef().getQueryAsForm().getFirstValue("ontology") != null)
			ontologies = Reference.decode((String) request.getResourceRef().getQueryAsForm().getFirstValue("ontology"));
	//	System.out.println(nameOption);
		this.options = new String[]{nameOption, synonymOption, definitionOption, ontologies};

	}

	// this constructor is to be used only for testing purposes
	@Deprecated
	public AutoCompleteResource(Shard obdsql, String text, String... options) {
		this.text = text;
		this.obdsql = obdsql;
		this.options = options;
		this.getVariants().add(new Variant(MediaType.APPLICATION_JSON));
	}

	public Representation getRepresentation(Variant variant) {

		Representation rep = null;
	//	String stringRep = "";

		try {
			this.jObjs = getTextMatches(this.text.toLowerCase(), this.options);
	//		stringRep = this.renderJsonObjectAsString(this.jObjs, 0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
{'fraction_non_alphanumeric': 0.12830494728304948, 'fraction_numerical': 0.00032441200324412003, 'mean_word_length': 5.4700944386149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2007373', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1812, 'n_words': 372}