Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,35 @@
-- Rosetta Code Task written in Ada
-- Determine sentence type
-- https://rosettacode.org/wiki/Determine_sentence_type
-- July 2024, R. B. E.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
procedure Determine_Sentence_Type is
S1 : String := "hi there, how are you today?";
S2 : String := "I'd like to present to you the washing machine 9001.";
S3 : String := "You have been nominated to win one of these!";
S4 : String := "Just make sure you don't break it";
procedure Just_Do_It (S: String) is
begin
if (S'Last = 0) then
Put_Line ("Error: The provided sentence was empty.");
else
case S (S'Last) is
when '?' => Put ("Q: ");
when '.' => Put ("S: ");
when '!' => Put ("E: ");
when others => Put ("N: ");
end case;
Put_Line (S);
end if;
end Just_Do_It;
begin
Just_Do_It (S1);
Just_Do_It (S2);
Just_Do_It (S3);
Just_Do_It (S4);
end Determine_Sentence_Type;

View file

@ -0,0 +1,7 @@
("hi there, how are you today? I'd like to present to you the washing machine 9001. " +
"You have been nominated to win one of these! " +
"Just make sure you don't break it").split(/([.!?])(?:\s+|$)/).each_slice(2) do |slice|
print slice.join, " -> ",
{ "." => "S", "!" => "E", "?" => "Q", nil => "N" }[slice[1]?],
"\n"
end

View file

@ -0,0 +1,28 @@
(defun get-last-character (str)
"Return the last character of STR."
(let ((str-length))
(setq str-length (length str))
(substring str (- str-length 1) str-length)))
(defun classify-sentence (str)
"Classify the type of sentence based on final punctuation."
(let ((last-character (get-last-character str)))
(cond ((string= last-character ".") (format "S - %s" str))
((string= last-character "!") (format "E - %s" str))
((string= last-character "?") (format "Q - %s" str))
(t (format "N - %s" str)))))
(defun classify-multiple-sentences (str)
"Classify each sentence as Q, S, E, or N."
;; sentence boundary is defined as:
;; a period (full stop), exclamation point/mark, or question mark
;; followed by one space
;; followed by a capital letter
;; while the above will work for this exercise, it won't
;; work in other situations. See the Perl code in this section
;; for cases that the above will not cover.
(let ((regex-sentence-boundary "\\([.?!]\\) \\([[:upper:]]\\)"))
;; split the text into list of individual sentences
(dolist (one-sentence (split-string (replace-regexp-in-string regex-sentence-boundary "\\1\n\\2" str) "\n"))
;; classify each sentence
(insert (format "\n%s" (classify-sentence one-sentence))))))

View file

@ -1,10 +1,10 @@
const text = """
Hi there, how are you today? I'd like to present to you the washing machine 9001.
You have been nominated to win one of these! Just make sure you don't break it"""
You have been nominated to win one of these! Just make sure you don't break it
""" |> strip
haspunctotype(s) = '.' in s ? "S" : '!' in s ? "E" : '?' in s ? "Q" : "N"
text = replace(text, "\n" => " ")
parsed = strip.(split(text, r"(?:(?:(?<=[\?\!\.])(?:))|(?:(?:)(?=[\?\!\.])))"))
isodd(length(parsed)) && push!(parsed, "") # if ends without pnctuation
for i in 1:2:length(parsed)-1

View file

@ -0,0 +1,19 @@
local function sentence_type(s)
if #s == 0 then return "" end
local types = {}
for i = 1, #s do
local c = s[i]
if c == "?" then
types:insert("Q")
elseif c == "!" then
types:insert("E")
elseif c == "." then
types:insert("S")
end
end
if not(s[-1] in "?!.") then types:insert("N") end
return types:concat("|")
end
local s = "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! Just make sure you don't break it"
print(sentence_type(s))

View file

@ -0,0 +1,52 @@
#[derive(Debug)]
enum SentenceType {
Neutral,
Exclamation,
Question,
Serious
}
struct SentenceIter<'a> {
rest: &'a str
}
fn sentences(input: &'_ str) -> SentenceIter<'_> {
SentenceIter { rest: input.trim() }
}
impl<'a> Iterator for SentenceIter<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<Self::Item> {
if self.rest.is_empty() {
return None;
}
let Some(punct_i) = self.rest.find(&['!', '?', '.']) else {
let ret = self.rest;
self.rest = "";
return Some(ret.trim());
};
let (ret, left) = self.rest.split_at(punct_i + 1);
self.rest = left.trim_start();
return Some(ret.trim());
}
}
fn determine_sentence_type(s: &str) -> Option<SentenceType> {
match s.chars().last() {
Some('!') => Some(SentenceType::Exclamation),
Some('?') => Some(SentenceType::Question),
Some('.') => Some(SentenceType::Serious),
Some(_) => Some(SentenceType::Neutral),
None => None
}
}
fn main() {
let s = "hi there, how are you today? I'd like to present to you the washing machine 9001. You have been nominated to win one of these! Just make sure you don't break it";
let si = sentences(s);
for s in si {
println!("\"{}\"{:?}", s, determine_sentence_type(s).unwrap());
}
}