<commit_before>package cheatsheet;

import cheatsheet.expression_parser.ExpressionParser;
import cheatsheet.javaluator_extension.ExtendedEvaluator;
import com.fathzer.soft.javaluator.StaticVariableSet;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.HashMap;

import net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot;
import info.bliki.wiki.model.WikiModel;
import net.sourceforge.jwbf.core.contentRep.Article;

import java.io.PrintWriter;

import net.sourceforge.jwbf.core.actions.HttpActionClient;

import org.jsoup.Jsoup;
import org.jsoup.examples.HtmlToPlainText;

import java.io.IOException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.*;
import java.net.*;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;

public class Calculator {
	private static final String DECIMAL_ROUND_OF_FORMAT = "0.00000000000000";
	private static final int[] PLOT_BUILD_BOUNDS = new int[]{-10, 10};
	private static final double PLOT_BUILD_STEP = 0.1;
	private final HashMap<Double, Double> coords = new HashMap<>();
	private Double evaluateResult;

    private int isAnswerExist = 0;
    private int isNameOfNumberExist = 0;
    private int isGraphicExist = 0;

	public String processExpression(final String expression) throws IllegalArgumentException,
			NullPointerException, ParseException {
		ExpressionParser parser = new ExpressionParser(expression);
		switch(parser.chooseType()) {
			case ARITHMETIC_EXPRESSION:
				evaluate(expression);
                this.isAnswerExist = 1;
                this.isGraphicExist = 1;
                this.isNameOfNumberExist = 1;
				return (this.evaluateResult.toString());
			case TWO_VAR_FUNCTION:
                this.isAnswerExist = 0;
                this.isNameOfNumberExist = 0;
                this.isGraphicExist = 1;
				buildPlot(expression);
				return (this.coords.keySet().toString()
						.concat("$")
						.concat(coords.values().toString())
						.replaceAll(" ", "")
						.replace("[", "")
						.replace("]", ""));
			case TEXT:
                this.isAnswerExist = 1;
                this.isNameOfNumberExist = 0;
                this.isGraphicExist = 0;
                System.out.println("try to get Wiki");
				return getWiki(expression);
			default:
				return "Unsupported input";
		}
	}

	private void buildPlot(String expression) throws IllegalArgumentException,
			NullPointerException, ParseException {
		final ExtendedEvaluator eval = new ExtendedEvaluator();
		final StaticVariableSet<Double> variables = new StaticVariableSet<Double>();
		String variable;

		if (expression.split("=")[1].toLowerCase().contains("x")) {
			variable = "x";
		} else if (expression.split("=")[1].toLowerCase().contains("y")){
			variable = "y";
		} else {
			variable = "z";
		}
		for (double step = PLOT_BUILD_BOUNDS[0]; step < PLOT_BUILD_BOUNDS[1];
			 	step += PLOT_BUILD_STEP) {
			variables.set(variable, step);
			Double result = eval.evaluate(expression.split("=")[1], variables);
			this.coords.put(step, result);
		}
	}

	private void evaluate(String expression)
			throws IllegalArgumentException, NullPointerException, ParseException {
		ExtendedEvaluator evaluator = new ExtendedEvaluator();

		DecimalFormat decimalFormat = new DecimalFormat(DECIMAL_ROUND_OF_FORMAT);
		String format = decimalFormat.format(evaluator.evaluate(expression));
		this.evaluateResult = this.convertDouble(decimalFormat.parse(format));
	}

	private double convertDouble(Object longValue) throws IllegalArgumentException {
		double valueTwo;

		if(longValue instanceof Long) {
			valueTwo = ((Long) longValue).doubleValue();
		} else if (longValue instanceof Double){
			valueTwo = (Double)longValue;
		} else {
			throw new IllegalArgumentException();
		}

		return valueTwo;
	}

