Refactor ReferencedEntitiesFinder

This patch improves the readability and structure in ReferencedEntitiesFinder.
It was split from https://gerrit.wikimedia.org/r/#/c/155896/

Change-Id: Ia8ccfe2db6fc857b3d10147326adaefd3055e255
Merge "Refactor ReferencedEntitiesFinder"