refactor Pattern Resource Type matching algorithm