Skip to content

Commit 42cd565

Browse files
committed
Detect copyright from damaged PDF
Signed-off-by: Philippe Ombredanne <pombredanne@aboutcode.org>
1 parent 7af79eb commit 42cd565

26 files changed

Lines changed: 135 additions & 35 deletions

src/cluecode/copyrights.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def logger_debug(*args):
6161
if TRACE_DEEP:
6262
logger_debug = print
6363

64-
6564
"""
6665
Detect and collect copyright statements.
6766
@@ -427,9 +426,9 @@ def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split):
427426

428427
if TRACE_TOK:
429428
logger_debug(' get_tokens: preped line: ' + repr(line))
430-
429+
431430
# when there is a an openning parens in the middle of a word, add a
432-
# space before in some cases: exclude (digit , (s , (c , (-
431+
# space before in some cases: exclude (digit , (s , (c , (-
433432
line = re.sub(pattern=r'(\([^rsc\-\d])', repl=' \g<1>', string=line, flags=re.IGNORECASE)
434433
for tok in splitter(line):
435434
# strip trailing quotes+comma
@@ -733,8 +732,8 @@ def build_detection_from_node(
733732
(r'^[Ss][Pp][Dd][Xx]-[Ff]ile[Cc]ontributor', 'SPDX-CONTRIB'),
734733

735734
# damaged PDF to text conversion with (cid:13) and rarer (cid:2)
736-
(r'^[Cc]?\(cid:13\)$','COPY'),
737-
(r'^[Cc]?\(cid:2\)$','COPY'),
735+
(r'^[Cc]?\(cid:13\)$', 'COPY'),
736+
(r'^[Cc]?\(cid:2\)$', 'COPY'),
738737

739738
############################################################################
740739
# ALL Rights Reserved.
@@ -821,6 +820,9 @@ def build_detection_from_node(
821820
(r'^W3C\(r\)$', 'COMP'),
822821
(r'^TeX$', 'NNP'),
823822

823+
# Copyright (c) 1989 ITAA, formerly ADAPSO
824+
(r'^formerly', 'NNP'),
825+
824826
# Three or more AsCamelCase GetQueueReference, with some exceptions
825827
(r'^(?:OpenStreetMap|AliasDotCom|AllThingsTalk).?$', 'NAME'),
826828

@@ -1240,6 +1242,9 @@ def build_detection_from_node(
12401242
# owlocationNameEntitieship.
12411243
(r"^([a-z]{2,}[A-Z]){2,}[a-z]+[\.,]?", 'JUNK'),
12421244

1245+
# lower case with (s)
1246+
# but not owner/author(s).
1247+
(r"^owner/author\(s\)\.?$", 'NNP'),
12431248
(r"^[a-z].+\(s\)[\.,]?$", 'JUNK'),
12441249

12451250
# parens in the middle: for(var
@@ -1292,7 +1297,7 @@ def build_detection_from_node(
12921297
(r'^[Bb]oth$', 'JUNK'),
12931298
(r'^[Cc]aller$', 'JUNK'),
12941299

1295-
#'!(r)'
1300+
# '!(r)'
12961301
(r'^!\(r\)$', 'JUNK'),
12971302

12981303
# vars with curly braces
@@ -2248,6 +2253,7 @@ def build_detection_from_node(
22482253
(r"^[a-z]'[A-Z]?[a-z]+[,\.]?$", 'NNP'),
22492254

22502255
# exceptions to all CAPS words
2256+
(r'^ISBN$', 'NN'),
22512257
(r'^[A-Z]{3,4}[0-9]{4},?$', 'NN'),
22522258

22532259
# exceptions to CAPS used in obfuscated emails like in joe AT foo DOT com
@@ -3091,8 +3097,13 @@ def build_detection_from_node(
30913097
# Author: Jeff LaBundy <jeff@labundy.com>
30923098
COPYRIGHT: {<COPY> <COPY> <YR-RANGE> <AUTH> <NAME-EMAIL>} #2280-3
30933099
3100+
# Common for ACM notices
3101+
# Copyright is held by the owner/author(s).
3102+
# (c) 2016 Copyright held by the owner/author(s).
3103+
COPYRIGHT2: {<COPY>+ <YR-RANGE>+ <COPY><IS>?<HELD><BY><NN>?<NNP>} #2280-9
30943104
30953105
COPYRIGHT2: {<COPY>+ <NN|CAPS>? <YR-RANGE>+ <PN>*} #2280
3106+
COPYRIGHT2: {<COPY><IS>?<HELD><BY><NN>?<NNP>} #2280-12
30963107
30973108
COPYRIGHT: {<COPYRIGHT2> <BY> <NAME-YEAR|NAME-EMAIL> <BY>? <NAME-YEAR|NAME-EMAIL>? } #2280-4
30983109
@@ -3122,7 +3133,8 @@ def build_detection_from_node(
31223133
# Rare form Copyright (c) 2008 All rights reserved by Amalasoft Corporation.
31233134
COPYRIGHT: {<COPYRIGHT2> <ALLRIGHTRESERVED> <BY> <COMPANY>} #2861
31243135
3125-
# Copyright (c) 1996 Adrian Rodriguez (adrian@franklins-tower.rutgers.edu) Laboratory for Computer Science Research Computing Facility
3136+
# Copyright (c) 1996 Adrian Rodriguez (adrian@franklins-tower.rutgers.edu) L
3137+
# aboratory for Computer Science Research Computing Facility
31263138
COPYRIGHT: {<COPYRIGHT> <NAME>} #2400
31273139
31283140
# copyrights in the style of Scilab/INRIA
@@ -4029,10 +4041,6 @@ def remove_dupe_copyright_words(c):
40294041
c = c.replace('and later', ' ')
40304042
c = c.replace('build.year', ' ')
40314043

4032-
# PDF to text damages
4033-
c = c.replace('(cid:13)', '(c)')
4034-
c = c.replace('(cid:2)', '(c)')
4035-
40364044
return c
40374045

40384046

@@ -4565,6 +4573,10 @@ def prepare_text_line(line):
45654573
.replace('\xc2', '')
45664574
.replace('\\xc2', '')
45674575

4576+
# PDF to text damages
4577+
.replace('c(cid:13)', '(c) ')
4578+
.replace('c(cid:2)', '(c) ')
4579+
45684580
# not really a dash: an emdash
45694581
.replace('–', '-')
45704582

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
what:
22
- copyrights
33
- holders
4+
copyrights:
5+
- Copyright (c) 2007 KISA (Korea Information Security Agency)
6+
holders:
7+
- KISA (Korea Information Security Agency)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- Copyright (c) 1989 ITAA, formerly ADAPSO, and 1991, 1993
6+
holders:
7+
- ITAA, formerly ADAPSO,
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
c(cid:13) 2016 Copyright held by the owner/author(s).
1+
c(cid:13) 2016 Copyright held by the owner/author(s).
2+
3+
4+
(c) 2016 Copyright held by the owner/author(s).
5+
6+
7+
Copyright held by the owner/author(s).
8+
9+
10+
Copyright is held by the owner/author(s)
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- (c) 2016 Copyright held by the owner/author(s)
6+
- (c) 2016 Copyright held by the owner/author(s)
7+
- Copyright held by the owner/author(s)
8+
- Copyright is held by the owner/author(s)
9+
holders:
10+
- the owner/author(s)
11+
- the owner/author(s)
12+
- the owner/author(s)
13+
- the owner/author(s)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- (c) BANDAI NAMCO Entertainment Inc.
6+
- Copyright (c) 2017 Live2D Inc.
7+
holders:
8+
- BANDAI NAMCO Entertainment Inc.
9+
- Live2D Inc.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- Copyright (c) 2006, American Association for Articial Intelli- gence (www.aaai.org)
6+
holders:
7+
- American Association for Articial Intelli- gence
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- (c) 2016 ACM.
6+
holders:
7+
- ACM
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- Copyright (c) 2006
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
what:
22
- copyrights
33
- holders
4-
- holders_summary
4+
copyrights:
5+
- Crown copyright 2017
6+
holders:
7+
- Crown

0 commit comments

Comments
 (0)