diff options
Diffstat (limited to 'encodeleaves')
-rw-r--r-- | encodeleaves/.gitignore | 6 | ||||
-rw-r--r-- | encodeleaves/encodeleaves.cpp | 113 | ||||
-rw-r--r-- | encodeleaves/encodeleaves.pro | 29 |
3 files changed, 148 insertions, 0 deletions
diff --git a/encodeleaves/.gitignore b/encodeleaves/.gitignore new file mode 100644 index 0000000..f878785 --- /dev/null +++ b/encodeleaves/.gitignore @@ -0,0 +1,6 @@ +Makefile +obj +Makefile.Debug +Makefile.Release +debug +release diff --git a/encodeleaves/encodeleaves.cpp b/encodeleaves/encodeleaves.cpp new file mode 100644 index 0000000..882684e --- /dev/null +++ b/encodeleaves/encodeleaves.cpp @@ -0,0 +1,113 @@ +/* + * Quackle -- Crossword game artificial intelligence and analysis tool + * Copyright (C) 2005-2006 Jason Katz-Brown and John O'Laughlin. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <string> +#include <iostream> +#include <iomanip> +#include <vector> +#include <map> + +#include <QtCore> + +#include <quackleio/flexiblealphabet.h> +#include <quackleio/froggetopt.h> +#include <quackleio/util.h> + +using namespace std; + +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; + +} diff --git a/encodeleaves/encodeleaves.pro b/encodeleaves/encodeleaves.pro new file mode 100644 index 0000000..bd9f197 --- /dev/null +++ b/encodeleaves/encodeleaves.pro @@ -0,0 +1,29 @@ +TEMPLATE = app +DEPENDPATH += .. ../quackleio +INCLUDEPATH += . .. + +# enable/disable debug symbols +# CONFIG += debug + +CONFIG += console + +build_pass:CONFIG(debug, debug|release) { + LIBS += -L../debug -L../quackleio/debug +} + +build_pass:CONFIG(release, debug|release) { + LIBS += -L../release -L../quackleio/release +} + +LIBS += -L.. -L../quackleio -lquackle -lquackleio + +# Input +SOURCES += encodeleaves.cpp + + +win32:!win32-g++ { + QMAKE_CFLAGS_DEBUG ~= s/-MDd/-MTd/ + QMAKE_CXXFLAGS_DEBUG ~= s/-MDd/-MTd/ + QMAKE_CFLAGS_RELEASE ~= s/-MD/-MT/ + QMAKE_CXXFLAGS_RELEASE ~= s/-MD/-MT/ +} |