File size: 1,698 Bytes
d4035c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
function sel = helperFindDb(X, stringFields, numericFields, varargin)
% HELPERFINDDB  Helper functions to find stuff in DBs
%
%   See also:: GETKERNELNAMES(), FINDROIS().
%   Author:: Andrea Vedaldi

% AUTORIGHTS
% Copyright (C) 2008-09 Andrea Vedaldi
%
% This file is part of the VGG MKL Class and VGG MKL Det code packages,
% available in the terms of the GNU General Public License version 2.

useRegex = 0 ;
sel = 1:length(X) ;

i = 1 ;
while i <= length(varargin)
  field = varargin{i} ;
  neg   = 0 ;

  if ~ischar(field)
    error('String expected.') ;
  end

  % turn regex on
  if strcmp('regexp', field)
    useRegex = 1 ;
    i = i + 1 ;
    continue ;
  end

  % turn regex off
  if strcmp('noregexp', field)
    useRegex = 0 ;
    i = i + 1 ;
    continue ;
  end

  % get value
  value = varargin{i+1} ;

  % handle value = '*'
  if ischar(value) & strcmp('*', value)
    i = i + 2 ;
    continue ;
  end

  % handle field begins with '~'
  if field(1) == '~'
    neg = 1 ;
    field = field(2:end) ;
  end

  switch field
    case 'subset'
      if ~ neg
        sel = intersect(sel, value) ;
      else
        sel = setdiff(sel, value) ;
      end

    case numericFields
      match = cellfun(@(x) isequalwithequalnans(x, value), {X(sel).(field)}) ;
      if neg, match = ~ match ; end
      sel = sel(match) ;

    case stringFields
      if ~ useRegex
        match = strcmp(value, {X(sel).(field)}) ;
      else
        match = cellfun(@(x)~isempty(x), regexp({X(sel).(field)}, value)) ;
      end
      if neg, match = ~ match ; end
      sel = sel(match) ;

    otherwise
      warning(sprintf('''%s'' is not a recognized field. Skipping.', field)) ;
  end
  i = i + 2 ;
end