<commit_before>package raptor.connector.fics.game;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import raptor.util.RaptorStringTokenizer;

/**
 * This parser is a bit unusual in that it maintains state as messages are
 * processed.
 * 
 * You can invoke getTakeBackMessage(gameId) to receive the last takeback offer
 * requested and whether or not it was accepted.
 * 
 * It is important to clearTakebackMessages after there is no longer a need to
 * keep this state.
 */
public class TakebackParser {

	public static class TakebackMessage {
		public int halfMovesRequested = -1;
		public boolean wasAccepted;
		public String gameId = "";
	}

	protected Map<String, TakebackMessage> gameToTakebackMessages = new HashMap<String, TakebackMessage>();

	public static final String IDENTIFIER = "Game";
	public static final String REQUEST_TAKE_BACK = "take back";
	public static final String ACCEPTD_TAKE_BACK = "accepts the takeback request";
	private static final Log LOG = LogFactory.getLog(TakebackParser.class);

	public TakebackMessage getTakebackMessage(String gameId) {
		return gameToTakebackMessages.get(gameId);
	}

	public void clearTakebackMessages(String gameId) {
		gameToTakebackMessages.remove(gameId);
	}

	public boolean parse(String line) {
		if (line.startsWith(IDENTIFIER) && line.contains(REQUEST_TAKE_BACK)) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Processing takeback offer.");
			}
			// Game 117: raptorb requests to take back 1 half move(s).
			TakebackMessage message = new TakebackMessage();
			RaptorStringTokenizer tok = new RaptorStringTokenizer(line, " ",
					true);

			tok.nextToken();<commit_msg>Added comments.<commit_after>package raptor.connector.fics.game;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import raptor.util.RaptorStringTokenizer;

/**
 * This parser is a bit unusual in that it maintains state as messages are
 * processed.
 * 
 * You can invoke getTakeBackMessage(gameId) to receive the last takeback offer
 * requested and whether or not it was accepted.
 * 
 * It is important to clearTakebackMessages after there is no longer a need to
 * keep this state.
 */
public class TakebackParser {

	public static class TakebackMessage {
		public int halfMovesRequested = -1;
		public boolean wasAccepted;
		public String gameId = "";
	}

	protected Map<String, TakebackMessage> gameToTakebackMessages = new HashMap<String, TakebackMessage>();

	public static final String IDENTIFIER = "Game";
	public static final String REQUEST_TAKE_BACK = "take back";
	public static final String ACCEPTD_TAKE_BACK = "accepts the takeback request";
	private static final Log LOG = LogFactory.getLog(TakebackParser.class);

	/**
	 * Returns the take back message for the specified game id. Returns null if
	 * there are none.
	 */
	public TakebackMessage getTakebackMessage(String gameId) {
		return gameToTakebackMessages.get(gameId);
	}

	/**
	 * Clears the take back message for the specified gameId.
	 */
	public void clearTakebackMessages(String gameId) {
		gameToTakebackMessages.remove(gameId);
	}

	/**
	 * Returns true if line is a take back accepted message.
	 */
	public boolean parse(String line) {
		if (line.startsWith(IDENTIFIER) && line.contains(REQUEST_TAKE_BACK)) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("Processing takeback offer.");
			}
			// Game 117: raptorb requests to take back 1 half move(s).
			TakebackMessage message = new TakebackMessage();
			RaptorStringTokenizer tok = new RaptorStringTokenizer(line, " ",
					true);

			tok.nextToken();
{'fraction_non_alphanumeric': 0.08702702702702703, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 4.49925705794948, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3136655', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1063, 'n_words': 347}