Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -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), comma, 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))))))
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
local fn SentenceType( sentence as CFStringRef ) as CFStringRef
|
||||
CFStringRef type
|
||||
select ( fn StringCharacterAtIndex( sentence, len(sentence)-1 ) )
|
||||
case _"?" : type = @"Q"
|
||||
case _"." : type = @"S"
|
||||
case _"!" : type = @"E"
|
||||
case else : type = @"N"
|
||||
end select
|
||||
end fn = type
|
||||
|
||||
print fn SentenceType( @"hi there, how are you today?" )
|
||||
print fn SentenceType( @"I'd like to present to you the washing machine 9001." )
|
||||
print fn SentenceType( @"You have been nominated to win one of these!" )
|
||||
print fn SentenceType( @"Just make sure you don't break it" )
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
function SentenceType(s: string): char;
|
||||
begin
|
||||
case s[^1] of
|
||||
'?': Result := 'Q';
|
||||
'!': Result := 'E';
|
||||
'.': Result := 'S';
|
||||
else Result := 'N';
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
var ss := Arr('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');
|
||||
foreach var s in ss do
|
||||
Println(s,'->',SentenceType(s));
|
||||
end.
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
$ENTRY Go {
|
||||
, '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': e.Sentences
|
||||
= <Prout <SentenceTypes e.Sentences>>;
|
||||
};
|
||||
|
||||
SentenceTypes {
|
||||
e.X '?' = Q;
|
||||
e.X '? ' e.Y = Q <SentenceTypes e.Y>;
|
||||
e.X '.' = S;
|
||||
e.X '. ' e.Y = S <SentenceTypes e.Y>;
|
||||
e.X '!' = E;
|
||||
e.X '! ' e.Y = E <SentenceTypes e.Y>;
|
||||
e.X = N;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue