Example #1
0
int main(int argc, char ** argv)
{
	try
	{
		bool document_object = false;
		bool show_navigation = false;

		const option_group general_options = { nullptr, {
			{ 'm', "document-object", bind_value(document_object, true),
			  i18n("Process events through a cainteoir::document object model") },
			{ 'n', "show-navigation", bind_value(show_navigation, true),
			  i18n("Print the navigation structure, not document content") },
		}};

		const std::initializer_list<const char *> usage = {
			i18n("events [OPTION..] DOCUMENT"),
			i18n("events [OPTION..]"),
		};

		const std::initializer_list<option_group> options = {
			general_options,
		};

		if (!parse_command_line(options, usage, argc, argv))
			return 0;

		rdf::graph metadata;
		const char *filename = (argc == 1) ? argv[0] : nullptr;
		rdf::uri subject(filename ? filename : std::string(), std::string());
		auto reader = cainteoir::createDocumentReader(filename, metadata, std::string());
		if (!reader)
		{
			fprintf(stderr, "unsupported document format for file \"%s\"\n", argv[0]);
			return 0;
		}

		if (document_object || show_navigation)
		{
			cainteoir::document doc(reader, metadata);
			if (show_navigation)
				print_navigation(metadata, doc, subject);
			else
			{
				auto docreader = cainteoir::createDocumentReader(doc.children());
				print_events(docreader);
			}
		}
		else
			print_events(reader);
	}
	catch (std::runtime_error &e)
	{
		fprintf(stderr, "error: %s\n", e.what());
	}

	return 0;
}
Example #2
0
 bindable &bindable::bind(const std::vector<sql_value> &values, size_t start_index) {
     size_t index = start_index;
     for(auto &value : values) {
         bind_value(index++, value);
     }
     return *this;
 }
Example #3
0
 static int foreach(sqlite3_stmt* statement, const Tuple& t)
 {
     int code = tuple_printer<Tuple, N - 1>::foreach(statement, t);
     if (code != SQLITE_OK)
     {
         return code;
     }
     return bind_value(statement, N, std::get<N - 1>(t));
 }
