<commit_before>package chesterfield;

import com.google.gson.JsonObject;

import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;

/**
 * Represents a Couchdb database which can be used to update documents
 */
public class Database
{
    private static final String DOC_COUNT = "doc_count";

    private final String name;
    private final Session session;

    public Database(String name, Session session)
    {
        this.name = name;
        this.session = session;
    }

    /**
     * Get the name of the database
     * @return database
     */
    public String getName()
    {
        return name;
    }

    /**
     * Get the session used to create this {@link chesterfield.Database} instance
     * @return session
     */
    public Session getSession()
    {
        return session;
    }

    /**
     * Get the Database Url
     * @return dbUrl
     */
    String getDbUrl()
    {
        try
        {
            return session.getBaseUrl() + URLEncoder.encode(name, "UTF-8") + "/";
        }
        catch (UnsupportedEncodingException e)
        {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    /**
     * Get the total number of documents in the database
     * @return count
     */
    public int getDocumentCount()
    {
        final CouchResult<JsonObject> result = session.getClient().createRequest(getDbUrl()).execute(HttpMethod.GET);
        return result.getElement().get(DOC_COUNT).getAsInt();
    }
}<commit_msg>Able to fetch documents from the database as JsonElements or pick a class type to deserialize from :-)<commit_after>package chesterfield;

import com.google.gson.JsonObject;
import com.google.gson.Gson;
import com.google.gson.JsonElement;

import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;

/**
 * Represents a Couchdb database which can be used to update documents
 */
public class Database
{
    private static final String DOC_COUNT = "doc_count";

    private final String name;
    private final Session session;

    public Database(String name, Session session)
    {
        this.name = name;
        this.session = session;
    }

    /**
     * Get the name of the database
     * @return database
     */
    public String getName()
    {
        return name;
    }

    /**
     * Get the session used to create this {@link chesterfield.Database} instance
     * @return session
     */
    public Session getSession()
    {
        return session;
    }

    /**
     * Get the couch client
     * @return client
     */
    CouchClient getClient()
    {
        return getSession().getClient();
    }

    /**
     * Get the Database Url
     * @return dbUrl
     */
    String getDbUrl()
    {
        return session.getBaseUrl() + urlEncode(name) + "/";
    }

    /**
     * Get the document with the given id
     * @param id
     * @return element
     */
    public JsonObject getDocument(String id)
    {
        return (JsonObject)getDocumentAsJsonElement(id);
    }

    private JsonElement getDocumentAsJsonElement(String id)
    {
        final CouchResult<JsonElement> result = getClient().createRequest(getDbUrl() + urlEncode(id)).execute(HttpMethod.GET);
        return result.isOK() ? result.getElement() : null;
    }

    /**
     * Get Document with the given id
     * @param id of the document
     * @param <T> type of the object to map to
     * @return document
     */
    public <T> T getDocument(String id, Class<T> t)
    {
        final JsonElement element = getDocumentAsJsonElement(id);
        if (element == null) return null;
        Gson gson = new Gson();
        return gson.fromJson(element, t);
    }

    /**
     * Get the total number of documents in the database
     * @return count
     */
    public int getDocumentCount()
    {
        final CouchResult<JsonObject> result = getClient().createRequest(getDbUrl()).execute(HttpMethod.GET);
        return result.getElement().get(DOC_COUNT).getAsInt();
    }

    private String urlEncode(String s)
    {
        try
        {
            return URLEncoder.encode(s, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
{'fraction_non_alphanumeric': 0.09934086629001883, 'fraction_numerical': 0.00047080979284369113, 'mean_word_length': 2.250956388676358, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2636958', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1190, 'n_words': 342}