public function loadDictionary(string $filename, $append = false, $regexp = "/^[a-z]{4,6}$/")
    {
        if (!file_exists($filename) || !is_readable($filename))
        {
            $orig = $filename;
            $filename = "/usr/share/dict/" . $filename;
            if (!file_exists($filename))
                throw new IOException("Cannot open file $orig and dictionary $filename does not exist");
        }

        $cnt = mime_content_type($filename);
        if (substr($cnt, 0, 4) !== "text")
            throw new IOException("$filename does not appear to contain text");

        $contents = file_get_contents($filename);
        $lines = explode("\n", $contents);
        if (!$append)
            $this->dictionary = array();

        $nwords = 0;

        $wrapper = new ErrorInterceptor('preg_match');
        $wrapper->registerError(E_WARNING, 'preg_match');

        foreach ($lines as $line)
        {
            if (empty($regexp) || $wrapper->execute($regexp, $line))
            {
                $this->dictionary[] = $line;
                ++$nwords;
            }

            if (count($wrapper->getInterceptedErrors()))
                throw new InvalidArgumentException("Invalid regexp: $regexp");
        }

        if ($nwords === 0)
            throw new InvalidArgumentException("File $filename contains no words that match $regexp");

        return $this;
    }