Determine sentence type: Difference between revisions

added Easylang
(New post.)
(added Easylang)
 
(4 intermediate revisions by 3 users not shown)
Line 160:
N Neutral
</pre>
 
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/List .
:import std/Char .
 
determine [∅?0 '?' ([(0 =? '?' 'Q' (0 =? '.' 'S' (0 =? '!' 'E' 'N')))] _0)]
 
:test (determine empty) ('?')
:test (determine "hi there, how are you today?") ('Q')
:test (determine "I'd like to present to you the washing machine 9001.") ('S')
:test (determine "You have been nominated to win one of these!") ('E')
:test (determine "Just make sure you don't break it") ('N')
</syntaxhighlight>
 
=={{header|C++}}==
Line 169 ⟶ 183:
#include <vector>
 
char sentence_type(const std::string& sentence) {
if ( sentence.empty() ) {
throw std::invalid_argument("Cannot classify an empty sentence");
Line 191 ⟶ 205:
"Just make sure you don't break it" };
 
for ( const std::string& sentence : sentences ) {
std::cout << sentence << " -> " << sentence_type(sentence) << std::endl;
}
Line 309 ⟶ 323:
You have been nominated to win one of these! (E)
Just make sure you don''t break it (N)
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func$ stype s$ .
h$ = substr s$ len s$ 1
ind = strpos "?!." h$ mod1 4
return substr "QESN" ind 1
.
txt$[] = [ "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" ]
for t$ in txt$[]
print t$ & " -> " & stype t$
.
</syntaxhighlight>
{{out}}
<pre>
hi there, how are you today? -> Q
I'd like to present to you the washing machine 9001. -> S
You have been nominated to win one of these! -> E
Just make sure you don't break it -> N
</pre>
 
Line 1,055 ⟶ 1,089:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var sentenceType = Fn.new { |s|
if (s.count == 0) return ""
var types = []
Line 1,082 ⟶ 1,116:
{{libheader|Wren-iterate}}
The following alternative version takes the simplistic view that (unless they end the final sentence of the paragraph) '''?''', '''!''' or '''.''' will only end a sentence if they're immediately followed by a space. This of course is nonsense, given the way English is written nowadays, but it's probably an improvement on the first version without the need to search through an inevitably incomplete list of abbreviations.
<syntaxhighlight lang="ecmascriptwren">import "./pattern" for Pattern
import "./iterate" for Indexed
 
1,983

edits