Example #1
0
// Given a string, turn it into a bitmask word
static Word string_to_bitmask(char const *p, unsigned const word_length)
{
	WordParser parser;

	while (*p != '\0')
		if (!parser.parse(*p++))
			return 0;
	return parser.result(word_length);
}
Example #2
0
int main() {
  // initialize Xerces
  try { XMLPlatformUtils::Initialize(); }
  catch (const XMLException& toCatch) { return 1; }

  WordParser *wordParser = new WordParser("data/words.xml");
  wordParser->parse();
  WordRepository *wordRepository = new WordRepository();
  wordParser->loadToRepository(wordRepository);

  TemplateParser *templateParser = new TemplateParser("data/templates.xml");
  templateParser->parse();
  PoemTemplateRepository *templateRepository = new PoemTemplateRepository();
  templateParser->loadToRepository(templateRepository);

  PoemGenerator *poemGenerator = new PoemGenerator(wordRepository, templateRepository);
  Poem *poem = poemGenerator->getPoem();
  std::string generatedKanjiPoem, generatedKanaPoem, generatedRomajiPoem, generatedEnglishPoem;
  generatedKanjiPoem = (new JapaneseKanjiRenderer(poem))->toString();
  generatedKanaPoem = (new JapaneseKanaRenderer(poem))->toString();
  generatedRomajiPoem = (new JapaneseRomajiRenderer(poem))->toString();
  generatedEnglishPoem = (new EnglishRenderer(poem))->toString();

  printf("KANJI:\n");
  printf("%s", generatedKanjiPoem.c_str());
  printf("\n");
  printf("KANA:\n");
  printf("%s", generatedKanaPoem.c_str());
  printf("\n");
  printf("ROMAJI:\n");
  printf("%s", generatedRomajiPoem.c_str());
  printf("\n");
  printf("ENGLISH:\n");
  printf("%s", generatedEnglishPoem.c_str());

  // shutdown Xerces
  XMLPlatformUtils::Terminate();
}
Example #3
0
// Parse a string in the form "<word> <matched>"
static bool parse_move(string const &cmd, unsigned const word_length, Word * const wordp, unsigned * const matchedp)
{
	WordParser parser;

	char const *p = cmd.c_str();
	for (;;) {
		if (*p == '\0')
			return false;
		if (*p == ' ' || *p == '\t')
			break;
		if (!parser.parse(*p++))
			return false;
	}
	*wordp = parser.result(word_length);
	if (*wordp == 0)
		return false;
	while (*p == ' ' || *p == '\t')
		p++;
	if (!isdigit(*p))
		return false;
	*matchedp = static_cast<unsigned>(atoi(p));
	return *matchedp <= word_length;
}