    public String getWiki(String findRequest) {
        try {
            HttpActionClient client = new HttpActionClient(new URL("https://en.wikipedia.org/w/"));
            MediaWikiBot wikiBot = new MediaWikiBot(client);
            Article article = wikiBot.getArticle(findRequest);
            wikiBot.login("evgenyzhurko", "evgenyzhurko123");
            article.save();
            try{
                WikiModel wikiModel = new WikiModel("${image}", "${title}");
                String html = wikiModel.render(article.getText());
            
                Document doc = Jsoup.parse(html);
                for(Element e: doc.select("a"))
                    e.remove();
                for(Element e: doc.select("table.toc"))
                    e.remove();
                for(Element e: doc.select("ul"))
                    e.remove();
            
                doc.getElementById("See_also").remove();
                doc.getElementById("References").remove();
                doc.getElementById("External_links").remove();
            
                System.out.println("Fuck" + html);

                html = doc.select("body").toString();
            
                System.out.println(html);

                if (html == null) {
                    return "Something went wrong...";
                }

                return html;
            } catch (IOException e) {<commit_msg>Update Calculator.java<commit_after>package cheatsheet;

import cheatsheet.expression_parser.ExpressionParser;
import cheatsheet.javaluator_extension.ExtendedEvaluator;
import com.fathzer.soft.javaluator.StaticVariableSet;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.HashMap;

import net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot;
import info.bliki.wiki.model.WikiModel;
import net.sourceforge.jwbf.core.contentRep.Article;

import java.io.PrintWriter;

import net.sourceforge.jwbf.core.actions.HttpActionClient;

import org.jsoup.Jsoup;
import org.jsoup.examples.HtmlToPlainText;

import java.io.IOException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.io.*;
import java.net.*;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;

public class Calculator {
	private static final String DECIMAL_ROUND_OF_FORMAT = "0.00000000000000";
	private static final int[] PLOT_BUILD_BOUNDS = new int[]{-10, 10};
	private static final double PLOT_BUILD_STEP = 0.1;
	private final HashMap<Double, Double> coords = new HashMap<>();
	private Double evaluateResult;

    private int isAnswerExist = 0;
    private int isNameOfNumberExist = 0;
    private int isGraphicExist = 0;

	public String processExpression(final String expression) throws IllegalArgumentException,
			NullPointerException, ParseException {
		ExpressionParser parser = new ExpressionParser(expression);
		switch(parser.chooseType()) {
			case ARITHMETIC_EXPRESSION:
				evaluate(expression);
                this.isAnswerExist = 1;
                this.isGraphicExist = 1;
                this.isNameOfNumberExist = 1;
				return (this.evaluateResult.toString());
			case TWO_VAR_FUNCTION:
                this.isAnswerExist = 0;
                this.isNameOfNumberExist = 0;
                this.isGraphicExist = 1;
				buildPlot(expression);
				return (this.coords.keySet().toString()
						.concat("$")
						.concat(coords.values().toString())
						.replaceAll(" ", "")
						.replace("[", "")
						.replace("]", ""));
			case TEXT:
                this.isAnswerExist = 1;
                this.isNameOfNumberExist = 0;
                this.isGraphicExist = 0;
                System.out.println("try to get Wiki");
				return getWiki(expression);
			default:
				return "Unsupported input";
		}
	}

	private void buildPlot(String expression) throws IllegalArgumentException,
			NullPointerException, ParseException {
		final ExtendedEvaluator eval = new ExtendedEvaluator();
		final StaticVariableSet<Double> variables = new StaticVariableSet<Double>();
		String variable;

		if (expression.split("=")[1].toLowerCase().contains("x")) {
			variable = "x";
		} else if (expression.split("=")[1].toLowerCase().contains("y")){
			variable = "y";
		} else {
			variable = "z";
		}
		for (double step = PLOT_BUILD_BOUNDS[0]; step < PLOT_BUILD_BOUNDS[1];
			 	step += PLOT_BUILD_STEP) {
			variables.set(variable, step);
			Double result = eval.evaluate(expression.split("=")[1], variables);
			this.coords.put(step, result);
		}
	}

	private void evaluate(String expression)
			throws IllegalArgumentException, NullPointerException, ParseException {
		ExtendedEvaluator evaluator = new ExtendedEvaluator();

		DecimalFormat decimalFormat = new DecimalFormat(DECIMAL_ROUND_OF_FORMAT);
		String format = decimalFormat.format(evaluator.evaluate(expression));
		this.evaluateResult = this.convertDouble(decimalFormat.parse(format));
	}

	private double convertDouble(Object longValue) throws IllegalArgumentException {
		double valueTwo;

		if(longValue instanceof Long) {
			valueTwo = ((Long) longValue).doubleValue();
		} else if (longValue instanceof Double){
			valueTwo = (Double)longValue;
		} else {
			throw new IllegalArgumentException();
		}

		return valueTwo;
	}

    public String getWiki(String findRequest) {
        try {
            HttpActionClient client = new HttpActionClient(new URL("https://en.wikipedia.org/w/"));
            MediaWikiBot wikiBot = new MediaWikiBot(client);
            Article article = wikiBot.getArticle(findRequest);
            //wikiBot.login("evgenyzhurko", "evgenyzhurko123");
            //article.save();
            try{
                WikiModel wikiModel = new WikiModel("${image}", "${title}");
                String html = wikiModel.render(article.getText());
            
                Document doc = Jsoup.parse(html);
                for(Element e: doc.select("a"))
                    e.remove();
                for(Element e: doc.select("table.toc"))
                    e.remove();
                for(Element e: doc.select("ul"))
                    e.remove();
            
                doc.getElementById("See_also").remove();
                doc.getElementById("References").remove();
                doc.getElementById("External_links").remove();
            
                System.out.println("Fuck" + html);

                html = doc.select("body").toString();
            
                System.out.println(html);

                if (html == null) {
                    return "Something went wrong...";
                }

                return html;
            } catch (IOException e) {
{'fraction_non_alphanumeric': 0.11376444741618111, 'fraction_numerical': 0.007832648772566625, 'mean_word_length': 2.887857408095061, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5887566', 'n_tokens_mistral': 3319, 'n_tokens_neox': 2918, 'n_words': 613}