-
-
Notifications
You must be signed in to change notification settings - Fork 571
/
Copy pathcopyrights.py
4205 lines (3382 loc) · 130 KB
/
copyrights.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/scancode-toolkit for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import os
import re
import string
import sys
from collections import deque
from time import time
import attr
from pygmars import lex
from pygmars import parse
from pygmars import Token
from pygmars.tree import Tree
from commoncode.text import toascii
from commoncode.text import unixlinesep
from cluecode import copyrights_hint
# Tracing flags
TRACE = False or os.environ.get('SCANCODE_DEBUG_COPYRIGHT', False)
# set to 1 to enable pygmars deep tracing
TRACE_DEEP = 0
if os.environ.get('SCANCODE_DEBUG_COPYRIGHT_DEEP'):
TRACE_DEEP = 1
TRACE = False
TRACE_TOK = False or os.environ.get('SCANCODE_DEBUG_COPYRIGHT_TOKEN', False)
VALIDATE = False or os.environ.get('SCANCODE_DEBUG_COPYRIGHT_VALIDATE', False)
# Tracing flags
def logger_debug(*args):
pass
if TRACE or TRACE_DEEP or TRACE_TOK:
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.DEBUG)
def logger_debug(*args):
return logger.debug(' '.join(isinstance(a, str) and a or repr(a) for a in args))
"""
Detect and collect copyright statements.
The process consists in:
- prepare and cleanup text
- identify regions of text that may contain copyright (using hints).
These are called "candidates".
- tag the text to recognize (e.g. lex) parts-of-speech (POS) tags to identify
various copyright statements parts such as dates, companies, names
("named entities"), etc. This is done using pygmars which contains a lexer
derived from NLTK POS tagger.
- feed the tagged text to a parsing grammar describing actual copyright
statements (also using pygmars) and obtain a parse tree.
- Walk the parse tree and yield Detection objects (e.g., copyright statements,
holder or authors) with start and end line from the parse tree with some
extra post-detection cleanups.
"""
def detect_copyrights(
location,
include_copyrights=True,
include_holders=True,
include_authors=True,
include_copyright_years=True,
include_copyright_allrights=False,
demarkup=True,
deadline=sys.maxsize,
):
"""
Yield Detection objects detected in the file at ``location``.
The flags ``include_copyrights``, ``include_holders`` and
``include_authors`` drive which actual detections are done and returned.
For copyrights only:
- If ``include_copyright_years`` is True, include years and year ranges.
- If ``include_copyright_allrights`` is True, include trailing
"all rights reserved"-style mentions
Strip markup from text if ``demarkup`` is True.
Run for up to ``deadline`` seconds and return results found so far.
"""
from textcode.analysis import numbered_text_lines
numbered_lines = numbered_text_lines(location, demarkup=demarkup)
numbered_lines = list(numbered_lines)
if TRACE or TRACE_TOK:
logger_debug('detect_copyrights: numbered_lines')
for nl in numbered_lines:
logger_debug(' numbered_line:', repr(nl))
include_copyright_years = include_copyrights and include_copyright_years
include_copyright_allrights = include_copyrights and include_copyright_allrights
yield from detect_copyrights_from_lines(
numbered_lines=numbered_lines,
include_copyrights=include_copyrights,
include_holders=include_holders,
include_authors=include_authors,
include_copyright_years=include_copyright_years,
include_copyright_allrights=include_copyright_allrights,
deadline=deadline,
)
DETECTOR = None
def detect_copyrights_from_lines(
numbered_lines,
include_copyrights=True,
include_holders=True,
include_authors=True,
include_copyright_years=True,
include_copyright_allrights=False,
deadline=sys.maxsize,
):
"""
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:
- If ``include_copyright_years`` is True, include years and year ranges.
- If ``include_copyright_allrights`` is True, include trailing
"all rights reserved"-style mentions
Run for up to ``deadline`` seconds and return results found so far.
"""
if not numbered_lines:
return
include_copyright_years = include_copyrights and include_copyright_years
include_copyright_allrights = include_copyrights and include_copyright_allrights
global DETECTOR
if not DETECTOR:
DETECTOR = detector = CopyrightDetector()
else:
detector = DETECTOR
candidate_lines_groups = candidate_lines(numbered_lines)
if TRACE or TRACE_TOK:
candidate_lines_groups = list(candidate_lines_groups)
logger_debug(
f'detect_copyrights_from_lines: ALL groups of candidate '
f'lines collected: {len(candidate_lines_groups)}',
)
for candidates in candidate_lines_groups:
if TRACE:
from pprint import pformat
can = pformat(candidates, width=160)
logger_debug(
f' detect_copyrights_from_lines: processing candidates group:\n'
f' {can}'
)
detections = detector.detect(
numbered_lines=candidates,
include_copyrights=include_copyrights,
include_holders=include_holders,
include_authors=include_authors,
include_copyright_years=include_copyright_years,
include_copyright_allrights=include_copyright_allrights
)
if TRACE:
detections = list(detections)
logger_debug(f' detect_copyrights_from_lines: {detections}')
for detection in detections:
yield detection
# TODO: return a warning if we missed the deadline
if time() > deadline:
break
################################################################################
# DETECTION PROPER
################################################################################
class CopyrightDetector(object):
"""
Detect copyrights and authors.
"""
def __init__(self):
self.lexer = lex.Lexer(patterns)
self.parser = parse.Parser(grammar, trace=TRACE_DEEP, validate=VALIDATE)
def detect(self,
numbered_lines,
include_copyrights=True,
include_holders=True,
include_authors=True,
include_copyright_years=True,
include_copyright_allrights=False,
):
"""
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:
- If ``include_copyright_years`` is True, include years and year ranges.
- If ``include_copyright_allrights`` is True, include trailing
"all rights reserved"-style mentions
"""
include_copyright_years = include_copyrights and include_copyright_years
include_copyright_allrights = include_copyrights and include_copyright_allrights
numbered_lines = list(numbered_lines)
if not numbered_lines:
return
if TRACE or TRACE_TOK:
logger_debug(f'CopyrightDetector: numbered_lines: {numbered_lines}')
tokens = list(get_tokens(numbered_lines))
if TRACE:
logger_debug(f'CopyrightDetector: initial tokens: {tokens}')
if not tokens:
return
# first, POS tag each token using token regexes
lexed_text = list(self.lexer.lex_tokens(tokens, trace=TRACE_TOK))
if TRACE:
logger_debug(f'CopyrightDetector: lexed tokens: {lexed_text}')
# then build a parse parse_tree based on tagged tokens
parse_tree = self.parser.parse(lexed_text)
if TRACE:
logger_debug(f'CopyrightDetector: parse_tree:\n{tree_pformat(parse_tree)}')
non_copyright_labels = frozenset()
if not include_copyright_years:
non_copyright_labels = frozenset([
'YR-RANGE', 'YR', 'YR-AND', 'YR-PLUS', 'BARE-YR',
])
non_holder_labels = frozenset([
'COPY',
'YR-RANGE', 'YR-AND', 'YR', 'YR-PLUS', 'BARE-YR',
'EMAIL', 'URL',
'HOLDER', 'AUTHOR',
])
non_holder_labels_mini = frozenset([
'COPY',
'YR-RANGE', 'YR-AND', 'YR', 'YR-PLUS', 'BARE-YR',
'HOLDER', 'AUTHOR',
])
non_authors_labels = frozenset([
'COPY',
'YR-RANGE', 'YR-AND', 'YR', 'YR-PLUS', 'BARE-YR',
'HOLDER', 'AUTHOR',
])
# then walk the parse parse_tree, collecting copyrights, years and authors
for tree_node in parse_tree:
if not isinstance(tree_node, Tree):
if TRACE:
logger_debug(f'CopyrightDetector: parse_tree node: {tree_node}')
continue
tree_node_label = tree_node.label
if (include_copyrights or include_holders) and 'COPYRIGHT' in tree_node_label:
copyrght = build_detection_from_node(
node=tree_node,
cls=CopyrightDetection,
ignores=non_copyright_labels,
include_copyright_allrights=include_copyright_allrights,
refiner=refine_copyright,
junk=COPYRIGHTS_JUNK,
)
if TRACE:
logger_debug(f'CopyrightDetector: detection: {copyrght}')
if copyrght:
if include_copyrights:
yield copyrght
if include_holders:
# By default we strip email and urls from holders ....
holder = build_detection_from_node(
node=tree_node,
cls=HolderDetection,
ignores=non_holder_labels,
refiner=refine_holder,
)
if not holder:
# ... but if we have no holder, we try again and
# this time we keep email and URLs for holders using
# "non_holder_labels_mini" as an "ignores" label set
holder = build_detection_from_node(
node=tree_node,
cls=HolderDetection,
ignores=non_holder_labels_mini,
refiner=refine_holder,
)
if holder:
if TRACE:
logger_debug(f'CopyrightDetector: holders: {holder}')
yield holder
elif include_authors and tree_node_label == 'AUTHOR':
author = build_detection_from_node(
node=tree_node,
cls=AuthorDetection,
ignores=non_authors_labels,
refiner=refine_author,
junk=AUTHORS_JUNK,
)
if author:
if TRACE:
logger_debug(f'CopyrightDetector: detected authors: {author}')
yield author
def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split):
"""
Return an iterable of pygmars.Token built from a ``numbered_lines`` iterable
of tuples of (line number, text).
We perform a simple tokenization on spaces, tabs and some punctuation: =;
"""
for start_line, line in numbered_lines:
if TRACE_TOK:
logger_debug(' get_tokens: bare line: ' + repr(line))
line = prepare_text_line(line)
if TRACE_TOK:
logger_debug(' get_tokens: preped line: ' + repr(line))
pos = 0
for tok in splitter(line):
# strip trailing quotes+comma
if tok.endswith("',"):
tok = tok.rstrip("',")
tok = (
tok
.strip("' ") # strip leading and trailing single quotes, and spaces
.rstrip(':') # strip trailing colons
.strip()
)
# the tokenizer allows a sinble colon or dot to be atoken and we discard these
if tok and tok not in ':.':
yield Token(value=tok, start_line=start_line, pos=pos)
pos += 1
class Detection:
def to_dict(self):
"""
Return a dict of primitive Python types.
"""
return attr.asdict(self)
@classmethod
def split(cls, detections, to_dict=False):
"""
Return a list of CopyrightDetection, a list of HolderDetection and a
list of AuthorDetection given a ``detections`` list of Detection.
If ``to_dict`` is True, return lists of mappings instead of objects.
"""
copyrights = []
holders = []
authors = []
for detection in detections:
det = detection.to_dict() if to_dict else detection
if isinstance(detection, CopyrightDetection):
copyrights.append(det)
elif isinstance(detection, HolderDetection):
holders.append(det)
elif isinstance(detection, AuthorDetection):
authors.append(det)
return copyrights, holders, authors
@classmethod
def split_values(cls, detections):
"""
Return a list of copyright strings, a list of holder strings and a
list of author strings given a ``detections`` list of Detection.
"""
copyrights, holders, authors = cls.split(detections)
copyrights = [det.copyright for det in copyrights]
holders = [det.holder for det in holders]
authors = [det.author for det in authors]
return copyrights, holders, authors
@attr.s(slots=True)
class CopyrightDetection(Detection):
copyright = attr.ib()
start_line = attr.ib()
end_line = attr.ib()
@attr.s(slots=True)
class HolderDetection(Detection):
holder = attr.ib()
start_line = attr.ib()
end_line = attr.ib()
@attr.s(slots=True)
class AuthorDetection(Detection):
author = attr.ib()
start_line = attr.ib()
end_line = attr.ib()
def build_detection_from_node(
node,
cls,
ignores=frozenset(),
include_copyright_allrights=False,
refiner=None,
junk=frozenset(),
junk_patterns=frozenset(),
):
"""
Return a ``cls`` Detection object from a pygmars.tree.Tree ``node`` with a
space-normalized string value or None.
Filter ``node`` Tokens with a type found in the ``ignores`` set of ignorable
token types.
For copyright detection, include trailing "All rights reserved" if
``include_copyright_allrights`` is True.
Apply the ``refiner`` callable function to the detection string.
Return None if the value exists in the ``junk`` strings set or is matched by
any of the regex in the ``junk_patterns`` set.
"""
include_copyright_allrights = (
cls == CopyrightDetection
and include_copyright_allrights
)
if ignores:
leaves = [
token for token in node.leaves()
if token.label not in ignores
]
else:
leaves = node.leaves()
# if TRACE_DEEP: logger_debug(' starting leaves:', leaves)
if include_copyright_allrights:
filtered = leaves
else:
filtered = []
for token in leaves:
# FIXME: this should operate on the tree and not on the leaves
# ALLRIGHTRESERVED: <NNP|NN|CAPS> <RIGHT> <NNP|NN|CAPS>? <RESERVED>
# This pops ALL RIGHT RESERVED by finding it backwards from RESERVED
if token.label == 'RESERVED':
if (
len(filtered) >= 2
and filtered[-1].label == 'RIGHT'
and filtered[-2].label in ('NN', 'CAPS', 'NNP')
):
filtered = filtered[:-2]
elif (
len(filtered) >= 3
and filtered[-1].label in ('NN', 'CAPS', 'NNP')
and filtered[-2].label == 'RIGHT'
and filtered[-3].label in ('NN', 'CAPS', 'NNP')
):
filtered = filtered[:-3]
else:
filtered.append(token)
node_string = ' '.join(t.value for t in filtered)
node_string = ' '.join(node_string.split())
if refiner:
node_string = refiner(node_string)
if node_string and not is_junk_copyryright(node_string):
start_line = filtered[0].start_line
end_line = filtered[-1].start_line
return cls(node_string, start_line=start_line, end_line=end_line)
################################################################################
# LEXING AND PARSING
################################################################################
_YEAR = (r'('
'19[6-9][0-9]' # 1960 to 1999
'|'
'20[0-3][0-9]' # 2000 to 2019
')')
_YEAR_SHORT = (r'('
'[6-9][0-9]' # 60 to 99
'|'
'[0-][0-9]' # 00 to 29
')')
_YEAR_YEAR = (r'('
# fixme v ....the underscore below is suspicious
'(19[6-9][0-9][\\.,\\-]_)+[6-9][0-9]' # 1960-99
'|'
'(19[6-9][0-9][\\.,\\-])+[0-9]' # 1998-9
'|'
'(20[0-3][0-9][\\.,\\-])+[0-2][0-9]' # 2001-16 or 2012-04
'|'
'(20[0-3][0-9][\\.,\\-])+[0-9]' # 2001-4 not 2012
'|'
'(20[0-3][0-9][\\.,\\-])+20[0-3][0-9]' # 2001-2012
')')
_PUNCT = (
r'('
r'['
fr'{re.escape(string.punctuation)}' # standard punctuation (ASCII)
r'i' # oddity
r']'
r'|'
r'\\ ' # html entity sometimes are double escaped
r')*'
) # repeated 0 or more times
_YEAR_PUNCT = _YEAR + _PUNCT
_YEAR_YEAR_PUNCT = _YEAR_YEAR + _PUNCT
_YEAR_SHORT_PUNCT = _YEAR_SHORT + _PUNCT
_YEAR_OR_YEAR_YEAR_WITH_PUNCT = fr'({_YEAR_PUNCT}|{_YEAR_YEAR_PUNCT})'
_YEAR_THEN_YEAR_SHORT = fr'({_YEAR_OR_YEAR_YEAR_WITH_PUNCT}({_YEAR_SHORT_PUNCT})*)'
_YEAR_DASH_PRESENT = _YEAR + r'[\-~]? ?[Pp]resent\.?,?'
patterns = [
############################################################################
# COPYRIGHT
############################################################################
# some exceptions
# NOT a copyright Copyright.txt : treat as NN
(r'^Copyright\.txt$', 'NN'),
# when lowercase with trailing period. this is not a Copyright statement
(r'^copyright\.\)?$', 'NN'),
# NOT a copyright symbol (ie. "copyrighted."): treat as NN
(r'^[Cc]opyrighted[\.,\)]$', 'NN'),
(r'^[Cc]opyrights[\.,\)]$', 'NN'),
(r'^[Cc]opyrighted[\.,\)]$', 'NN'),
(r'^[Cc]opyrights[\.,\)]$', 'NN'),
(r'^COPYRIGHTS[\.,\)]$', 'NN'),
(r'^COPYRIGHTED[\.,\)]$', 'NN'),
# copyright word or symbol
(r'^[\(\.@_\-\#\):]*[Cc]opyrights?:?$', 'COPY'),
(r'^[\(\.@_]*COPYRIGHT[sS]?:?$', 'COPY'),
(r'^[\(\.@]*[Cc]opyrighted?:?$', 'COPY'),
(r'^[\(\.@]*COPYRIGHTED?:?$', 'COPY'),
(r'^[\(\.@]*CopyRights?:?$', 'COPY'),
# TODO: add other languages
# Chinese: 版权 and 版權
# Czech: autorská práva
# Greek: πνευματική ιδιοκτησία
# Hebrew: זכויות יוצרים
# Japanese: 著作権
# Korean: 저작권
# Russian: Авторские права
# Slovenian: avtorske pravice
# Ukrainian: авторське право
# rare typo copyrighy
(r'^Copyrighy$', 'COPY'),
# OSGI
(r'^Bundle-Copyright', 'COPY'),
# (c)opyright and (c)opyleft, we ignore case
(r'^(?i:\(c\)opy(rights?|righted|left))$', 'COPY'),
# truncated opyright and opyleft, we ignore case
(r'^(?i:opy(rights?|righted|left|lefted)[\.\,]?)$', 'COPY'),
(r'^//opylefted$', 'COPY'),
(r"^c'opylefted$", 'COPY'),
# typo in cppyright
(r'^[Cc]ppyright[\.\,]?$', 'COPY'),
# with a trailing comma
(r'^Copyright,$', 'COPY'),
# with a trailing quote and HTML bracket
(r"^[Cc]opyright'>$", 'COPY'),
# as javadoc
(r'^@[Cc]opyrights?:?$', 'COPY'),
(r'^\(C\)\,?$', 'COPY'),
(r'^\(c\)\,?$', 'COPY'),
(r'^COPR\.?$', 'COPY'),
(r'^copr\.?$', 'COPY'),
(r'^Copr\.?$', 'COPY'),
# copyright in markup, until we strip markup: apache'>Copyright
(r'[A-Za-z0-9]+[\'">]+[Cc]opyright', 'COPY'),
# A copyright line in some manifest, meta or structured files such Windows PE
(r'^AssemblyCopyright.?$', 'COPY'),
(r'^AppCopyright?$', 'COPY'),
# seen in binaries
(r'^[A-Z]Copyright?$', 'COPY'),
# SPDX-FileCopyrightText as defined by the FSFE Reuse project
# SPDX-SnippetCopyrightText seen in the wild
(r'^[Ss][Pp][Dd][Xx]-(?:[Ff]ile|[Sn]nippet)[Cc]opyright[Tt]ext', 'COPY'),
# SPDX-FileContributor as defined in SPDX and seen used in KDE
(r'^[Ss][Pp][Dd][Xx]-[Ff]ile[Cc]ontributor', 'SPDX-CONTRIB'),
############################################################################
# ALL Rights Reserved.
############################################################################
# All|Some|No Rights Reserved. should be a terminator/delimiter.
(r'^All$', 'NN'),
(r'^all$', 'NN'),
(r'^ALL$', 'NN'),
(r'^NO$', 'NN'),
(r'^No$', 'NN'),
(r'^no$', 'NN'),
(r'^Some$', 'NN'),
(r'^[Rr]ights?$', 'RIGHT'),
(r'^RIGHTS?$', 'RIGHT'),
(r'^[Rr]eserved[\.,]*$', 'RESERVED'),
(r'^RESERVED[\.,]*$', 'RESERVED'),
# this is really reversed, seen in some pranky statements in copyleft notices
(r'^[Rr]eversed[\.,]*$', 'RESERVED'),
(r'^REVERSED[\.,]*$', 'RESERVED'),
# in German
(r'^[Aa]lle$', 'NN'),
(r'^[Rr]echte$', 'RIGHT'),
(r'^[Vv]orbehalten[\.,]*$', 'RESERVED'),
# in French
(r'^[Tt]ous$', 'NN'),
(r'^[Dr]roits?$', 'RIGHT'),
(r'^[Rr]éservés[\.,]*$', 'RESERVED'),
(r'^[Rr]eserves[\.,]*$', 'RESERVED'),
# TODO: in Dutch Alle rechten voorbehouden.
# TODO: in Spanish Reservados todos los derechos
############################################################################
# JUNK are things to ignore
# Exceptions to JUNK
############################################################################
# trailing parens: notice(s) and exceptions
(r'^Special$', 'NN'),
(r"^Member\(s\)[\.,]?$", 'NNP'),
(r"^__authors?__$", 'AUTHS'),
(r"^__contributors?__$", 'AUTHS'),
(r"^Author\(s\)[\.,:]?$", 'AUTHS'),
(r"^[A-a]ffiliate\(s\)[\.,:]?$", 'COMP'),
# Exceptions to short mixed caps with trailing cap
(r"ApS$", 'COMP'),
# short two chars as B3
(r"^[A-Z][0-9]$", 'NN'),
# Short words skipping some leading caps
(r'^[BEFHJMNPQRTUVW][a-z]$', 'NN'),
# misc exceptions
(r'^dead_horse$', 'NN'),
(r'^A11yance', 'NNP'),
(r'^Fu$', 'NNP'),
(r'^W3C\(r\)$', 'COMP'),
############################################################################
# JUNK proper
############################################################################
# path with trailing year-like are NOT a year as in
# Landroid/icu/impl/IDNA2003 : treat as JUNK
(r'^[^\\/]+[\\/][^\\/]+[\\/].*$', 'JUNK'),
# Combo of many (3+) letters and punctuations groups without spaces is likely junk
# "AEO>>,o>>'!xeoI?o?O1/4thuA/"
# (r'((\w+\W+){3,})+', 'JUNK'),
# CamELCaseeXXX is typcally JUNK such as code variable names
# AzaAzaaaAz BBSDSB002923,
(r'^([A-Z][a-z]+){3,20}[A-Z]+[0-9]*,?$', 'JUNK'),
# multiple parens (at least two (x) groups) is a sign of junk
# such as in (1)(ii)(OCT
(r'^.*\(.*\).*\(.*\).*$', 'JUNK'),
# parens such as (1) or (a) is a sign of junk but of course NOT (c)
(r'^\(([abdefghi\d]|ii|iii)\)$', 'JUNK'),
# @link in javadoc is not a NN
(r'^@?link:?$', 'JUNK'),
(r'@license:?$', 'JUNK'),
# found in crypto certificates and LDAP
(r'^O=$', 'JUNK'),
(r'^OU=?$', 'JUNK'),
(r'^XML$', 'JUNK'),
(r'^Parser$', 'JUNK'),
(r'^Dual$', 'JUNK'),
(r'^Crypto$', 'JUNK'),
(r'^PART$', 'JUNK'),
(r'^[Oo]riginally?$', 'JUNK'),
(r'^[Rr]epresentations?\.?$', 'JUNK'),
(r'^works,$', 'JUNK'),
(r'^Refer$', 'JUNK'),
(r'^Apt$', 'JUNK'),
(r'^Agreement$', 'JUNK'),
(r'^Usage$', 'JUNK'),
(r'^Please$', 'JUNK'),
(r'^\(?Based$', 'JUNK'),
(r'^Upstream$', 'JUNK'),
(r'^Files?$', 'JUNK'),
(r'^Filename:?$', 'JUNK'),
(r'^Description:?$', 'JUNK'),
(r'^[Pp]rocedures?$', 'JUNK'),
(r'^You$', 'JUNK'),
(r'^Everyone$', 'JUNK'),
(r'^[Ff]unded$', 'JUNK'),
(r'^Unless$', 'JUNK'),
(r'^rant$', 'JUNK'),
(r'^Subject$', 'JUNK'),
(r'^Acknowledgements?$', 'JUNK'),
(r'^Derivative$', 'JUNK'),
(r'^[Ll]icensable$', 'JUNK'),
(r'^[Ss]ince$', 'JUNK'),
(r'^[Ll]icen[cs]e[\.d]?$', 'JUNK'),
(r'^[Ll]icen[cs]ors?$', 'JUNK'),
(r'^under$', 'JUNK'),
(r'^TCK$', 'JUNK'),
(r'^Use$', 'JUNK'),
(r'^[Rr]estrictions?$', 'JUNK'),
(r'^[Ii]ntrodu`?ction$', 'JUNK'),
(r'^[Ii]ncludes?$', 'JUNK'),
(r'^[Vv]oluntary$', 'JUNK'),
(r'^[Cc]ontributions?$', 'JUNK'),
(r'^[Mm]odifications?$', 'JUNK'),
(r'^Company:$', 'JUNK'),
(r'^For$', 'JUNK'),
(r'^File$', 'JUNK'),
(r'^Last$', 'JUNK'),
(r'^[Rr]eleased?$', 'JUNK'),
(r'^[Cc]opyrighting$', 'JUNK'),
(r'^[Aa]uthori.*$', 'JUNK'),
(r'^such$', 'JUNK'),
(r'^[Aa]ssignments?[.,]?$', 'JUNK'),
(r'^[Bb]uild$', 'JUNK'),
(r'^[Ss]tring$', 'JUNK'),
(r'^Implementation-Vendor$', 'JUNK'),
(r'^dnl$', 'JUNK'),
(r'^rem$', 'JUNK'),
(r'^REM$', 'JUNK'),
(r'^Supports$', 'JUNK'),
(r'^Separator$', 'JUNK'),
(r'^\.byte$', 'JUNK'),
(r'^Idata$', 'JUNK'),
(r'^[Cc]ontributed?$', 'JUNK'),
(r'^[Ff]unctions?$', 'JUNK'),
(r'^[Nn]otices?$', 'JUNK'),
(r'^[Mm]ust$', 'JUNK'),
(r'^ISUPPER?$', 'JUNK'),
(r'^ISLOWER$', 'JUNK'),
(r'^AppPublisher$', 'JUNK'),
(r'^DISCLAIMS?$', 'JUNK'),
(r'^SPECIFICALLY$', 'JUNK'),
(r'^IDENTIFICATION$', 'JUNK'),
(r'^WARRANTIE?S?$', 'JUNK'),
(r'^WARRANTS?$', 'JUNK'),
(r'^WARRANTYS?$', 'JUNK'),
(r'^hispagestyle$', 'JUNK'),
(r'^Generic$', 'JUNK'),
(r'^generate-', 'JUNK'),
(r'^Change$', 'JUNK'),
(r'^Add$', 'JUNK'),
(r'^Average$', 'JUNK'),
(r'^Taken$', 'JUNK'),
(r'^LAWS\.?$', 'JUNK'),
(r'^design$', 'JUNK'),
(r'^Driver$', 'JUNK'),
(r'^[Cc]ontribution\.?', 'JUNK'),
(r'DeclareUnicodeCharacter$', 'JUNK'),
(r'^Language-Team$', 'JUNK'),
(r'^Last-Translator$', 'JUNK'),
(r'^OMAP730$', 'JUNK'),
(r'^Law\.$', 'JUNK'),
(r'^dylid$', 'JUNK'),
(r'^BeOS$', 'JUNK'),
(r'^Generates?$', 'JUNK'),
(r'^Thanks?$', 'JUNK'),
(r'^therein$', 'JUNK'),
(r'^their$', 'JUNK'),
# various programming constructs
(r'^var$', 'JUNK'),
(r'^[Tt]his$', 'JUNK'),
(r'^thats?$', 'JUNK'),
(r'^xmlns$', 'JUNK'),
(r'^file$', 'JUNK'),
(r'^[Aa]sync$', 'JUNK'),
(r'^Keyspan$', 'JUNK'),
(r'^grunt.template', 'JUNK'),
(r'^else', 'JUNK'),
(r'^constructor.$', 'JUNK'),
(r'^(if|elsif|elif|self|catch|this|else|switch|type|typeof|case|pos|break|[Nn]one|null|var|return|def|function|method|var).?$', 'JUNK'),
(r'^.?(null|function|try|catch|except|throw|typeof|catch|switch).?$', 'JUNK'),
(r'^.*[\.:](?:value|ref|key|case|type|typeof|props|state|error|null)$', 'JUNK'),
(r'^[a-z]{,5}\[!?]+', 'JUNK'),
# func call with short var in minified code
(r'^\w{2,6}\([a-z, ]{1,6}\)', 'JUNK'),
# neither and nor conjunctions and some common licensing words are NOT part
# of a copyright statement
(r'^neither$', 'JUNK'),
(r'^nor$', 'JUNK'),
(r'^data-.*$', 'JUNK'),
(r'^providing$', 'JUNK'),
(r'^Execute$', 'JUNK'),
(r'^NOTICE[.,]*$', 'JUNK'),
(r'^[Nn]otice[.,]*$', 'JUNK'),
(r'^passes$', 'JUNK'),
(r'^Should$', 'JUNK'),
(r'^[Ll]icensing\@?$', 'JUNK'),
(r'^Disclaimer$', 'JUNK'),
(r'^LAWS\,?$', 'JUNK'),
(r'^[Ll]aws?,?$', 'JUNK'),
(r'^me$', 'JUNK'),
(r'^Derived$', 'JUNK'),
(r'^Limitations?$', 'JUNK'),
(r'^Nothing$', 'JUNK'),
(r'^Policy$', 'JUNK'),
(r'^available$', 'JUNK'),
(r'^Recipient\.?$', 'JUNK'),
(r'^LICEN[CS]EES?\.?$', 'JUNK'),
(r'^[Ll]icen[cs]ees?,?$', 'JUNK'),
(r'^Application$', 'JUNK'),
(r'^Receiving$', 'JUNK'),
(r'^Party$', 'JUNK'),
(r'^interfaces$', 'JUNK'),
(r'^owner$', 'JUNK'),
(r'^Sui$', 'JUNK'),
(r'^Generis$', 'JUNK'),
(r'^Conditioned$', 'JUNK'),
(r'^Disclaimer$', 'JUNK'),
(r'^Warranty$', 'JUNK'),
(r'^Configure$', 'JUNK'),
(r'^Excluded$', 'JUNK'),
(r'^Represents$', 'JUNK'),
(r'^Sufficient$', 'JUNK'),
(r'^Each$', 'JUNK'),
(r'^Partially$', 'JUNK'),
(r'^Limitation$', 'JUNK'),
(r'^Liability$', 'JUNK'),
(r'^Named$', 'JUNK'),
(r'^defaults?$', 'JUNK'),
(r'^Use.$', 'JUNK'),
(r'^EXCEPT$', 'JUNK'),
(r'^OWNER\.?$', 'JUNK'),
(r'^Comments\.?$', 'JUNK'),
(r'^you$', 'JUNK'),
(r'^means$', 'JUNK'),
(r'^information$', 'JUNK'),
(r'^[Aa]lternatively.?$', 'JUNK'),
(r'^[Aa]lternately.?$', 'JUNK'),
(r'^INFRINGEMENT.?$', 'JUNK'),
(r'^Install$', 'JUNK'),
(r'^Updates$', 'JUNK'),
(r'^Record-keeping$', 'JUNK'),
(r'^Privacy$', 'JUNK'),
(r'^within$', 'JUNK'),
# various trailing words that are junk
(r'^Copyleft$', 'JUNK'),
(r'^LegalCopyright$', 'JUNK'),
(r'^Report$', 'JUNK'),
(r'^Available$', 'JUNK'),
(r'^true$', 'JUNK'),
(r'^false$', 'JUNK'),
(r'^node$', 'JUNK'),
(r'^jshint$', 'JUNK'),
(r'^node\':true$', 'JUNK'),
(r'^node:true$', 'JUNK'),
(r'^this$', 'JUNK'),
(r'^Act,?$', 'JUNK'),
(r'^[Ff]unctionality$', 'JUNK'),
(r'^bgcolor$', 'JUNK'),
(r'^F+$', 'JUNK'),
(r'^Rewrote$', 'JUNK'),
(r'^Much$', 'JUNK'),
(r'^remains?,?$', 'JUNK'),
(r'^earlier$', 'JUNK'),
(r'^is$', 'JUNK'),
(r'^[lL]aws?$', 'JUNK'),
(r'^Insert$', 'JUNK'),
(r'^url$', 'JUNK'),
(r'^[Ss]ee$', 'JUNK'),
(r'^[Pp]ackage\.?$', 'JUNK'),
(r'^Covered$', 'JUNK'),
(r'^date$', 'JUNK'),
(r'^practices$', 'JUNK'),
(r'^[Aa]ny$', 'JUNK'),
(r'^ANY$', 'JUNK'),
(r'^fprintf.*$', 'JUNK'),
(r'^CURDIR$', 'JUNK'),
(r'^Environment/Libraries$', 'JUNK'),
(r'^Environment/Base$', 'JUNK'),
(r'^Violations\.?$', 'JUNK'),
(r'^Owner$', 'JUNK'),
(r'^behalf$', 'JUNK'),
(r'^know-how$', 'JUNK'),
(r'^interfaces?,?$', 'JUNK'),
(r'^than$', 'JUNK'),
(r'^whom$', 'JUNK'),
(r'^are$', 'JUNK'),
(r'^However,?$', 'JUNK'),
(r'^[Cc]ollectively$', 'JUNK'),
(r'^following$', 'JUNK'),
(r'^[Cc]onfig$', 'JUNK'),
(r'^file\.$', 'JUNK'),
# version variables listed after Copyright variable in FFmpeg
(r'^ExifVersion$', 'JUNK'),
(r'^FlashpixVersion$', 'JUNK'),
(r'^.+ArmsAndLegs$', 'JUNK'),