<commit_before>package com.oldterns.vilebot.handlers.user;

/**
 * Created by eunderhi on 14/08/15.
 */

import ca.szc.keratin.bot.annotation.HandlerContainer;
import ca.szc.keratin.core.event.message.recieve.ReceivePrivmsg;
import net.engio.mbassy.listener.Handler;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by emmett on 12/08/15.
 */

@HandlerContainer
public class GetInfoOn {

    private static final Pattern questionPattern = Pattern.compile("^!(infoon)\\s(.+)$");
    @Handler
    public void getInfo(ReceivePrivmsg event) {
        String text = event.getText();
        Matcher matcher = questionPattern.matcher( text );

        if (matcher.matches()) {
            String question = matcher.group(2);
            String answer = getWiki(question);
            event.reply(answer);
        }
    }

    String getWiki(String query) {
        try {
            String wikiURL = getWikiURLFromGoogle(query);
            String wikipediaContent = getContent(wikiURL);
            String parsedWikiContent = parseResponse(wikipediaContent);
            return parsedWikiContent;
        }
        catch(Exception e) {
            return "Look I don't know.";
        }
    }
    String getWikiURLFromGoogle(String query) throws Exception {
        String googleURL = makeGoogleURL(query);
        String googleResponse = getContent(googleURL);
        String wikiURL = getWikiLink(googleResponse);
        return wikiURL;
    }
    String makeGoogleURL(String query) {
        query += "site:wikipedia.org";
        query = encode(query);
        return "https://www.google.com/search?q=" + query;
    }

    String getWikiLink(String googleHTML) {
        Document doc = Jsoup.parse(googleHTML);
        Element link = doc.select("a[href*=/url?q=https://en.wikipedia]").first();<commit_msg>Fix odd query results<commit_after>package com.oldterns.vilebot.handlers.user;

/**
 * Created by eunderhi on 14/08/15.
 */

import ca.szc.keratin.bot.annotation.HandlerContainer;
import ca.szc.keratin.core.event.message.recieve.ReceivePrivmsg;
import net.engio.mbassy.listener.Handler;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by emmett on 12/08/15.
 */

@HandlerContainer
public class GetInfoOn {

    private static final Pattern questionPattern = Pattern.compile("^!(infoon)\\s(.+)$");
    @Handler
    public void getInfo(ReceivePrivmsg event) {
        String text = event.getText();
        Matcher matcher = questionPattern.matcher( text );

        if (matcher.matches()) {
            String question = matcher.group(2);
            String answer = getWiki(question);
            event.reply(answer);
        }
    }

    String getWiki(String query) {
        try {
            String wikiURL = getWikiURLFromGoogle(query);
            String wikipediaContent = getContent(wikiURL);
            String parsedWikiContent = parseResponse(wikipediaContent);
            return parsedWikiContent;
        }
        catch(Exception e) {
            return "Look I don't know.";
        }
    }
    String getWikiURLFromGoogle(String query) throws Exception {
        String googleURL = makeGoogleURL(query);
        String googleResponse = getContent(googleURL);
        String wikiURL = getWikiLink(googleResponse);
        return wikiURL;
    }
    String makeGoogleURL(String query) {
        query += " site:wikipedia.org";
        query = encode(query);
        return "https://www.google.com/search?q=" + query;
    }

    String getWikiLink(String googleHTML) {
        Document doc = Jsoup.parse(googleHTML);
        Element link = doc.select("a[href*=/url?q=https://en.wikipedia]").first();
{'fraction_non_alphanumeric': 0.11295361691900985, 'fraction_numerical': 0.006248497957221821, 'mean_word_length': 2.907981220657277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '6270890', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1207, 'n_words': 254}