function [counts, countrootwithparts, countparts] = LMcountparts(D, objectname, method)


if nargin == 2;
    method = '';
end

n = length(D);

if nargin == 2
    [D, j] = LMquery(D, 'object.name', objectname, method);
else
    j = 1:n;
end

counts = zeros(n,1);
countrootwithparts = zeros(n,1);
countparts = zeros(n,1);


for i = 1:length(D);
    counts(j(i)) = LMcountobject(D(i));
    countrootwithparts(j(i)) = 0;
    countparts(j(i)) = 0;
    for k = 1:LMcountobject(D(i))
        if isfield(D(i).annotation.object(k),'parts')
            if isfield(D(i).annotation.object(k).parts,'ispartof') && ~isempty(D(i).annotation.object(k).parts.ispartof)
                countparts(j(i)) = countparts(j(i))+1;
            elseif isfield(D(i).annotation.object(k).parts,'hasparts') && ~isempty(D(i).annotation.object(k).parts.hasparts)
                countrootwithparts(j(i)) = countrootwithparts(j(i))+1;
            end
        end
    end
end
    