<commit_before>import collections
import re

from src.data import crossword
from src.puzzle.problems import problem

_CROSSWORD_REGEX = re.compile(r'^.*\(([\d\s,|]+)\)$')
_INTS = re.compile(r'(\d+)')

class CrosswordProblem(problem.Problem):
  def __init__(self, name, lines):
    super(CrosswordProblem, self).__init__(name, lines)
    self._conn = None
    self._cursor = None
    for line in lines:
      for match in _CROSSWORD_REGEX.finditer(line):
        lengths = _INTS.findall(match.group(1))
        if len(lengths) == 1:
          self.constrain(lambda x, _: len(x) == int(lengths[0]))
        else:
          target = sum(map(int, lengths))
          self.constrain(lambda x, _: len(x) >= target)
        break

  @staticmethod
  def score(src):
    # TODO: Look for common crossword expressions.
    if _CROSSWORD_REGEX.match(src):
      return 1
    # Something with a lot of words *might* be a crossword clue.
    return max(0, 0.5 * (min(5, len(src.split())) / 5))

  def _get_cursor(self):
    if self._cursor is None:
      self._conn, self._cursor = crossword.connect('data/crossword.sqlite')
    return self._cursor
<commit_msg>Fix trivial lint warning regarding mismatched types to max().<commit_after>import collections
import re

from src.data import crossword
from src.puzzle.problems import problem

_CROSSWORD_REGEX = re.compile(r'^.*\(([\d\s,|]+)\)$')
_INTS = re.compile(r'(\d+)')

class CrosswordProblem(problem.Problem):
  def __init__(self, name, lines):
    super(CrosswordProblem, self).__init__(name, lines)
    self._conn = None
    self._cursor = None
    for line in lines:
      for match in _CROSSWORD_REGEX.finditer(line):
        lengths = _INTS.findall(match.group(1))
        if len(lengths) == 1:
          self.constrain(lambda x, _: len(x) == int(lengths[0]))
        else:
          target = sum(map(int, lengths))
          self.constrain(lambda x, _: len(x) >= target)
        break

  @staticmethod
  def score(src):
    # TODO: Look for common crossword expressions.
    if _CROSSWORD_REGEX.match(src):
      return 1
    # Something with a lot of words *might* be a crossword clue.
    return max(0.0, 0.5 * (min(5, len(src.split())) / 5))

  def _get_cursor(self):
    if self._cursor is None:
      self._conn, self._cursor = crossword.connect('data/crossword.sqlite')
    return self._cursor

{'fraction_non_alphanumeric': 0.13213981244671782, 'fraction_numerical': 0.008098891730605285, 'mean_word_length': 3.1393298059964727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2480553', 'n_tokens_mistral': 816, 'n_tokens_neox': 781, 'n_words': 200}