Return a ranked list of rule candidates for further matching give a `query_run`. Use approximate matching based on token sets ignoring positions. Only consider rules that have an rid in a `matchable_rids` rids set if provided. The ranking is based on a combo of resemblance, con
(query_run, idx, matchable_rids, top=50,
high_resemblance=False, high_resemblance_threshold=0.8,
_use_bigrams=False)
| 242 | |
| 243 | |
| 244 | def compute_candidates(query_run, idx, matchable_rids, top=50, |
| 245 | high_resemblance=False, high_resemblance_threshold=0.8, |
| 246 | _use_bigrams=False): |
| 247 | """ |
| 248 | Return a ranked list of rule candidates for further matching give a |
| 249 | `query_run`. Use approximate matching based on token sets ignoring |
| 250 | positions. Only consider rules that have an rid in a `matchable_rids` rids |
| 251 | set if provided. |
| 252 | |
| 253 | The ranking is based on a combo of resemblance, containment, length and |
| 254 | other measures. |
| 255 | |
| 256 | if `high_resemblance` is True, this return only candidates that have a a |
| 257 | high resemblance above `high_resemblance_threshold`. |
| 258 | """ |
| 259 | # collect query-side sets used for matching |
| 260 | token_ids = query_run.matchable_tokens() |
| 261 | qset, qmset = build_set_and_mset(token_ids, _use_bigrams=_use_bigrams) |
| 262 | |
| 263 | len_legalese = idx.len_legalese |
| 264 | |
| 265 | # perform two steps of ranking: |
| 266 | # step one with tid sets and step two with tid multisets for refinement |
| 267 | |
| 268 | ############################################################################ |
| 269 | # step 1 is on token id sets: |
| 270 | ############################################################################ |
| 271 | |
| 272 | sortable_candidates = [] |
| 273 | sortable_candidates_append = sortable_candidates.append |
| 274 | |
| 275 | sets_by_rid = idx.sets_by_rid |
| 276 | |
| 277 | for rid, rule in enumerate(idx.rules_by_rid): |
| 278 | if rid not in matchable_rids: |
| 279 | continue |
| 280 | |
| 281 | scores_vectors, high_set_intersection = compare_token_sets( |
| 282 | qset=qset, |
| 283 | iset=sets_by_rid[rid], |
| 284 | intersector=tids_sets_intersector, |
| 285 | counter=tids_set_counter, |
| 286 | high_intersection_filter=high_tids_set_subset, |
| 287 | len_legalese=len_legalese, |
| 288 | unique=True, |
| 289 | rule=rule, |
| 290 | filter_non_matching=True, |
| 291 | high_resemblance_threshold=high_resemblance_threshold) |
| 292 | |
| 293 | if scores_vectors: |
| 294 | svr, svf = scores_vectors |
| 295 | if (not high_resemblance |
| 296 | or (high_resemblance and svr.is_highly_resemblant and svf.is_highly_resemblant)): |
| 297 | sortable_candidates_append((scores_vectors, rid, rule, high_set_intersection)) |
| 298 | |
| 299 | if not sortable_candidates: |
| 300 | return sortable_candidates |
| 301 |
nothing calls this directly
no test coverage detected