Return a list of exact LicenseMatch by matching the `query_run` against the `automaton` and `idx` index.
(
idx,
query_run,
automaton,
matcher=MATCH_AHO_EXACT,
matcher_order=MATCH_AHO_EXACT_ORDER,
**kwargs,
)
| 82 | |
| 83 | |
| 84 | def exact_match( |
| 85 | idx, |
| 86 | query_run, |
| 87 | automaton, |
| 88 | matcher=MATCH_AHO_EXACT, |
| 89 | matcher_order=MATCH_AHO_EXACT_ORDER, |
| 90 | **kwargs, |
| 91 | ): |
| 92 | """ |
| 93 | Return a list of exact LicenseMatch by matching the `query_run` against |
| 94 | the `automaton` and `idx` index. |
| 95 | """ |
| 96 | if TRACE: logger_debug(' #exact_AHO: start ... ') |
| 97 | if TRACE_DEEP: logger_debug(' #exact_AHO: query_run:', query_run) |
| 98 | |
| 99 | matches = [] |
| 100 | matches_append = matches.append |
| 101 | |
| 102 | qbegin = query_run.start |
| 103 | |
| 104 | matched_positions = get_matched_positions(query_run.tokens, qbegin, automaton) |
| 105 | if TRACE: |
| 106 | matched_positions = list(matched_positions) |
| 107 | logger_debug(' ##exact_AHO: matched_positions', matched_positions) |
| 108 | matched_spans = get_matched_spans(matched_positions, query_run.matchables) |
| 109 | if TRACE: |
| 110 | matched_spans = list(matched_spans) |
| 111 | logger_debug(' ##exact_AHO: matched_spans', matched_spans) |
| 112 | |
| 113 | len_legalese = idx.len_legalese |
| 114 | rules_by_rid = idx.rules_by_rid |
| 115 | tids_by_rid = idx.tids_by_rid |
| 116 | query = query_run.query |
| 117 | for rid, qspan, ispan in matched_spans: |
| 118 | itokens = tids_by_rid[rid] |
| 119 | hispan = Span(p for p in ispan if itokens[p] < len_legalese) |
| 120 | |
| 121 | rule = rules_by_rid[rid] |
| 122 | match = LicenseMatch( |
| 123 | rule=rule, |
| 124 | qspan=qspan, |
| 125 | ispan=ispan, |
| 126 | hispan=hispan, |
| 127 | query_run_start=qbegin, |
| 128 | matcher=matcher, |
| 129 | matcher_order=matcher_order, |
| 130 | query=query, |
| 131 | ) |
| 132 | matches_append(match) |
| 133 | if TRACE and matches: |
| 134 | logger_debug(' ##exact_AHO: matches found#') |
| 135 | for m in matches: |
| 136 | print(m) |
| 137 | |
| 138 | return matches |
| 139 | |
| 140 | |
| 141 | def get_matched_spans(positions, matchables): |
no test coverage detected