Skip to content

Commit

Permalink
initial adds
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Hanheide authored and Marc Hanheide committed Mar 26, 2012
0 parents commit 0dac4dc
Show file tree
Hide file tree
Showing 15 changed files with 20,545 additions and 0 deletions.
324 changes: 324 additions & 0 deletions 2010-04-22-vpen01.eaf

Large diffs are not rendered by default.

4,690 changes: 4,690 additions & 0 deletions VP01-face-1.eaf

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions elanAnnotationMatches.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
85 changes: 85 additions & 0 deletions elanAssignTiersWithCSV.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
% function elan = elanAssignTiersWithCSV (elan, tiers, csvid, part)
%
% This function assigns tiers with linkedFiles (or parts of them) given in
% the arguments.
%
% NEEDS :
% USED BY :
%
% ARGUMENTS: elan: an elan .eaf file loaded with elanReadFile.m
% tiers: one or more tiers
% csvid: id of one linkedFile (timeseries/csv)
% part: columns of csv file that are assigned to tiers
% RETURNS : elan: elan .eaf file with assignedTiers struct added
%
% adierker / 2011-03-03
% USAGE : [elan] = elanAssignTiersWithCSV(eaffile,{'Kopfgesten_remus','mt9_remus_classification_hg_004'},'csv_1',[2:7]);
%
% Note: If your assigned pairs are erroneous you have to explicitly
% reset the assignments to a new value or delete
% them by using the variable browser in your workspace and choose "delete"
% on the assignedTiers struct
function elan = elanAssignTiersWithCSV (elan, tiers, csvid, part)

% check correctness of arguments

% argument one: elan
if (~isfield(elan,'linkedFiles'))
error('there are no timeseries files linked to your elan file');
end%if

% argument two: tiers
if (~iscell(tiers))
% if 'tiers' is only single tier create cell with one element
tiers = {tiers};
end%if

% argument three: csvid
if (nargin < 3)
linkedFiles = fieldnames(elan.linkedFiles);
csvid = linkedFiles{1};
if (length(linkedFiles)>1)
warning('please choose _one_ linked File');
end
elseif (iscell(csvid))
warning('Elan does not support more than one linked File yet and thus this software toolkit does not support it as well');
elseif (~isfield(elan.linkedFiles,csvid))
warning('csvid "%s" not found in linked Files',csvid);
end%if

csvlength = size(elan.linkedFiles.(csvid).data,2);
% argument four: part
if (nargin < 4)
part = [2:csvlength];
elseif (length(part) > csvlength-1)
error('%s has only columns 2 to %s assign',csvid,num2str(csvlength))
end%if

% which part of the csv shall be assigned?
%partname = strcat('part_',num2str(1));
partsize = strcat('part_',regexprep(num2str(part),' ','_'));

% assign csvids (with parts) with tiernames
% add entries for csvids and all tiernames
for tiernum = 1:length(tiers)
if (~isfield(elan,'assignedTiers'))
elan.assignedTiers = struct();
end%if
tiername = tiers{tiernum};
if (isfield(elan.tiers,tiername))
if (~isfield(elan.assignedTiers,csvid))
elan.assignedTiers.(csvid) = struct();
end%if
elan.assignedTiers.(csvid).(partsize) = tiers;
%elan.assignedTiers.(csvid).(partname).partsize = num2str(part);
elan.assignedTiers.(tiername)= struct();
elan.assignedTiers.(tiername).(csvid) = num2str(part);
%elan.assignedTiers.(tiername).(partname) = part;
else
warning('tiername "%s" not found',tiername);
end%if
end%for

end%mainfunction
% suppress some matlab code warnings for this file (only for use with matlab editor)
%#ok<*WNTAG>
126 changes: 126 additions & 0 deletions elanComputeOverlap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
% function [newCompTier,overlaps,redundantCompTier]=elanComputeOverlap(compTier,refStartTS,refStopTS,refTierValues,numOverlap)
%
% compare compTier with arrays of timestamps (e.g. from refTier): [refStartTS] and [refStopTS];
% compute overlap cases (CCCCC is the compTier/annotation, RRR is the
% refTier that actually is sliced)
% case 1: "extend" (overlapCase 3)
% CCCCCCCCCCCCCC
% RRRRRRR
% case 2: "end extends" (overlapCase 5)
% CCCCCCCC
% RRRRRRR
% case 3: "begin extends" (overlapCase 9)
% CCCCCC
% RRRRRRR
% case 4: "include" (overlapCase 17)
% CCCC
% RRRRRRRRR
% feature request: function argument that specifies a min number frames to
% overlap that leads to an overlap situation
function [newCompTier,overlaps,redundantCompTier]=elanComputeOverlap(compTier,refStartTS,refStopTS,refTierName,compTierName,refTierValues,minOverlap)

