parent
70bac99083
commit
fd9c7ab669
12bitfloat_rust
@ -1,121 +1 @@
|
||||
#![feature(let_chains)]
|
||||
|
||||
use std::{env, fs};
|
||||
|
||||
fn clean_content(content: &str) -> String {
|
||||
let alloed_ichars = "01234567891abcdefghijklmnopqrstuvwxyz \n.,!?";
|
||||
|
||||
let clean_content = content.chars()
|
||||
.filter(|&c| alloed_ichars.contains(c))
|
||||
.collect::<String>();
|
||||
|
||||
clean_content
|
||||
}
|
||||
|
||||
fn get_sentences(content: &str) -> Vec<&str> {
|
||||
let mut sentences = content.split('.')
|
||||
.map(|s| s.trim_start()) // Remove leading whitespace
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Remove last "sentence" if didn't end with a dot
|
||||
if let Some(last) = sentences.last() && !last.ends_with('.') {
|
||||
sentences.pop();
|
||||
}
|
||||
|
||||
sentences
|
||||
}
|
||||
|
||||
fn get_words(sentences: &str) -> impl Iterator<Item = &str> + Clone {
|
||||
sentences.split_whitespace()
|
||||
}
|
||||
|
||||
fn is_fully_capitalized_word(word: &str) -> bool {
|
||||
word.chars()
|
||||
.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())
|
||||
}
|
||||
|
||||
fn get_capitalized_words(content: &str) -> Vec<&str> {
|
||||
let sentences = get_sentences(content);
|
||||
let mut cap_words = vec![];
|
||||
|
||||
for sentence in sentences {
|
||||
// Always skip the first word since sentences start with
|
||||
for word in get_words(sentence).skip(1) {
|
||||
if is_fully_capitalized_word(word) {
|
||||
cap_words.push(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cap_words
|
||||
}
|
||||
|
||||
fn get_numbers(content: &str) -> Vec<String> {
|
||||
let clean = clean_content(content);
|
||||
|
||||
clean.split(|c: char| c.is_ascii_digit())
|
||||
.map(|n| n.to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_forbidden_words(content: &str) -> Vec<&str> {
|
||||
fn check_forbidden(w: &str) -> bool {
|
||||
FORBIDDEN_WORDS.iter()
|
||||
.find(|fw| str::eq_ignore_ascii_case(w, fw))
|
||||
.is_some()
|
||||
}
|
||||
|
||||
get_words(content)
|
||||
.filter(|w| check_forbidden(w))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn analyze(data: &str) {
|
||||
let clean_data = clean_content(data);
|
||||
drop(clean_data); // You aren't actually using clean_data :O
|
||||
|
||||
// All capitalized words
|
||||
let cap_words = get_capitalized_words(data);
|
||||
println!("All capitalized words: {}", cap_words.len());
|
||||
|
||||
// All sentences
|
||||
let sentences = get_sentences(data);
|
||||
println!("Sentences: {}", sentences.len());
|
||||
|
||||
// All words
|
||||
let words = get_words(data);
|
||||
println!("Words: {}", words.clone().count());
|
||||
|
||||
// Numbers
|
||||
let numbers = get_numbers(data);
|
||||
println!("Numbers: {}", numbers.len());
|
||||
|
||||
// Forbidden words
|
||||
let fw = get_forbidden_words(data);
|
||||
println!("Forbidden words: {}", fw.len());
|
||||
|
||||
let word_count_per_sentence = words.count() / sentences.len();
|
||||
println!("Word count per sentence: {}", word_count_per_sentence);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Read in files from args
|
||||
for arg in env::args().skip(1) { // skip program arg
|
||||
let Ok(text) = fs::read_to_string(&arg) else {
|
||||
eprintln!("{arg} isn't a valid file or couldn't be read");
|
||||
continue;
|
||||
};
|
||||
|
||||
analyze(&text);
|
||||
}
|
||||
|
||||
// analyze(&SPAM1);
|
||||
}
|
||||
|
||||
static FORBIDDEN_WORDS: &'static [&'static str] = &[
|
||||
"recovery", "techie", "http", "https", "digital", "hack", "::", "//", "com",
|
||||
"@", "crypto", "bitcoin", "wallet", "hacker", "welcome", "whatsapp", "email", "cryptocurrency",
|
||||
"stolen", "freeze", "quick", "crucial", "tracing", "scammers", "expers", "hire", "century",
|
||||
"transaction", "essential", "managing", "contact", "contacting", "understanding", "assets", "funds"
|
||||
];
|
||||
|
||||
#![feature(let_chains)]\n\nuse std::{env, fs};\n\nfn clean_content(content: &str) -> String {\n\tlet alloed_ichars = \"01234567891abcdefghijklmnopqrstuvwxyz \\n.,!?\";\n\t\n\tlet clean_content = content.chars()\n\t\t.filter(|&c| alloed_ichars.contains(c))\n\t\t.collect::<String>();\n\t\n\tclean_content\n}\n\nfn get_sentences(content: &str) -> Vec<&str> {\n\tlet mut sentences = content.split('.')\n\t\t.map(|s| s.trim_start()) // Remove leading whitespace\n\t\t.collect::<Vec<_>>();\n\t\n\t// Remove last \"sentence\" if didn't end with a dot\n\tif let Some(last) = sentences.last() && !last.ends_with('.') {\n\t\tsentences.pop();\n\t}\n\t\n\tsentences\n}\n\nfn get_words(sentences: &str) -> impl Iterator<Item = &str> + Clone {\n\tsentences.split_whitespace()\n}\n\nfn is_fully_capitalized_word(word: &str) -> bool {\n\tword.chars()\n\t\t.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())\n}\n\nfn get_capitalized_words(content: &str) -> Vec<&str> {\n\tlet sentences = get_sentences(content);\n\tlet mut cap_words = vec![];\n\t\n\tfor sentence in sentences {\n\t\t// Always skip the first word since sentences start with\n\t\tfor word in get_words(sentence).skip(1) {\n\t\t\tif is_fully_capitalized_word(word) {\n\t\t\t\tcap_words.push(word);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tcap_words\n}\n\nfn get_numbers(content: &str) -> Vec<String> {\n\tlet clean = clean_content(content);\n\t\n\tclean.split(|c: char| c.is_ascii_digit())\n\t\t.map(|n| n.to_string())\n\t\t.collect()\n}\n\nfn get_forbidden_words(content: &str) -> Vec<&str> {\n\tfn check_forbidden(w: &str) -> bool {\n\t\tFORBIDDEN_WORDS.iter()\n\t\t\t.find(|fw| str::eq_ignore_ascii_case(w, fw))\n\t\t\t.is_some()\n\t}\n\t\n\tget_words(content)\n\t\t.filter(|w| check_forbidden(w))\n\t\t.collect()\n}\n\nfn analyze(data: &str) {\n\tlet clean_data = clean_content(data);\n\tdrop(clean_data); // You aren't actually using clean_data :O\n\t\n\t// All capitalized words\n\tlet cap_words = get_capitalized_words(data);\n\tprintln!(\"All capitalized words: {}\", cap_words.len());\n\t\n\t// All sentences\n\tlet sentences = get_sentences(data);\n\tprintln!(\"Sentences: {}\", sentences.len());\n\t\n\t// All words\n\tlet words = get_words(data);\n\tprintln!(\"Words: {}\", words.clone().count());\n\t\n\t// Numbers\n\tlet numbers = get_numbers(data);\n\tprintln!(\"Numbers: {}\", numbers.len());\n\t\n\t// Forbidden words\n\tlet fw = get_forbidden_words(data);\n\tprintln!(\"Forbidden words: {}\", fw.len());\n\t\n\tlet word_count_per_sentence = words.count() / sentences.len();\n\tprintln!(\"Word count per sentence: {}\", word_count_per_sentence);\n}\n\nfn main() {\n // Read in files from args\n for arg in env::args().skip(1) { // skip program arg\n \tlet Ok(text) = fs::read_to_string(&arg) else {\n \t\teprintln!(\"{arg} isn't a valid file or couldn't be read\");\n \t\tcontinue;\n \t};\n \t\n \tanalyze(&text);\n }\n \n//\tanalyze(&SPAM1);\n}\n\nstatic FORBIDDEN_WORDS: &'static [&'static str] = &[\n \"recovery\", \"techie\", \"http\", \"https\", \"digital\", \"hack\", \"::\", \"//\", \"com\",\n \"@\", \"crypto\", \"bitcoin\", \"wallet\", \"hacker\", \"welcome\", \"whatsapp\", \"email\", \"cryptocurrency\",\n \"stolen\", \"freeze\", \"quick\", \"crucial\", \"tracing\", \"scammers\", \"expers\", \"hire\", \"century\",\n \"transaction\", \"essential\", \"managing\", \"contact\", \"contacting\", \"understanding\", \"assets\", \"funds\"\n];\n
|
@ -1,140 +1 @@
|
||||
#!+[feature(let_chains)]
|
||||
|
||||
|
||||
fn clean_content(content: &str) -> String {
|
||||
let alloed_ichars = "01234567891abcdefghijklmnopqrstuvwxyz \n.,!?";
|
||||
|
||||
let clean_content = content.chars()
|
||||
.filter(|&c| alloed_ichars.contains(c))
|
||||
.collect::<String>();
|
||||
|
||||
clean_content
|
||||
}
|
||||
|
||||
fn get_sentences(content: &str) -> Vec<&str> {
|
||||
let mut sentences = content.split('.')
|
||||
.map(|s| s.trim_start()) // Remove leading whitespace
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Remove last "sentence" if didn't end with a dot
|
||||
if let Some(last) = sentences.last() && !last.ends_with('.') {
|
||||
sentences.pop();
|
||||
}
|
||||
|
||||
sentences
|
||||
}
|
||||
|
||||
fn get_words(sentences: &str) -> impl Iterator<Item = &str> + Clone {
|
||||
sentences.split_whitespace()
|
||||
}
|
||||
|
||||
fn is_fully_capitalized_word(word: &str) -> bool {
|
||||
word.chars()
|
||||
.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())
|
||||
}
|
||||
|
||||
fn get_capitalized_words(content: &str) -> Vec<&str> {
|
||||
let sentences = get_sentences(content);
|
||||
let mut cap_words = vec![];
|
||||
|
||||
for sentence in sentences {
|
||||
// Always skip the first word since sentences start with
|
||||
for word in get_words(sentence).skip(1) {
|
||||
if is_fully_capitalized_word(word) {
|
||||
cap_words.push(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cap_words
|
||||
}
|
||||
|
||||
fn get_numbers(content: &str) -> Vec<String> {
|
||||
let clean = clean_content(content);
|
||||
|
||||
clean.split(|c: char| c.is_ascii_digit())
|
||||
.map(|n| n.to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_forbidden_words(content: &str) -> Vec<&str> {
|
||||
fn check_forbidden(w: &str) -> bool {
|
||||
FORBIDDEN_WORDS.iter()
|
||||
.find(|fw| str::eq_ignore_ascii_case(w, fw))
|
||||
.is_some()
|
||||
}
|
||||
|
||||
get_words(content)
|
||||
.filter(|w| check_forbidden(w))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn analyze(data: &str) {
|
||||
let clean_data = clean_content(data);
|
||||
drop(clean_data); // You aren't actually using clean_data :O
|
||||
|
||||
// All capitalized words
|
||||
let cap_words = get_capitalized_words(data);
|
||||
println!("All capitalized words: {}", cap_words.len());
|
||||
|
||||
// All sentences
|
||||
let sentences = get_sentences(data);
|
||||
println!("Sentences: {}", sentences.len());
|
||||
|
||||
// All words
|
||||
let words = get_words(data);
|
||||
println!("Words: {}", words.clone().count());
|
||||
|
||||
// Numbers
|
||||
let numbers = get_numbers(data);
|
||||
println!("Numbers: {}", numbers.len());
|
||||
|
||||
// Forbidden words
|
||||
let fw = get_forbidden_words(data);
|
||||
println!("Forbidden words: {}", fw.len());
|
||||
|
||||
let word_count_per_sentence = words.count() / sentences.len();
|
||||
println!("Word count per sentence: {}", word_count_per_sentence);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// // Read in files from args
|
||||
// for arg in env::args() {
|
||||
// let Ok(text) = fs::read_to_string(arg) else {
|
||||
// eprintln!("{arg} isn't a valid file or couldn't be read");
|
||||
// continue;
|
||||
// };
|
||||
//
|
||||
// analyze(&text);
|
||||
// }
|
||||
|
||||
analyze(&SPAM1);
|
||||
}
|
||||
|
||||
static FORBIDDEN_WORDS: &'static [&'static str] = &[
|
||||
"recovery", "techie", "http", "https", "digital", "hack", "::", "//", "com",
|
||||
"@", "crypto", "bitcoin", "wallet", "hacker", "welcome", "whatsapp", "email", "cryptocurrency",
|
||||
"stolen", "freeze", "quick", "crucial", "tracing", "scammers", "expers", "hire", "century",
|
||||
"transaction", "essential", "managing", "contact", "contacting", "understanding", "assets", "funds"
|
||||
];
|
||||
|
||||
static SPAM1: &'static str = "HIRE Century Web Recovery TO RECOVER YOUR LOST BITCOIN
|
||||
If you’ve lost your Bitcoin to an online scam, hiring a professional recovery service can significantly improve your chances of getting your funds back. Century Web Recovery specializes in Bitcoin recovery, helping victims reclaim their stolen assets. Here’s what you need to know:
|
||||
|
||||
Understanding the Recovery Process
|
||||
The recovery process begins with contacting Century Web Recovery. Their team will guide you through the steps necessary to initiate an investigation into your case. Understanding the process is key to managing your expectations.
|
||||
|
||||
Documenting Your Case
|
||||
To facilitate recovery, it’s essential to document all relevant information regarding the scam. This includes transaction records, wallet addresses, and any communications with the scammer. Century Web Recovery will help you gather this information to build a strong case.
|
||||
|
||||
Investigation and Tracking
|
||||
Once you hire Century Web Recovery, their experts will begin investigating your case. They use sophisticated tools to track the stolen Bitcoin, identifying the paths taken by the scammers. This tracing is crucial for successful recovery.
|
||||
|
||||
Freezing Stolen Assets
|
||||
Quick action is vital in recovering stolen Bitcoin.Century Web Recovery works directly with cryptocurrency exchanges to freeze any stolen assets, preventing the scammers from cashing out your funds. This collaboration is essential for a successful recovery.
|
||||
|
||||
Legal Support and Guidance
|
||||
If necessary, Century Web Recovery can provide legal support. They will guide you on reporting the scam to law enforcement and assist in filing any legal claims. Their expertise in crypto-related cases ensures you receive the best advice on how to proceed.
|
||||
|
||||
If you’ve lost Bitcoin to an online scam, don’t hesitate. Hire Century Web Recovery to recover your lost assets and regain your financial security.";
|
||||
|
||||
#!+[feature(let_chains)]\n\n\nfn clean_content(content: &str) -> String {\n\tlet alloed_ichars = \"01234567891abcdefghijklmnopqrstuvwxyz \\n.,!?\";\n\t\n\tlet clean_content = content.chars()\n\t\t.filter(|&c| alloed_ichars.contains(c))\n\t\t.collect::<String>();\n\t\n\tclean_content\n}\n\nfn get_sentences(content: &str) -> Vec<&str> {\n\tlet mut sentences = content.split('.')\n\t\t.map(|s| s.trim_start()) // Remove leading whitespace\n\t\t.collect::<Vec<_>>();\n\t\n\t// Remove last \"sentence\" if didn't end with a dot\n\tif let Some(last) = sentences.last() && !last.ends_with('.') {\n\t\tsentences.pop();\n\t}\n\t\n\tsentences\n}\n\nfn get_words(sentences: &str) -> impl Iterator<Item = &str> + Clone {\n\tsentences.split_whitespace()\n}\n\nfn is_fully_capitalized_word(word: &str) -> bool {\n\tword.chars()\n\t\t.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())\n}\n\nfn get_capitalized_words(content: &str) -> Vec<&str> {\n\tlet sentences = get_sentences(content);\n\tlet mut cap_words = vec![];\n\t\n\tfor sentence in sentences {\n\t\t// Always skip the first word since sentences start with\n\t\tfor word in get_words(sentence).skip(1) {\n\t\t\tif is_fully_capitalized_word(word) {\n\t\t\t\tcap_words.push(word);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tcap_words\n}\n\nfn get_numbers(content: &str) -> Vec<String> {\n\tlet clean = clean_content(content);\n\t\n\tclean.split(|c: char| c.is_ascii_digit())\n\t\t.map(|n| n.to_string())\n\t\t.collect()\n}\n\nfn get_forbidden_words(content: &str) -> Vec<&str> {\n\tfn check_forbidden(w: &str) -> bool {\n\t\tFORBIDDEN_WORDS.iter()\n\t\t\t.find(|fw| str::eq_ignore_ascii_case(w, fw))\n\t\t\t.is_some()\n\t}\n\t\n\tget_words(content)\n\t\t.filter(|w| check_forbidden(w))\n\t\t.collect()\n}\n\nfn analyze(data: &str) {\n\tlet clean_data = clean_content(data);\n\tdrop(clean_data); // You aren't actually using clean_data :O\n\t\n\t// All capitalized words\n\tlet cap_words = get_capitalized_words(data);\n\tprintln!(\"All capitalized words: {}\", cap_words.len());\n\t\n\t// All sentences\n\tlet sentences = get_sentences(data);\n\tprintln!(\"Sentences: {}\", sentences.len());\n\t\n\t// All words\n\tlet words = get_words(data);\n\tprintln!(\"Words: {}\", words.clone().count());\n\t\n\t// Numbers\n\tlet numbers = get_numbers(data);\n\tprintln!(\"Numbers: {}\", numbers.len());\n\t\n\t// Forbidden words\n\tlet fw = get_forbidden_words(data);\n\tprintln!(\"Forbidden words: {}\", fw.len());\n\t\n\tlet word_count_per_sentence = words.count() / sentences.len();\n\tprintln!(\"Word count per sentence: {}\", word_count_per_sentence);\n}\n\nfn main() {\n//\t// Read in files from args\n//\tfor arg in env::args() {\n//\t\tlet Ok(text) = fs::read_to_string(arg) else {\n//\t\t\teprintln!(\"{arg} isn't a valid file or couldn't be read\");\n//\t\t\tcontinue;\n//\t\t};\n//\t\t\n//\t\t
|
@ -1,138 +1 @@
|
||||
#![feature(let_chains)]
|
||||
|
||||
use rayon::prelude::*;
|
||||
//use rayon::prelude::*;
|
||||
use std::{env, fs};
|
||||
|
||||
fn clean_content(content: &str) -> String {
|
||||
let alloed_ichars = "01234567891abcdefghijklmnopqrstuvwxyz \n.,!?";
|
||||
|
||||
let clean_content = content.chars()
|
||||
.filter(|&c| alloed_ichars.contains(c))
|
||||
.collect::<String>();
|
||||
|
||||
clean_content
|
||||
}
|
||||
|
||||
fn get_sentences(content: &str) -> Vec<&str> {
|
||||
let mut sentences = content.split('.')
|
||||
.map(|s| s.trim_start()) // Remove leading whitespace
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Remove last "sentence" if didn't end with a dot
|
||||
if let Some(last) = sentences.last() && !last.ends_with('.') {
|
||||
sentences.pop();
|
||||
}
|
||||
|
||||
sentences
|
||||
}
|
||||
|
||||
fn get_words(sentences: &str) -> impl Iterator<Item = &str> + Clone {
|
||||
sentences.split_whitespace()
|
||||
}
|
||||
|
||||
fn is_fully_capitalized_word(word: &str) -> bool {
|
||||
word.chars()
|
||||
.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())
|
||||
}
|
||||
|
||||
fn get_capitalized_words(content: &str) -> Vec<&str> {
|
||||
let sentences = get_sentences(content);
|
||||
let mut cap_words = vec![];
|
||||
|
||||
for sentence in sentences {
|
||||
// Always skip the first word since sentences start with
|
||||
for word in get_words(sentence).skip(1) {
|
||||
if is_fully_capitalized_word(word) {
|
||||
cap_words.push(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cap_words
|
||||
}
|
||||
|
||||
fn get_numbers(clean_content: &str) -> Vec<&str> {
|
||||
clean_content.split(|c: char| c.is_ascii_digit())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_forbidden_words(content: &str) -> Vec<&str> {
|
||||
fn check_forbidden(w: &str) -> bool {
|
||||
FORBIDDEN_WORDS.iter()
|
||||
.find(|fw| str::eq_ignore_ascii_case(w, fw))
|
||||
.is_some()
|
||||
}
|
||||
|
||||
get_words(content)
|
||||
.filter(|w| check_forbidden(w))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn analyze(data: &str) {
|
||||
let clean_data = clean_content(data);
|
||||
// drop(clean_data); // You aren't actually using clean_data :O
|
||||
|
||||
// All capitalized words
|
||||
let cap_words = get_capitalized_words(data);
|
||||
println!("All capitalized words: {}", cap_words.len());
|
||||
|
||||
// All sentences
|
||||
let sentences = get_sentences(data);
|
||||
println!("Sentences: {}", sentences.len());
|
||||
|
||||
// All words
|
||||
let words = get_words(data);
|
||||
println!("Words: {}", words.clone().count());
|
||||
|
||||
// Numbers
|
||||
let numbers = get_numbers(&clean_data);
|
||||
println!("Numbers: {}", numbers.len());
|
||||
|
||||
// Forbidden words
|
||||
let fw = get_forbidden_words(data);
|
||||
println!("Forbidden words: {}", fw.len());
|
||||
|
||||
if sentences.len() > 0 {
|
||||
let word_count_per_sentence = words.count() / sentences.len();
|
||||
println!("Word count per sentence: {}", word_count_per_sentence);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Read in files from args
|
||||
let mut files = Vec::with_capacity(env::args().len());
|
||||
let mut do_parallel = false;
|
||||
|
||||
for arg in env::args().skip(1) { // skip program arg
|
||||
if arg == "-p" {
|
||||
do_parallel = true;
|
||||
} else {
|
||||
files.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
// Do the work
|
||||
let work = |file| {
|
||||
let Ok(text) = fs::read_to_string(&file) else {
|
||||
eprintln!("{file} isn't a valid file or couldn't be read");
|
||||
return;
|
||||
};
|
||||
|
||||
analyze(&text);
|
||||
};
|
||||
|
||||
if !do_parallel {
|
||||
files.iter().for_each(work);
|
||||
} else {
|
||||
files.par_iter().for_each(work)
|
||||
}
|
||||
}
|
||||
|
||||
static FORBIDDEN_WORDS: &'static [&'static str] = &[
|
||||
"recovery", "techie", "http", "https", "digital", "hack", "::", "//", "com",
|
||||
"@", "crypto", "bitcoin", "wallet", "hacker", "welcome", "whatsapp", "email", "cryptocurrency",
|
||||
"stolen", "freeze", "quick", "crucial", "tracing", "scammers", "expers", "hire", "century",
|
||||
"transaction", "essential", "managing", "contact", "contacting", "understanding", "assets", "funds"
|
||||
];
|
||||
|
||||
#![feature(let_chains)]\\n\\nuse rayon::prelude::*;\\n//use rayon::prelude::*;\\nuse std::{env, fs};\\n\\nfn clean_content(content: &str) -> String {\\n\\tlet alloed_ichars = \\\"01234567891abcdefghijklmnopqrstuvwxyz \\\\n.,!?\\\";\\n\\t\\n\\tlet clean_content = content.chars()\\n\\t\\t.filter(|&c| alloed_ichars.contains(c))\\n\\t\\t.collect::<String>();\\n\\t\\n\\tclean_content\\n}\\n\\nfn get_sentences(content: &str) -> usize {\\n\\tlet sentences = content.split('.')\\n\\t\\t.map(|s| s.trim_start()) // Remove leading whitespace\\n\\t\\t.count();\\n\\t\\n//\\t// Remove last \\\"sentence\\\" if didn't end with a dot\\n//\\tif let Some(last) = sentences.last() && !last.ends_with('.') {\\n//\\t\\tsentences.pop();\\n//\\t}\\n\\t\\n\\tsentences\\n}\\n\\nfn get_words(content: &str, words: &mut usize, caps: &mut usize, fw: &mut usize) {\\n\\tfn check_forbidden(w: &str) -> bool {\\n\\t\\tFORBIDDEN_WORDS.iter()\\n\\t\\t\\t.find(|fw| str::eq_ignore_ascii_case(w, fw))\\n\\t\\t\\t.is_some()\\n\\t}\\n\\t\\n\\tfor word in content.split_whitespace() {\\n\\t\\t*words += 1;\\n\\t\\t\\n\\t\\tif is_fully_capitalized_word(word) {\\n\\t\\t\\t*caps += 1;\\n\\t\\t}\\n\\t\\tif check_forbidden(word) {\\n\\t\\t\\t*fw += 1;\\n\\t\\t}\\n\\t}\\n}\\n\\nfn is_fully_capitalized_word(word: &str) -> bool {\\n\\tword.chars()\\n\\t\\t.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())\\n}\\n\\nfn get_numbers(clean_content: &str) -> usize {\\n\\tclean_content.split(|c: char| !c.is_ascii_digit())\\n\\t\\t.count()\\n}\\n\\nfn analyze(data: &str) {\\n\\tlet clean_data = clean_content(data);\\n//\\tdrop(clean_data); // You aren't actually using clean_data :O\\n\\t\\n\\t// All capitalized words\\n\\tlet mut words = 0;\\n\\tlet mut fw = 0;\\n\\tlet mut cap_words = 0;\\n\\tget_words(&clean_data, &mut words, &mut fw, &mut cap_words);\\n\\t\\n\\tprintln!(\\\"All capitalized words: {}\\\", cap_words);\\n\\t\\n\\t// All sentences\\n\\tlet sentences = get_sentences(data);\\n\\tprintln!(\\\"Sentences: {}\\\", sentences);\\n\\t\\n\\t// All words\\n\\tprintln!(\\\"Words: {}\\\", words);\\n\\t\\n\\t// Numbers\\n\\tlet numbers = get_numbers(&clean_data);\\n\\tprintln!(\\\"Numbers: {}\\\", numbers);\\n\\t\\n\\t// Forbidden words\\n\\tprintln!(\\\"Forbidden words: {}\\\", fw);\\n\\t\\n\\tif sentences > 0 {\\n\\t\\tlet word_count_per_sentence = words / sentences;\\n\\t\\tprintln!(\\\"Word count per sentence: {}\\\", word_count_per_sentence);\\n\\t}\\n}\\n\\nfn main() {\\n // Read in files from args\\n\\tlet mut files = Vec::with_capacity(env::args().len());\\n\\tlet mut do_parallel = false;\\n\\t\\n\\tfor arg in env::args().skip(1) { // skip program arg\\n\\t\\tif arg == \\\"-p\\\" {\\n\\t\\t\\tdo_parallel = true;\\n\\t\\t} else {\\n\\t\\t\\tfiles.push(arg);\\n\\t\\t}\\n\\t}\\n\\t\\n\\t// Do the work\\n\\tlet work = |file| {\\n\\t let Ok(text) = fs::read_to_string(&file) else {\\n\\t\\t\\teprintln!(\\\"{file} isn't a valid file or couldn't be read\\\");\\n\\t\\t\\treturn;\\n\\t };\\n\\t \\tanalyze(&text);\\n\\t};\\n\\t\\n\\tif !do_parallel {\\n\\t\\tfiles.iter().for_each(work);\\n\\t} else {\\n\\t\\tfiles.par_iter().for_each(work)\\n\\t}\\n}\\n\\nstatic FORBIDDEN_WORDS: &'static [&'static str] = &[\\n \\\"recovery\\\", \\\"techie\\\", \\\"http\\\", \\\"https\\\", \\\"digital\\\", \\\"hack\\\", \\\"::\\\", \\\"//\\\", \\\"com\\\",\\n \\\"@\\\", \\\"crypto\\\", \\\"bitcoin\\\", \\\"wallet\\\", \\\"hacker\\\", \\\"welcome\\\", \\\"whatsapp\\\", \\\"email\\\", \\\"cryptocurrency\\\",\\n \\\"stolen\\\", \\\"freeze\\\", \\\"quick\\\", \\\"crucial\\\", \\\"tracing\\\", \\\"scammers\\\", \\\"expers\\\", \\\"hire\\\", \\\"century\\\",\\n \\\"transaction\\\", \\\"essential\\\", \\\"managing\\\", \\\"contact\\\", \\\"contacting\\\", \\\"understanding\\\", \\\"assets\\\", \\\"funds\\\"\\n];\\n
|
@ -1,157 +1 @@
|
||||
#![feature(let_chains)]
|
||||
|
||||
use rayon::prelude::*;
|
||||
//use rayon::prelude::*;
|
||||
use std::{env, fs};
|
||||
|
||||
fn clean_content(content: &str) -> String {
|
||||
let alloed_ichars = "01234567891abcdefghijklmnopqrstuvwxyz \n.,!?";
|
||||
|
||||
let clean_content = content.chars()
|
||||
.filter(|&c| alloed_ichars.contains(c))
|
||||
.collect::<String>();
|
||||
|
||||
clean_content
|
||||
}
|
||||
|
||||
fn get_sentences(content: &str) -> usize {
|
||||
let sentences = content.split('.')
|
||||
.map(|s| s.trim_start()) // Remove leading whitespace
|
||||
.count();
|
||||
|
||||
// // Remove last "sentence" if didn't end with a dot
|
||||
// if let Some(last) = sentences.last() && !last.ends_with('.') {
|
||||
// sentences.pop();
|
||||
// }
|
||||
|
||||
sentences
|
||||
}
|
||||
|
||||
fn get_words(content: &str, words: &mut usize, caps: &mut usize, fw: &mut usize) {
|
||||
fn check_forbidden(w: &str) -> bool {
|
||||
FORBIDDEN_WORDS.iter()
|
||||
.find(|fw| str::eq_ignore_ascii_case(w, fw))
|
||||
.is_some()
|
||||
}
|
||||
|
||||
for word in content.split_whitespace() {
|
||||
*words += 1;
|
||||
|
||||
if is_fully_capitalized_word(word) {
|
||||
*caps += 1;
|
||||
}
|
||||
if check_forbidden(word) {
|
||||
*fw += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_fully_capitalized_word(word: &str) -> bool {
|
||||
word.chars()
|
||||
.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())
|
||||
}
|
||||
|
||||
//fn get_capitalized_words(content: &str) -> usize {
|
||||
// let sentences = get_sentences(content);
|
||||
//// let mut cap_words = vec![];
|
||||
// let mut count = 0;
|
||||
//
|
||||
// for sentence in sentences {
|
||||
// // Always skip the first word since sentences start with
|
||||
// for word in get_words(sentence).skip(1) {
|
||||
// if is_fully_capitalized_word(word) {
|
||||
// count += 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// count
|
||||
//}
|
||||
|
||||
fn get_numbers(clean_content: &str) -> usize {
|
||||
clean_content.split(|c: char| !c.is_ascii_digit())
|
||||
.count()
|
||||
}
|
||||
|
||||
//fn get_forbidden_words(content: &str) -> usize {
|
||||
// fn check_forbidden(w: &str) -> bool {
|
||||
// FORBIDDEN_WORDS.iter()
|
||||
// .find(|fw| str::eq_ignore_ascii_case(w, fw))
|
||||
// .is_some()
|
||||
// }
|
||||
//
|
||||
// get_words(content)
|
||||
// .filter(|w| check_forbidden(w))
|
||||
// .collect()
|
||||
//}
|
||||
|
||||
fn analyze(data: &str) {
|
||||
let clean_data = clean_content(data);
|
||||
// drop(clean_data); // You aren't actually using clean_data :O
|
||||
|
||||
// All capitalized words
|
||||
let mut words = 0;
|
||||
let mut fw = 0;
|
||||
let mut cap_words = 0;
|
||||
get_words(&clean_data, &mut words, &mut fw, &mut cap_words);
|
||||
|
||||
println!("All capitalized words: {}", cap_words);
|
||||
|
||||
// All sentences
|
||||
let sentences = get_sentences(data);
|
||||
println!("Sentences: {}", sentences);
|
||||
|
||||
// All words
|
||||
println!("Words: {}", words);
|
||||
|
||||
// Numbers
|
||||
let numbers = get_numbers(&clean_data);
|
||||
println!("Numbers: {}", numbers);
|
||||
|
||||
// Forbidden words
|
||||
println!("Forbidden words: {}", fw);
|
||||
|
||||
if sentences > 0 {
|
||||
let word_count_per_sentence = words / sentences;
|
||||
println!("Word count per sentence: {}", word_count_per_sentence);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Read in files from args
|
||||
let mut files = Vec::with_capacity(env::args().len());
|
||||
let mut do_parallel = false;
|
||||
|
||||
for arg in env::args().skip(1) { // skip program arg
|
||||
if arg == "-p" {
|
||||
do_parallel = true;
|
||||
} else {
|
||||
files.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
// Do the work
|
||||
let work = |file| {
|
||||
let Ok(text) = fs::read_to_string(&file) else {
|
||||
eprintln!("{file} isn't a valid file or couldn't be read");
|
||||
return;
|
||||
};
|
||||
|
||||
analyze(&text);
|
||||
};
|
||||
|
||||
if !do_parallel {
|
||||
files.iter().for_each(work);
|
||||
} else {
|
||||
files.par_iter().for_each(work)
|
||||
}
|
||||
}
|
||||
|
||||
static FORBIDDEN_WORDS: &'static [&'static str] = &[
|
||||
"recovery", "techie", "http", "https", "digital", "hack", "::", "//", "com",
|
||||
"@", "crypto", "bitcoin", "wallet", "hacker", "welcome", "whatsapp", "email", "cryptocurrency",
|
||||
"stolen", "freeze", "quick", "crucial", "tracing", "scammers", "expers", "hire", "century",
|
||||
"transaction", "essential", "managing", "contact", "contacting", "understanding", "assets", "funds"
|
||||
];
|
||||
|
||||
|
||||
#![feature(let_chains)]\\n\\nuse rayon::prelude::*;\\n//use rayon::prelude::*;\\nuse std::{env, fs};\\n\\nfn clean_content(content: &str) -> String {\\n\\tlet alloed_ichars = \\\"01234567891abcdefghijklmnopqrstuvwxyz \\\\n.,!?\\\";\\n\\t\\n\\tlet clean_content = content.chars()\\n\\t\\t.filter(|&c| alloed_ichars.contains(c))\\n\\t\\t.collect::<String>();\\n\\t\\n\\tclean_content\\n}\\n\\nfn get_sentences(content: &str) -> usize {\\n\\tlet sentences = content.split('.')\\n\\t\\t.map(|s| s.trim_start()) // Remove leading whitespace\\n\\t\\t.count();\\n\\t\\n//\\t// Remove last \\\"sentence\\\" if didn't end with a dot\\n//\\tif let Some(last) = sentences.last() && !last.ends_with('.') {\\n//\\t\\tsentences.pop();\\n//\\t}\\n\\t\\n\\tsentences\\n}\\n\\nfn get_words(content: &str, words: &mut usize, caps: &mut usize, fw: &mut usize) {\\n\\tfn check_forbidden(w: &str) -> bool {\\n\\t\\tFORBIDDEN_WORDS.iter()\\n\\t\\t\\t.find(|fw| str::eq_ignore_ascii_case(w, fw))\\n\\t\\t\\t.is_some()\\n\\t}\\n\\t\\n\\tfor word in content.split_whitespace() {\\n\\t\\t*words += 1;\\n\\t\\t\\n\\t\\tif is_fully_capitalized_word(word) {\\n\\t\\t\\t*caps += 1;\\n\\t\\t}\\n\\t\\tif check_forbidden(word) {\\n\\t\\t\\t*fw += 1;\\n\\t\\t}\\n\\t}\\n}\\n\\nfn is_fully_capitalized_word(word: &str) -> bool {\\n\\tword.chars()\\n\\t\\t.all(|c| !c.is_ascii_alphanumeric() || c.is_ascii_uppercase())\\n}\\n\\nfn get_numbers(clean_content: &str) -> usize {\\n\\tclean_content.split(|c: char| !c.is_ascii
|
Loading…
Reference in New Issue
Block a user