Compare commits
6 commits
a48353148f
...
22858e4b1b
Author | SHA1 | Date | |
---|---|---|---|
Martin Brodbeck | 22858e4b1b | ||
Martin Brodbeck | cb2b7de4b3 | ||
Martin Brodbeck | 06c7e144db | ||
Martin Brodbeck | 9a6420410c | ||
Martin Brodbeck | 04b54c09de | ||
Martin Brodbeck | cf57870d26 |
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
build/**
|
||||
build/**
|
||||
xxx/**
|
||||
|
|
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
|
||||
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
|
||||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [{
|
||||
"name": "Debug",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/build/tipplektionen",
|
||||
"args": ["--min-length", "2", "--max-length", "6", "-c", "ctienrsg"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
}]
|
||||
}
|
92
.vscode/settings.json
vendored
Normal file
92
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
{
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"hash_map": "cpp",
|
||||
"strstream": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"source_location": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"__bit_reference": "cpp",
|
||||
"__bits": "cpp",
|
||||
"__config": "cpp",
|
||||
"__debug": "cpp",
|
||||
"__errc": "cpp",
|
||||
"__hash_table": "cpp",
|
||||
"__locale": "cpp",
|
||||
"__mutex_base": "cpp",
|
||||
"__node_handle": "cpp",
|
||||
"__split_buffer": "cpp",
|
||||
"__threading_support": "cpp",
|
||||
"__tree": "cpp",
|
||||
"__tuple": "cpp",
|
||||
"__verbose_abort": "cpp",
|
||||
"ios": "cpp",
|
||||
"locale": "cpp",
|
||||
"queue": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.24)
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(tipplektionen VERSION 0.0.1)
|
||||
project(tipplektionen VERSION 1.0.0)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
add_compile_options(-Wall -Wextra -Wpedantic -Wsuggest-override)
|
||||
|
||||
find_package(Boost 1.80 COMPONENTS program_options REQUIRED)
|
||||
find_package(Boost 1.74 COMPONENTS program_options REQUIRED)
|
||||
find_package(ICU 70.0 COMPONENTS uc io REQUIRED)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
|
@ -13,4 +15,4 @@ set(SOURCES
|
|||
|
||||
add_executable(tipplektionen ${SOURCES})
|
||||
target_include_directories(tipplektionen PRIVATE ${Boost_INCLUDE_DIR})
|
||||
target_link_libraries(tipplektionen PRIVATE Boost::program_options)
|
||||
target_link_libraries(tipplektionen PRIVATE Boost::program_options ICU::uc ICU::io)
|
39
README.md
Normal file
39
README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# tipplektionen
|
||||
|
||||
Das Programm erstellt aus einem Wörterbuch Tipplektionen.
|
||||
|
||||
Dabei können verschiedene Optionen angegeben werden:
|
||||
* Minmale / maximale Wortlänge
|
||||
* Maximale Zeilenlänge
|
||||
* Anzahl der auszugebenden Zeilen
|
||||
* Vorgabe von Buchstaben, aus denen die Wörter bestehen dürfen
|
||||
* Ausgabe auf Wunsch nur in Kleinbuchstaben
|
||||
|
||||
## Abhängigkeiten
|
||||
Das Programm verwendet folgende Bibliotheken:
|
||||
* Boost, Ver. >= 1.74
|
||||
* ICU, Ver. >= 70
|
||||
|
||||
Außerdem wird unter `/usr/share/dict/ngerman` eine Datei mit infrage kommender Wörter erwartet. Unter Arch Linux kann man etwa das Paket *community/words* installieren, das u. a. diese liefert. Ansonsten kann auch die mitgelieferte Datei `ngerman` verwendet werden. Entweder kann sie an entsprechende Stelle kopiert oder der Pfad mittels `--dictfile` angegeben werden.
|
||||
|
||||
## Installation
|
||||
Die Anwendung kann mittels `cmake` compiliert werden:
|
||||
```
|
||||
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build
|
||||
```
|
||||
Anschließend liegt im build-Verzeichnis die ausführbare Datei.
|
||||
|
||||
## Verwendung
|
||||
Die Option `-h` listet alle Möglichkeiten auf:
|
||||
```
|
||||
Erlaubte Optionen:
|
||||
-h [ --help ] Ausgabe der Hilfe
|
||||
-c [ --characters ] arg Enthaltene Buchstaben
|
||||
--min-length arg Minimale Wortlänge
|
||||
--max-length arg Maximale Wortlänge
|
||||
--line-length arg Maximale Zeilenlänge
|
||||
-n [ --num-lines ] arg Anzahl Zeilen
|
||||
--lowercase Ausgabe nur klein geschrieben
|
||||
-d [ --dictfile ] arg Pfad zur Wörterbuchdatei
|
||||
```
|
83
main.cpp
83
main.cpp
|
@ -1,36 +1,107 @@
|
|||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <unicode/unistr.h>
|
||||
#include <unicode/ustream.h>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::string letters;
|
||||
int wordLengthMin{1};
|
||||
int wordLengthMax{1024};
|
||||
int lineLength{60};
|
||||
int numLines{4};
|
||||
std::string wordsFile{"/usr/share/dict/ngerman"};
|
||||
bool lowercase{false};
|
||||
|
||||
po::options_description desc("Erlaubte Optionen");
|
||||
desc.add_options()("help,h", "Ausgabe der Hilfe")("letters,l", po::value<std::string>(&letters),
|
||||
"Enthaltene Buchstaben");
|
||||
desc.add_options()("help,h", "Ausgabe der Hilfe")(
|
||||
"characters,c", po::value<std::string>(&letters), "Enthaltene Buchstaben")(
|
||||
"min-length", po::value<int>(&wordLengthMin),
|
||||
"Minimale Wortlänge")("max-length", po::value<int>(&wordLengthMax), "Maximale Wortlänge")(
|
||||
"line-length", po::value<int>(&lineLength),
|
||||
"Maximale Zeilenlänge")("num-lines,n", po::value<int>(&numLines), "Anzahl Zeilen")(
|
||||
"lowercase", po::bool_switch(&lowercase), "Ausgabe nur klein geschrieben")(
|
||||
"dictfile,d", po::value<std::string>(&wordsFile), "Pfad zur Wörterbuchdatei");
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
if (vm.contains("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ifstream infile("../wortliste.txt");
|
||||
std::ifstream infile(wordsFile);
|
||||
std::string line;
|
||||
|
||||
icu::UnicodeString uline;
|
||||
std::vector<icu::UnicodeString> words;
|
||||
icu::UnicodeString ucLetters = icu::UnicodeString::fromUTF8(letters);
|
||||
icu::UnicodeString ucLettersUpper = icu::UnicodeString::fromUTF8(letters).toUpper();
|
||||
long counter{0};
|
||||
|
||||
if (!std::filesystem::exists(wordsFile)) {
|
||||
std::cerr << "Datei existiert nicht: " << wordsFile << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (std::getline(infile, line)) {
|
||||
uline = icu::UnicodeString::fromUTF8(line);
|
||||
int length = uline.length();
|
||||
|
||||
if (length < wordLengthMin || length > wordLengthMax)
|
||||
continue;
|
||||
|
||||
if (ucLetters.length() > 0) {
|
||||
bool valid = true;
|
||||
for (int i{0}; i < uline.length(); i++) {
|
||||
auto ch = uline.charAt(i);
|
||||
if (ucLetters.indexOf(ch) == -1 && ucLettersUpper.indexOf(ch) == -1) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!valid)
|
||||
continue;
|
||||
}
|
||||
if (lowercase) {
|
||||
uline.toLower();
|
||||
}
|
||||
|
||||
words.push_back(uline);
|
||||
counter++;
|
||||
}
|
||||
|
||||
std::cout << "Anzahl: " << counter << std::endl;
|
||||
std::cout << "Anzahl infrage kommender Wörter: " << counter << "\n" << std::endl;
|
||||
|
||||
std::random_device rdev;
|
||||
std::mt19937 rng(rdev());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> distrib(0, words.size() - 1);
|
||||
for (int i{0}; i < numLines; i++) {
|
||||
icu::UnicodeString lectionLine;
|
||||
while (lectionLine.length() < lineLength) {
|
||||
if (lectionLine.isEmpty())
|
||||
lectionLine.append(words.at(distrib(rng)));
|
||||
else
|
||||
lectionLine.append(" " + words.at(distrib(rng)));
|
||||
}
|
||||
|
||||
if (lectionLine.length() > lineLength) {
|
||||
lectionLine.retainBetween(0, lectionLine.lastIndexOf(" ") + 1);
|
||||
lectionLine.trim();
|
||||
}
|
||||
|
||||
std::cout << lectionLine << std::endl;
|
||||
}
|
||||
}
|
427200
wortliste.txt → ngerman
427200
wortliste.txt → ngerman
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue