Yield Detection objects detected in a ``numbered_lines`` sequence of tuples of (line number, text). The flags ``include_copyrights``, ``include_holders`` and ``include_authors`` drive which actual detections are done and returned. For copyrights only:
(self,
numbered_lines,
include_copyrights=True,
include_holders=True,
include_authors=True,
include_copyright_years=True,
include_copyright_allrights=False,
)
| 246 | ) |
| 247 | |
| 248 | def detect(self, |
| 249 | numbered_lines, |
| 250 | include_copyrights=True, |
| 251 | include_holders=True, |
| 252 | include_authors=True, |
| 253 | include_copyright_years=True, |
| 254 | include_copyright_allrights=False, |
| 255 | ): |
| 256 | """ |
| 257 | Yield Detection objects detected in a ``numbered_lines`` sequence of |
| 258 | tuples of (line number, text). |
| 259 | |
| 260 | The flags ``include_copyrights``, ``include_holders`` and |
| 261 | ``include_authors`` drive which actual detections are done and returned. |
| 262 | |
| 263 | For copyrights only: |
| 264 | - If ``include_copyright_years`` is True, include years and year ranges. |
| 265 | - If ``include_copyright_allrights`` is True, include trailing |
| 266 | "all rights reserved"-style mentions |
| 267 | """ |
| 268 | |
| 269 | include_copyright_years = include_copyrights and include_copyright_years |
| 270 | include_copyright_allrights = include_copyrights and include_copyright_allrights |
| 271 | |
| 272 | if not numbered_lines: |
| 273 | return |
| 274 | |
| 275 | if TRACE or TRACE_TOK: |
| 276 | logger_debug(f'CopyrightDetector: numbered_lines: {numbered_lines}') |
| 277 | |
| 278 | tokens = list(get_tokens(numbered_lines)) |
| 279 | |
| 280 | if TRACE: |
| 281 | logger_debug(f'CopyrightDetector: initial tokens: {tokens}') |
| 282 | |
| 283 | if not tokens: |
| 284 | return |
| 285 | |
| 286 | # first, POS tag each token using token regexes |
| 287 | lexed_text = list(self.lexer.lex_tokens(tokens, trace=TRACE_TOK)) |
| 288 | |
| 289 | if TRACE or TRACE_DEEP: |
| 290 | logger_debug(f'CopyrightDetector: lexed tokens:') |
| 291 | for l in lexed_text: |
| 292 | logger_debug(f' {l!r}') |
| 293 | |
| 294 | # then build a parse parse_tree based on tagged tokens |
| 295 | parse_tree = self.parser.parse(lexed_text) |
| 296 | |
| 297 | if TRACE or TRACE_DEEP: |
| 298 | logger_debug('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') |
| 299 | logger_debug(f'CopyrightDetector: final parse_tree:\n{tree_pformat(parse_tree)}') |
| 300 | |
| 301 | non_copyright_labels = frozenset() |
| 302 | if not include_copyright_years: |
| 303 | non_copyright_labels = frozenset([ |
| 304 | 'YR-RANGE', 'YR', 'YR-AND', 'YR-PLUS', 'BARE-YR', |
| 305 | ]) |
no test coverage detected