6 Commits
1.0.0 ... main

Author SHA1 Message Date
f6279d19cd Delete entrypoint.sh 2025-05-01 21:10:14 +02:00
071c71ae99 Delete Dockerfile 2025-05-01 21:10:02 +02:00
bb0f7ac0b1 docs:; update readme 2025-04-05 15:40:44 +02:00
5071c28f4f feat: optimize and simplify python download script 2025-04-05 15:25:40 +02:00
f5b2737178 feat: make it even simpler 2025-04-05 14:33:02 +02:00
6d9a5bbb84 feat: over simplify the code 2025-04-05 14:28:31 +02:00
7 changed files with 43 additions and 219 deletions

125
Cargo.lock generated
View File

@@ -3,131 +3,14 @@
version = 4
[[package]]
name = "cfg-if"
version = "1.0.0"
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "rpg"
version = "1.0.0"
dependencies = [
"rand",
]
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zerocopy"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be"
dependencies = [
"proc-macro2",
"quote",
"syn",
"fastrand",
]

View File

@@ -4,4 +4,4 @@ version = "1.0.0"
edition = "2021"
[dependencies]
rand = "0.8"
fastrand = "2.3.0"

View File

@@ -1,12 +0,0 @@
FROM python:3-alpine
COPY . /app
WORKDIR /app
VOLUME /app/data
RUN pip install -r requirements.txt
ENTRYPOINT [ "/app/entrypoint.sh" ]
CMD [ "start" ]

View File

@@ -17,7 +17,7 @@ docker build -t download_data .
docker run --volume $(pwd)/data:/app/data download_data
```
# Generate pseudonyms
## Generate pseudonyms
To generate pseudonyms, just run the rust program with cargo :

View File

@@ -1,33 +1,29 @@
import nltk
import os
def main():
# Load the corpora
nltk.download('wordnet')
nltk.download('averaged_perceptron_tagger')
nltk.download('universal_tagset')
nltk.download("wordnet")
# Get all the adjectives and nouns
adjectives = set()
nouns = set()
for synset in nltk.corpus.wordnet.all_synsets():
for lemma in synset.lemmas():
if lemma.name().isalpha():
if synset.pos() == 'a':
adjectives.add(lemma.name())
elif synset.pos() == 'n':
nouns.add(lemma.name())
adjectives = {
lemma.name().capitalize()
for synset in nltk.corpus.wordnet.all_synsets(pos="a")
for lemma in synset.lemmas()
if lemma.name().isalpha()
}
nouns = {
lemma.name().capitalize()
for synset in nltk.corpus.wordnet.all_synsets(pos="n")
for lemma in synset.lemmas()
if lemma.name().isalpha()
}
# Create the output directory if it doesn't exist
os.makedirs('data', exist_ok=True)
os.makedirs("data", exist_ok=True)
with open("data/adjectives.txt", "w") as adj_file:
adj_file.write("\n".join(sorted(adjectives)))
with open("data/nouns.txt", "w") as noun_file:
noun_file.write("\n".join(sorted(nouns)))
with open('data/adjectives.txt', 'w+') as file:
for adjective in adjectives:
file.write(str(adjective).capitalize() + '\n')
with open('data/nouns.txt', 'w+') as file:
for noun in nouns:
file.write(str(noun).capitalize() + '\n')
if __name__ == '__main__':
if __name__ == "__main__":
main()

View File

@@ -1,14 +0,0 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "No command provided"
exit 1
fi
if [ "$1" = "start" ]; then
echo "Running the command: python /app/pyrpg.py ${NUMBER_OF_PSEUDONYMS:-100}"
python /app/pyrpg.py ${NUMBER_OF_PSEUDONYMS:-100}
else
echo "Running the command: $@"
exec "$@"
fi

View File

@@ -1,49 +1,20 @@
use rand::seq::SliceRandom;
use rand::Rng;
use std::env;
use std::io::{BufRead, BufReader};
fn main() {
let num_pseudonyms: usize = {
let args: Vec<String> = env::args().collect();
if args.len() > 1 {
match args[1].parse::<usize>() {
Ok(num) => num,
Err(_) => {
eprintln!("Le nombre de pseudonymes doit être un entier positif.");
std::process::exit(1);
}
}
} else {
100
}
};
let num_pseudonyms = env::args()
.nth(1)
.and_then(|arg| arg.parse().ok())
.unwrap_or(10);
let adjectives: Vec<String> = {
BufReader::new(include_str!("../data/adjectives.txt").as_bytes())
.lines()
.filter_map(Result::ok)
.collect()
};
let adjectives = include_str!("../data/adjectives.txt").lines().collect::<Vec<_>>();
let nouns = include_str!("../data/nouns.txt").lines().collect::<Vec<_>>();
let nouns: Vec<String> = {
BufReader::new(include_str!("../data/nouns.txt").as_bytes())
.lines()
.filter_map(Result::ok)
.collect()
};
let mut rng = rand::thread_rng();
for _ in 0..num_pseudonyms {
let Some(adjective) = adjectives.choose(&mut rng) else {
eprintln!("Impossible de choisir un adjectif.");
std::process::exit(1);
};
let Some(noun) = nouns.choose(&mut rng) else {
eprintln!("Impossible de choisir un nom.");
std::process::exit(1);
};
let number: u32 = rng.gen_range(1..=999);
println!("{}", format!("{}-{}-{}", adjective, noun, number));
}
(0..num_pseudonyms).for_each(|_| {
println!(
"{}-{}-{}",
adjectives[fastrand::usize(0..adjectives.len())],
nouns[fastrand::usize(0..nouns.len())],
fastrand::u32(0..1000)
);
});
}