Determine sentence type: Difference between revisions
m
syntax highlighting fixup automation
(Added XPL0 example.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 24:
{{trans|Go}}
<
I s.empty
R ‘’
Line 43:
V 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(sentenceType(s))</
{{out}}
Line 52:
=={{header|ALGOL 68}}==
Classifies an empty string as "".
<
CHAR exclamation = "E"; # classification codes... #
CHAR question = "Q";
Line 89:
)
)
END</
{{out}}
<pre>
Line 96:
=={{header|AutoHotkey}}==
<
Msgbox, % SentenceType(Sentence)
Line 111:
}
return (D = SubStr(Sentence, 1, 3)) ? RTrim(RTrim(type, "|"), "N|") : RTrim(type, "|")
}</
{{out}}
<pre>Q|S|E|N</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f DETERMINE_SENTENCE_TYPE.AWK
BEGIN {
Line 147:
sentence = ""
}
</syntaxhighlight>
{{out}}
<pre>
Line 162:
=={{header|CLU}}==
<
% 'S' or 'N' for every sentence found.
% Because sentences are separated by punctuation, only the
Line 214:
stream$putc(po, c)
end
end start_up </
{{out}}
<pre>QSEN</pre>
=={{header|Epoxy}}==
<
["?"]:"Q",
["."]:"S",
Line 243:
cls
GetSentences("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")</
{{out}}
<pre>
Line 255:
This program attempts to prevent common abbreviations from ending sentences early. It also tries to handle parenthesized sentences and implements an additional type for exclamatory questions (EQ).
{{works with|Factor|0.99 2021-06-02}}
<
wrap.strings ;
Line 312:
"Hello, Mr. Anderson!" show
nl
"Are you sure?!?! How can you know?" show</
{{out}}
<pre>
Line 330:
=={{header|FreeBASIC}}==
<
'determines the sentence type of the first sentence in the string
'returns "E" for an exclamation, "Q" for a question, "S" for serious
Line 359:
while len(spam)>0
print sentype(spam)
wend</
{{out}}<pre>Q
S
Line 368:
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 398:
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"
fmt.Println(sentenceType(s))
}</
{{out}}
Line 411:
The following parses sentences with embedded quotations naively,
so that for example the sentence "He asked 'How are you?'." results in: Q S
<syntaxhighlight lang="jq">
# Input: a string
# Output: a stream of sentence type indicators
Line 432:
def 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";
s | sentenceTypes</
{{out}}
<pre>
Line 442:
=={{header|Julia}}==
<
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"""
Line 454:
println(rpad(parsed[i] * parsed[i + 1], 52), " ==> ", haspunctotype(parsed[i + 1]))
end
</
<pre>
Hi there, how are you today? ==> Q
Line 463:
=={{header|Lua}}==
<
p2t = { [""]="N", ["."]="S", ["!"]="E", ["?"]="Q" }
for s, p in text:gmatch("%s*([^%!%?%.]+)([%!%?%.]?)") do
print(s..p..": "..p2t[p])
end</
{{out}}
<pre>hi there, how are you today?: Q
Line 475:
=={{header|Perl}}==
<
use warnings;
use feature 'say';
Line 501:
else { say 'N' }
}
}</
{{out}}
<pre>hi there, how are you today?| Q
Line 511:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`hi there, how are you today? I'd like to present
Line 521:
<span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">v</span><span style="color: #0000FF;">,</span><span style="color: #008000;">'|'</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">w</span>
<!--</
{{out}}
<pre>
Line 528:
=={{header|Python}}==
<
txt = """
Line 543:
for i in range(0, len(pars)-1, 2):
print((pars[i] + pars[i + 1]).ljust(54), "==>", haspunctotype(pars[i + 1]))
</
<pre>
Hi there, how are you today? ==> Q
Line 553:
Or for more generality, and an alternative to hand-crafted regular expressions:
<
from functools import reduce
Line 666:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>('E', ['You have been nominated to win one of these!', "But perhaps substance isn't the goal!"])
Line 675:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my $paragraph = q:to/PARAGRAPH/;
Line 697:
default { 'N' };
}
}</
{{out}}
<pre>hi there, how are you today? | Q
Line 717:
=={{header|Vlang}}==
{{trans|go}}
<
if s.len == 0 {
return ""
Line 740:
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"
println(sentence_type(s))
}</
{{out}}
Line 748:
=={{header|Wren}}==
<
if (s.count == 0) return ""
var types = []
Line 765:
var 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"
System.print(sentenceType.call(s))</
{{out}}
Line 775:
{{libheader|Wren-trait}}
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.
<
import "./trait" for Indexed
Line 802:
}
System.print()
}</
{{out}}
Line 819:
=={{header|XPL0}}==
<
int Sentence, N, Len;
char Str;
Line 836:
if N < 3 then ChOut(0, ^|);
];
]</
{{out}}
|