function kernel=bag_of_words(s,t)

% function kernel=bag_of_words(s,t)
%
%This function computes the bag of words kernel between two strings
%
%INPUT
% s and t =  two strings
%
%OUTPUT
% kernel = the evaluation of the bag of words kernel on these strings
%
%
%For more info, see www.kernel-methods.net

%
%Author: Tijl De Bie, 25/02/2004, adapted (for speed-up) on 21/10/04


swords=strread(s,'%s');
twords=strread(t,'%s');

kernel=0;
for i=1:length(swords)
    kernel=kernel+sum(strcmpi(swords{i},twords));
end

%% Previous version:
%%
% kernel=0;
% for i=1:length(swords)
%     for j=1:length(twords)
%         if strcmpi(swords{i},twords{j})
%             kernel=kernel+1;
%         end
%     end
% end
