building similarity relationship logic