% create four grids (one for each start/stop value list)
% e.g. refStartMat: width=length(refStartTS) length=length(compTier) with refStartTS values
% e.g. compStartMat: width=length(refStartTS) length=length(compTier) with compTier.start values
[refStartMat, compStartMat] = meshgrid(refStartTS,[compTier.start]);
[refStopMat, compStopMat] = meshgrid(refStopTS,[compTier.stop]);

% identify all annotations that at least touch somehow
overlaps=double((compStartMat < refStopMat) & (compStopMat > refStartMat));

[compIndex, refIndex]=find(overlaps); %[row, col] = find(X)

% set all overlapSeconds to zero
for i=1:length(refIndex)
compTier(compIndex(i)).overlapSeconds=0;
end;



% check all overlaps for their overlapCase and plot them
for i=1:length(refIndex)
rStart=refStartTS(refIndex(i));
rStop=refStopTS(refIndex(i));
rDur=rStop-rStart;

if nargin > 3 % for plotting of overlaps: RefTier
gcf;
clf;
% plot this annotation
annoval = strcat(' "',refTierValues{refIndex(i)},'" id: ',num2str(refIndex(i)));
lineval = strcat(' ',refTierName,' (refTier)');
z = 2;
x=rStart; %start point for annotation
w=rDur; %width for annotation
y=z-0.4;% 'line' in plot where tier will be plotted
h=0.6; % height for tiers in plot
grey = [.7 .7 .7];
rectangle('Position',[x y w h],'EdgeColor','none','FaceColor',grey);%,'Curvature',0.2);
text(x,z,annoval,'Color',[0 0 0],'Interpreter','none');
text(x,z-0.25,lineval,'Color',[0 0 0],'Interpreter','none');
hold on;
end

cStart=compTier(compIndex(i)).start;
cStop=compTier(compIndex(i)).stop;
cDur=cStop-cStart;
overDur=0;



% case 1:
% CCCCCCCCCCCCCC
% RRRRRRR
if (cStart < rStart && cStop > rStop)
overlaps(compIndex(i), refIndex(i)) = bitor(overlaps(compIndex(i), refIndex(i)), 2);
overDur=rDur; % duration of overlap
% case 2:
% CCCCCCCC
% RRRRRRR
elseif (cStart >= rStart && cStop > rStop)
overlaps(compIndex(i), refIndex(i)) = bitor(overlaps(compIndex(i), refIndex(i)), 4);
overDur=rStop-cStart;
% case 3:
% CCCCCC
% RRRRRRR
elseif (cStart < rStart && cStop <= rStop)
overlaps(compIndex(i), refIndex(i)) = bitor(overlaps(compIndex(i), refIndex(i)), 8);
overDur=cStop-rStart;
% case 4:
% CCCC
% RRRRRRRRR
elseif (cStart >= rStart && cStop <= rStop)
overlaps(compIndex(i), refIndex(i)) = bitor(overlaps(compIndex(i), refIndex(i)), 16);
overDur=cDur;
else
warning('unmodeled case');
end;
compTier(compIndex(i)).overlapCase=overlaps(compIndex(i), refIndex(i));
compTier(compIndex(i)).overlapSeconds=compTier(compIndex(i)).overlapSeconds+overDur;


if nargin > 3 % for plotting of overlaps: CompTier
% plot overlap case
blue = [0.30 0.40 0.6];
text(x,1.4,strcat('OverlapCase: ',num2str(overlaps(compIndex(i)), refIndex(i))),'Color',[0 0 0],'BackgroundColor',blue,'FontWeight','bold','FontSize',14,'EdgeColor','none','Interpreter','none');
% plot this annotation
annoval = strcat(' "',compTier(compIndex(i)).value,'" id: ',num2str(compIndex(i)));
lineval = strcat(' ',compTierName,' (compTier)');
z = 1;
x=cStart; %start point for annotation
w=cDur; %width for annotation
y=z-0.4;% 'line' in plot where tier will be plotted
h=0.6; % height for tiers in plot
grey = [.7 .7 .7];
rectangle('Position',[x y w h],'FaceColor',grey,'EdgeColor','none');%,'Curvature',0.2);
text(x,z,annoval,'Color',[0 0 0],'Interpreter','none');
text(x,z-0.25,lineval,'Color',[0 0 0],'Interpreter','none');
hold off;
pause(2.5);
end
end;

% prepare return variables redundantCompTier and newCompTier
selectedCompInd=unique(compIndex);
newCompTier=compTier(selectedCompInd); % single elements (for slicing)
redundantCompTier = compTier(compIndex); % repeated elements (only important for elanCorrelateTiers)
Loading

0 comments on commit 0dac4dc

Please sign in to comment.