<commit_before>package Database;

import DataClasses.*;

import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

public class DatabaseHandler {

    public static void insertTitle(String title, String subTitle, String Url) {
        HashMap<String, String> values = new HashMap<>();
        values.put("title", title);
        values.put("subtitle", subTitle);
        values.put("url", Url);

        SqlHandler.insert("Titles", values);
    }

    public static int getTitleId(String title) {
        // TODO : return the actual id
        SqlHandler.select("Titles", new String[] {"id"}, "");

        return 1;
    }

    public static void updateTitle(int id) {
        String condition = "id=" + id;
        HashMap<String, String> values = new HashMap<>();
        SqlHandler.upadte("Titles", values, condition);
    }

    // will search the db for titles with the same words in the same order
    // will return <found title length> / <title length>
    public static Map<String,Double> searchTitle(String[] title) throws SQLException {
        HashMap<String, Double> values = new HashMap<>();
        ResultSet rs = SqlHandler.select("Titles", new String[]{"id", "headline"}, "headline LIKE");
        double max = 0;
        String id = "";
        while(rs.next()) {
            String[] dbTitle = (String[]) rs.getArray("headline").getArray();
            int index = 0;
            for (int i = 0; i < title.length; i++) {
                if (dbTitle[i].equals(title[index]))
                    index++;
            }
            double reliability = index / title.length;
            if (max < reliability) {
                max = reliability;
                id = rs.getString("id");
            }
            values.put(rs.getString("id"), reliability);
        }
        return values;
    }

    public static String processCrawlRequest(Map<Integer, Article> request, String domain) {

        return "";
    }

    public static String processMarkRequest(Map<Integer, Article> request, String domain) {<commit_msg>write handle title<commit_after>package Database;

import DataClasses.*;

import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

public class DatabaseHandler {

    public static void insertTitle(String title, String subTitle, String Url) {
        HashMap<String, String> values = new HashMap<>();
        values.put("title", title);
        values.put("subtitle", subTitle);
        values.put("url", Url);

        SqlHandler.insert("Titles", values);
    }

    public static int getTitleId(String title) {
        // TODO : return the actual id
        SqlHandler.select("Titles", new String[] {"id"}, "");

        return 1;
    }

    public static void updateTitle(int id) {
        String condition = "id=" + id;
        HashMap<String, String> values = new HashMap<>();
        SqlHandler.upadte("Titles", values, condition);
    }

    // will search the db for titles with the same words in the same order
    // will return <found title length> / <title length>
    public static Map<String,Double> searchTitle(String[] title) throws SQLException {
        HashMap<String, Double> values = new HashMap<>();
        ResultSet rs = SqlHandler.select("Titles", new String[]{"id", "headline"}, "");
        double max = 0;
        String id = "";
        while(rs.next()) {
            String[] dbTitle = (String[]) rs.getArray("headline").getArray();
            int index = 0;
            for (int i = 0; i < title.length; i++) {
                if (dbTitle[i].equals(title[index]))
                    index++;
            }
            double reliability = index / title.length;
            if (max < reliability) {
                max = reliability;
                id = rs.getString("id");
            }
            values.put(rs.getString("id"), reliability);
        }
        return values;
    }

    public static String processCrawlRequest(Map<Integer, Article> request, String domain) {

        return "";
    }

    public static String processMarkRequest(Map<Integer, Article> request, String domain) {
{'fraction_non_alphanumeric': 0.1266249398170438, 'fraction_numerical': 0.0019258545979778526, 'mean_word_length': 2.340032154340836, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 25, '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': '2548049', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1093, 'n_words': 332}