forked from cwbishop/SIN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSIN_keywords.m
50 lines (44 loc) · 1.3 KB
/
SIN_keywords.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function [iskey, words] = SIN_keywords(sentence, varargin)
%% DESCRIPTION:
%
% In SIN, key words are capitalized and word options are enclosed in
% square brackets and separated by a forward spash (e.g., [are/were] or
% [ARE/WERE]). Words are separated by white space.
%
% This function accepts as its input a character string (e.g., a
% sentence) and returns a logical vector specifying if each word in the
% sequence is a keyword or not.
%
% INPUT:
%
% sentence: string, sentence (e.g., 'a DOG ran in the PARK')
%
% OUTPUT:
%
% iskey: bool, logical vector of length N, where N is the number of
% words in sentence.
%
% Development:
%
% 1. Modularize punctuation removal routine.
%
% Christopher W Bishop
% University of Washington
% 9/14
%% GET WORDS FROM SENTENCE
% Words are separated by white space.
words = strsplit(sentence);
% Assume words are not keywords by default
iskey = false(numel(words),1);
%% FIND KEYWORDS
% Determine keywords by capitalization in spreadsheet.
for n=1:length(words)
% Remove potential markups, and punctuation from words
tw = SIN_removepunctuation(words{n});
% If all words are capitalized
if all(isstrprop(tw, 'upper'))
iskey(n)=true;
else
iskey(n)=false;
end % if isstrprop ...
end % for i=1:length(w)