Example #4
0
int main(int argc, char ** argv)
{
	try
	{
		decltype(writeTextDocument) *writer = nullptr;

		const option_group general_options = { nullptr, {
			{ 0, "text", bind_value(writer, &writeTextDocument),
			  i18n("Output as plain text.") },
			{ 0, "html", bind_value(writer, &writeHtmlDocument),
			  i18n("Output as a HTML document.") },
		}};

		const std::initializer_list<const char *> usage = {
			i18n("doc2doc [OPTION..] DOCUMENT"),
			i18n("doc2doc [OPTION..]"),
		};

		if (!parse_command_line({ general_options }, usage, argc, argv))
			return 0;

		const char *filename = (argc == 1) ? argv[0] : nullptr;

		if (!writer)
			throw std::runtime_error(i18n("unsupported format to convert to (html and text only)"));

		rdf::graph metadata;
		auto reader = cainteoir::createDocumentReader(filename, metadata, std::string());
		if (!reader)
		{
			fprintf(stderr, i18n("unsupported document format for file \"%s\"\n"), filename ? filename : "<stdin>");
			return EXIT_FAILURE;
		}

		writer(reader);
	}
	catch (std::runtime_error &e)
	{
		fprintf(stderr, i18n("error: %s\n"), e.what());
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Example #5
0
        bind_mapping &bind_mapping::bind(const std::string &name, const sql_value &value)
        {
            if (mappings_.count(name) == 0) {
                throw binding_error("No parameter named '" + name + "' found");
            }

            auto indexes = mappings_[name];

            for (auto &index : indexes) {
                bind_value(index, value);
            }
            return *this;
        }
Example #6
0
void mysql_statement::bind_value(MYSQL_BIND &bind, enum_field_types type, const object_base_ptr &value, int index)
{
  bind_value(bind, type, value.id(), index);
}
Example #7
0
void mysql_statement::write(const char *, const object_base_ptr &x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_LONG, x.id(), host_index);
  ++host_index;
}
Example #8
0
void mysql_statement::write(const char *, const varchar_base &x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_VAR_STRING, x.c_str(), x.size(), host_index);
  ++host_index;
}
Example #9
0
void mysql_statement::write(const char *, const std::string &x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_STRING, x.data(), x.size(), host_index);
  ++host_index;
}
Example #10
0
void mysql_statement::write(const char *, const char *x, int s)
{
  bind_value(host_array[host_index], MYSQL_TYPE_VAR_STRING, x, s, host_index);
  ++host_index;
}
int main(int argc, char ** argv)
{
	try
	{
		tts::stress_type stress = tts::stress_type::as_transcribed;
		phoneme_mode mode = phoneme_mode::joined;
		bool no_pauses = false;
		bool show_features = false;
		const char *phoneme_map = nullptr;
		const char *accent = nullptr;

		const option_group general_options = { nullptr, {
			{ 's', "separate", bind_value(mode, phoneme_mode::separate),
			  i18n("Display each phoneme on a new line") },
			{ 'f', "features", bind_value(show_features, true),
			  i18n("Show the features along with the transcription") },
			{ 0, "no-pauses", bind_value(no_pauses, true),
			  i18n("Do not process pause phonemes") },
			{ 'M', "phoneme-map", phoneme_map, "PHONEME_MAP",
			  i18n("Use PHONEME_MAP to convert phonemes (e.g. accent conversion)") },
			{ 'a', "accent", accent, "ACCENT",
			  i18n("Use ACCENT to convert phonemes to the specified accent") },
		}};

		const option_group stress_options = { i18n("Phoneme Stress Placement:"), {
			{ 0, "syllables", bind_value(mode, phoneme_mode::syllables),
			  i18n("Show the syllable structure") },
			{ 0, "vowel-stress", bind_value(stress, tts::stress_type::vowel),
			  i18n("Place the stress on vowels (e.g. espeak, arpabet)") },
			{ 0, "syllable-stress", bind_value(stress, tts::stress_type::syllable),
			  i18n("Place the stress on syllable boundaries") },
		}};

		const option_group marker_options = { i18n("Phoneme Markers:"), {
			{ 0, "broad", bind_value(mode, phoneme_mode::broad_markers),
			  i18n("Use /.../ between phonetic transcriptions") },
			{ 0, "narrow", bind_value(mode, phoneme_mode::narrow_markers),
			  i18n("Use [...] between phonetic transcriptions") },
			{ 0, "espeak", bind_value(mode, phoneme_mode::espeak_markers),
			  i18n("Use [[...]] between phonetic transcriptions") },
		}};

		const std::initializer_list<const option_group *> options = {
			&general_options,
			&stress_options,
			&marker_options
		};

		const std::initializer_list<const char *> usage = {
			i18n("phoneme-converter [OPTION..] FROM TO TRANSCRIPTION"),
			i18n("phoneme-converter [OPTION..] FROM TO"),
		};

		if (!parse_command_line(options, usage, argc, argv))
			return 0;

		if (argc != 2 && argc != 3)
		{
			print_help(options, usage);
			return 0;
		}
		auto from = tts::createPhonemeReader(argv[0]);
		auto to   = tts::createPhonemeWriter(argv[1]);
		auto data = argc == 3 ? cainteoir::make_file_buffer(argv[2])
		                      : cainteoir::make_file_buffer(stdin);

		if (phoneme_map)
			from = tts::createPhonemeToPhonemeConverter(phoneme_map, from);
		if (accent)
			from = tts::createAccentConverter(accent, from);

		if (mode == phoneme_mode::syllables)
		{
			auto syllables = tts::create_syllable_reader();
			ipa::phonemes phonemes;
			from->reset(data);
			while (read_phonemes(from, phonemes))
			{
				tts::make_stressed(phonemes, stress);
				print_phonemes(phonemes, to, syllables);
			}
		}
		else
		{
			ipa::phonemes phonemes;
			from->reset(data);
			while (read_phonemes(from, phonemes))
			{
				tts::make_stressed(phonemes, stress);
				print_phonemes(phonemes, to, mode, no_pauses, show_features);
			}
		}
	}
	catch (std::runtime_error &e)
	{
		fprintf(stderr, i18n("error: %s\n"), e.what());
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Example #12
0
void mysql_statement::write(const char *, float x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_FLOAT, x, host_index);
  ++host_index;
}
Example #13
0
void mysql_statement::write(const char *, bool x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_TINY, x, host_index);
  ++host_index;
}
Example #14
0
void mysql_statement::write(const char *, unsigned long x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_LONGLONG, x, host_index);
  ++host_index;
}
Example #15
0
void mysql_statement::write(const char *, unsigned short x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_SHORT, x, host_index);
  ++host_index;
}
Example #16
0
 static int foreach(sqlite3_stmt* statement, const Tuple& t)
 {
     return bind_value(statement, 1, std::get<0>(t));
 }
