MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_full_qspan_matched_text

Function get_full_qspan_matched_text

src/licensedcode/match.py:3213–3328  ·  view source on GitHub ↗

Yield strings corresponding to words of the matched query text given a ``match_qspan`` LicenseMatch qspan Span detected with an `idx` LicenseIndex in a query file at ``location`` or a ``query_string``. - ``match_query_start_line`` is the match query.start_line - ``match_start_l

(
    match_qspan,
    match_query_start_line,
    match_start_line,
    match_end_line,
    location=None,
    query_string=None,
    idx=None,
    whole_lines=False,
    highlight=True,
    highlight_matched='{}',
    highlight_not_matched='[{}]',
    only_matched=False,
    stopwords=STOPWORDS,
    _usecache=True,
    trace=TRACE_MATCHED_TEXT,
)

Source from the content-addressed store, hash-verified

3211
3212
3213def get_full_qspan_matched_text(
3214 match_qspan,
3215 match_query_start_line,
3216 match_start_line,
3217 match_end_line,
3218 location=None,
3219 query_string=None,
3220 idx=None,
3221 whole_lines=False,
3222 highlight=True,
3223 highlight_matched='{}',
3224 highlight_not_matched='[{}]',
3225 only_matched=False,
3226 stopwords=STOPWORDS,
3227 _usecache=True,
3228 trace=TRACE_MATCHED_TEXT,
3229):
3230 """
3231 Yield strings corresponding to words of the matched query text given a
3232 ``match_qspan`` LicenseMatch qspan Span detected with an `idx` LicenseIndex
3233 in a query file at ``location`` or a ``query_string``.
3234
3235 - ``match_query_start_line`` is the match query.start_line
3236 - ``match_start_line`` is the match start_line
3237 - ``match_end_line`` is the match= end_line
3238
3239 The returned strings contains the full text including punctuations and
3240 spaces that are not participating in the match proper including punctuations.
3241
3242 If ``whole_lines`` is True, the unmatched part at the start of the first
3243 matched line and the unmatched part at the end of the last matched lines are
3244 also included in the returned text (unless the line is very long).
3245
3246 If ``highlight`` is True, each token is formatted for "highlighting" and
3247 emphasis with the ``highlight_matched`` format string for matched tokens or to
3248 the ``highlight_not_matched`` for tokens not matched. The default is to
3249 enclose an unmatched token sequence in [] square brackets. Punctuation is
3250 not highlighted.
3251
3252 if ``only_matched`` is True, only matched tokens are returned and
3253 ``whole_lines`` and ``highlight`` are ignored. Unmatched words are replaced
3254 by a "dot".
3255
3256 If ``_usecache`` is True, the tokenized text is cached for efficiency.
3257 """
3258 if trace:
3259 logger_debug('get_full_qspan_matched_text: match_qspan:', match_qspan)
3260 logger_debug('get_full_qspan_matched_text: location:', location)
3261 logger_debug('get_full_qspan_matched_text: query_string :', query_string)
3262
3263 assert location or query_string
3264 assert idx
3265
3266 if only_matched:
3267 # use highlighting to skip the reporting of unmatched entirely
3268 whole_lines = False
3269 highlight = True
3270 highlight_matched = '{}'

Callers 2

match_unknownsFunction · 0.90
get_full_matched_textFunction · 0.85

Calls 4

tokenize_matched_textFunction · 0.85
reportable_tokensFunction · 0.85
logger_debugFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected