-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathelanAnnotationMatches.m
79 lines (72 loc) · 2.18 KB
/
elanAnnotationMatches.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
% function res=elanAnnotationMatches(tier, matchingString)
%
% calculates the occurences of 'matchingString' in the annotations of 'tier' and
% returns the number of matches. The match is ignoring the case (e.g.
% 'Biron' matches 'biron').
%
% arguments: tier: _one_ tier structure
% matchingString: the string to search for (if it is a cell
% array, all the values are search for and
% results are reported separately
%
% example:
% s=elanAnnotationStats(e.tiers.SaySrv,'ich');
%
% res =
%
% matchingCount: 99
% totalCount: 181
% matchingPercent: 0.5470
% matchingIndices: [1x99 double]
%
% example:
% res=elanAnnotationMatches(e.tiers.SaySrv,{' ist ' ' ich '})
%
% res =
%
% anno_ist: [1x1 struct]
% anno_ich: [1x1 struct]
%res.anno_ich
%
% ans =
%
% matchingCount: 99
% totalCount: 181
% matchingPercent: 0.5470
% matchingIndices: [1x99 double]
function res=elanAnnotationMatches(tier, pattern)
if (iscell(pattern))
for i=1:length(pattern);
res.(correctStructID(pattern{i}))=elanAnnotationMatches(tier, pattern{i});
end;
else
% compute for each value
annos=lower({tier.value});
matches=[];
for i=1:length(annos);
if (strfind(annos{i}, lower(pattern)))
matches=[matches i];
end;
end;
res.matchingCount = length(matches);
res.totalCount= length(annos);
res.matchingPercent = res.matchingCount / res.totalCount;
res.matchingIndices = matches;
end;
function structID=correctStructID(in)
structID=regexprep(strtrim(in),'[^\w]|[äöüßÄÖÜ]','_');
% structID = strrep(in, '.', '_');
% structID = strrep(structID, '-', '_');
% structID = strrep(structID, ' ', '_');
% structID = strrep(structID, ',', '_');
% structID = strrep(structID, ';', '_');
% structID = strrep(structID, ':', '_');
% structID = strrep(structID, ':', '_');
% structID = strrep(structID, ':', '_');
% structID = strrep(structID, ':', '_');
% add 'anno_' before annotation value
if (~isempty(structID))
structID = strcat('anno_',structID);
% else
% warning ('empty tierID');
end