Exemple #1
0
bool GaddagFactory::pushWord(const Quackle::LetterString &word)
{
	++m_encodableWords;
	hashWord(word);
	// FIXME: This hash will fail if duplicate words are passed in.
	// But testing for duplicate words isn't so easy without keeping
	// an entirely separate list.

	for (unsigned i = 1; i <= word.length(); i++)
	{
		Quackle::LetterString newword;

		for (int j = i - 1; j >= 0; j--)
			newword.push_back(word[j]);

		if (i < word.length())
		{
			newword.push_back(internalSeparatorRepresentation);  // "^"
			for (unsigned j = i; j < word.length(); j++)
				newword.push_back(word[j]);
		}
		m_gaddagizedWords.push_back(newword);
	}
	return true;
}
Exemple #2
0
void GaddagFactory::Node::pushWord(const Quackle::LetterString& word)
{
	if (word.length() == 0)
	{
		t = true;
		return;
	}

	Quackle::Letter first = Quackle::String::front(word);
	Quackle::LetterString rest = Quackle::String::allButFront(word);
	int index = -1;

	for (size_t i = 0; i < children.size(); i++)
	{
		if (children[i].c == first)
		{
			index = i;
			i = children.size();
		}
	}

	if (index == -1)
	{
		Node n;
		n.c = first;
		n.t = false;
		n.pointer = 0;
		n.lastchild = false;
		children.push_back(n);
		index = children.size() - 1;
	}

	children[index].pushWord(rest);
}
Exemple #3
0
void GaddagFactory::hashWord(const Quackle::LetterString &word)
{
	QCryptographicHash wordhash(QCryptographicHash::Md5);
	wordhash.addData(word.constData(), word.length());
	QByteArray wordhashbytes = wordhash.result();
	m_hash.int32ptr[0] ^= ((const int32_t*)wordhashbytes.constData())[0];
	m_hash.int32ptr[1] ^= ((const int32_t*)wordhashbytes.constData())[1];
	m_hash.int32ptr[2] ^= ((const int32_t*)wordhashbytes.constData())[2];
	m_hash.int32ptr[3] ^= ((const int32_t*)wordhashbytes.constData())[3];
}
Exemple #4
0
void Node::pushword(Quackle::LetterString word, bool inSmaller, int pb) {
    if (word.length() == 0) {
        t = true;
				playability = pb;
				insmallerdict = inSmaller;
    }
    else {
        char first = word[0];
        Quackle::LetterString rest = word.substr(1, word.length() - 1);
        int index = -1;
 
        // cout << "first: " << first << ", rest: " << rest << endl;

        for (unsigned int i = 0; i < children.size(); i++) {
            if (children[i].c == first) {
                index = i;
                i = children.size();
            }
        }
        
        if (index == -1) {
            Node n;
            n.c = first;
            n.t = false;
						n.playability = 0;
						n.insmallerdict = false;
            n.pointer = 0;
						n.oldpointer = 0;
            n.lastchild = false;
            children.push_back(n);
            index = children.size() - 1;
        }

        children[index].pushword(rest, inSmaller, pb);
    }

	dexplored = false;
	sexplored = false;
	lexplored = false;
	deleted = false;
	written = false;
}
Exemple #5
0
int main(int argc, char **argv) {
	QCoreApplication a(argc, argv);

	GetOpt opts;
	QString alphabet;
	opts.addOption('a', "alphabet", &alphabet);
	if (!opts.parse())
		return 1;

	if (alphabet.isNull())
		alphabet = "english";

	Quackle::AlphabetParameters *alphas = 0;
	QString alphabetFile = QString("../data/alphabets/%1.quackle_alphabet").arg(alphabet);
	UVcout << "Using alphabet file: " << QuackleIO::Util::qstringToString(alphabetFile) << endl;
	QuackleIO::FlexibleAlphabetParameters *flexure = new QuackleIO::FlexibleAlphabetParameters;
	flexure->load(alphabetFile);
	alphas = flexure;

	QString leavesFilename = "superleaves.raw";
	QFile file(leavesFilename);
	if (!file.exists())
	{
		UVcout << "leaves file does not exist: " << QuackleIO::Util::qstringToString(leavesFilename) << endl;
		return false;
	}

	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		UVcout << "Could not open " << QuackleIO::Util::qstringToString(leavesFilename) << endl;
		return false;
	}

	QTextStream stream(&file);
	stream.setCodec(QTextCodec::codecForName("UTF-8"));

	ofstream out("encoded");

	int encodableLeaves = 0;
	int unencodableLeaves = 0;

  while (!stream.atEnd()) {
		QString leaveQString;
		stream >> leaveQString;
		double value;
		stream >> value;
		//UVcout << "value: " << value << endl;

		UVString leaveString = QuackleIO::Util::qstringToString(leaveQString);

		if (stream.atEnd())
			break;

		//UVcout << "read original string: " << originalString << endl;
		UVString leftover;
    Quackle::LetterString encodedLeave = alphas->encode(leaveString, &leftover);
		if (leftover.empty())
		{
			unsigned char leavelength = encodedLeave.length();
			out.write((char*)(&leavelength), 1);
			out.write(encodedLeave.begin(), encodedLeave.length());
			unsigned short int intvalue = (value + 128) * 256;
			//UVcout << "intvalue: " << intvalue << endl;
			out.write((char*)(&intvalue), 2);
			++encodableLeaves;
		}
		else
		{
			//UVcout << "not encodable without leftover: " << originalString << endl;
			++unencodableLeaves;
		}
    }

	file.close();
	delete alphas;

	UVcout << "encodable leaves: " << encodableLeaves << ", unencodable leaves: " << unencodableLeaves << endl;

}