Example #17
0
void mysql_statement::write(const char *, double x)
{
  bind_value(host_array[host_index], MYSQL_TYPE_DOUBLE, x, host_index);
  ++host_index;
}
Example #18
0
int main(int argc, char ** argv)
{
	setlocale(LC_MESSAGES, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	try
	{
		enum
		{
			rdf_ntriple,
			rdf_turtle,
			vorbis_comments,
			metadata_author,
			metadata_creation,
			metadata_description,
			metadata_language,
			metadata_modification,
			metadata_publication,
			metadata_publisher,
			metadata_rights,
			metadata_subjects,
			metadata_title,
		} output_type = rdf_ntriple;

		bool print_time = false;
		bool all_metadata = false;

		const option_group general_options = { nullptr, {
			{ 't', "time", bind_value(print_time, true),
			  i18n("Time how long it takes to extract the metadata") },
			{ 'a', "all", bind_value(all_metadata, true),
			  i18n("Extract all available metadata") },
		}};

		const option_group format_options = { i18n("Metadata Format:"), {
			{ 0, "ntriple", bind_value(output_type, rdf_ntriple),
			  i18n("Output RDF N-Triple metadata statements") },
			{ 0, "turtle", bind_value(output_type, rdf_turtle),
			  i18n("Output RDF Turtle metadata statements") },
			{ 0, "vorbis", bind_value(output_type, vorbis_comments),
			  i18n("Output VorbisComment entries") },
		}};

		const option_group extract_options = { i18n("Metadata Extraction:"), {
			{ 0, "author", bind_value(output_type, metadata_author),
			  i18n("Output the document author") },
			{ 0, "creation", bind_value(output_type, metadata_creation),
			  i18n("Output the document creation date") },
			{ 0, "description", bind_value(output_type, metadata_description),
			  i18n("Output the document description") },
			{ 0, "language", bind_value(output_type, metadata_language),
			  i18n("Output the document language") },
			{ 0, "modification", bind_value(output_type, metadata_modification),
			  i18n("Output the document modification date") },
			{ 0, "publication", bind_value(output_type, metadata_publication),
			  i18n("Output the document publication date") },
			{ 0, "publisher", bind_value(output_type, metadata_publisher),
			  i18n("Output the document publisher") },
			{ 0, "rights", bind_value(output_type, metadata_rights),
			  i18n("Output the document rights (e.g. copyright)") },
			{ 0, "subjects", bind_value(output_type, metadata_subjects),
			  i18n("Output the document subjects") },
			{ 0, "title", bind_value(output_type, metadata_title),
			  i18n("Output the document title") },
		}};

		const std::initializer_list<const option_group *> options = {
			&general_options,
			&format_options,
			&extract_options,
		};

		const std::initializer_list<const char *> usage = {
			i18n("metadata [OPTION..] DOCUMENT.."),
		};

		if (!parse_command_line(options, usage, argc, argv))
			return 0;

		cainteoir::stopwatch timer;
		rdf::graph metadata;

		if (argc == 0)
			cainteoir::createDocumentReader(nullptr, metadata, std::string());
		else for(int i = 0; i < argc; ++i)
		{
			auto reader = cainteoir::createDocumentReader(argv[i], metadata, std::string());
			if (!reader)
				fprintf(stderr, i18n("unsupported document format for file \"%s\"\n"), argv[i]);
			if (all_metadata)
				while (reader->read(&metadata)) ;
		}

		if (print_time)
			fprintf(stderr, "Extraction Time: %G\n", timer.elapsed());

		const char *filename = (argc == 1) ? argv[0] : nullptr;
		rdf::uri subject(filename ? filename : std::string(), std::string());

		if (!metadata.empty()) switch (output_type)
		{
		case vorbis_comments:
			{
				const rdf::uri subject = rdf::uri(argv[0], std::string());
				std::list<cainteoir::vorbis_comment> comments;
				cainteoir::add_document_metadata(comments, metadata, subject);
				for (auto &comment : comments)
					std::cout << comment.label << "=" << comment.value << std::endl;
			}
			break;
		case metadata_author:
			fprintf(stdout, "%s\n", get_author(metadata, subject).c_str());
			break;
		case metadata_creation:
			fprintf(stdout, "%s\n", get_date(metadata, subject, "creation").c_str());
			break;
		case metadata_description:
			fprintf(stdout, "%s\n", get_dublincore(metadata, subject, "description").c_str());
			break;
		case metadata_language:
			fprintf(stdout, "%s\n", get_dublincore(metadata, subject, "language").c_str());
			break;
		case metadata_modification:
			fprintf(stdout, "%s\n", get_date(metadata, subject, "modification").c_str());
			break;
		case metadata_publication:
			fprintf(stdout, "%s\n", get_date(metadata, subject, "publication").c_str());
			break;
		case metadata_publisher:
			fprintf(stdout, "%s\n", get_dublincore(metadata, subject, "publisher").c_str());
			break;
		case metadata_rights:
			fprintf(stdout, "%s\n", get_dublincore(metadata, subject, "rights").c_str());
			break;
		case metadata_subjects:
			for (auto &item : get_dublincore_items(metadata, subject, "subject"))
				fprintf(stdout, "%s\n", item.c_str());
			break;
		case metadata_title:
			fprintf(stdout, "%s\n", get_dublincore(metadata, subject, "title").c_str());
			break;
		default:
			{
				(*rdf::create_formatter(std::cout, output_type == rdf_ntriple ? rdf::formatter::ntriple : rdf::formatter::turtle))
					<< rdf::rdf
					<< rdf::rdfa
					<< rdf::rdfs
					<< rdf::xsd
					<< rdf::xml
					<< rdf::owl
					<< rdf::dc
					<< rdf::dcterms
					<< rdf::dcam
					<< rdf::epub
					<< rdf::epv
					<< rdf::opf
					<< rdf::ocf
					<< rdf::pkg
					<< rdf::media
					<< rdf::onix
					<< rdf::marc
					<< rdf::ncx
					<< rdf::dtb
					<< rdf::smil
					<< rdf::xhtml
					<< rdf::skos
					<< rdf::foaf
					<< rdf::ref
					<< rdf::tts
					<< rdf::iana
					<< rdf::subtag
					<< metadata;
			}
			break;
		}
	}
	catch (std::runtime_error &e)
	{
		fprintf(stderr, i18n("error: %s\n"), e.what());
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}