Skip to content

Commit 1ebd0dc

Browse files
committed
Fix author detection for compact dotted names
Signed-off-by: Hrithik Sharma <sharmahrithik2806@gmail.com>
1 parent 058f439 commit 1ebd0dc

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/cluecode/copyrights.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,15 @@ def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split):
431431
# space before in some cases: exclude (digit , (s , (c , (-
432432
# this allows to recover from words like KISA(Korean
433433
line = re.sub(pattern=r'(\([^rsc\-\d])', repl=r' \g<1>', string=line)
434+
435+
# Split compact author prefixes such as Author:Frankie.Chu while
436+
# preserving colons elsewhere, for example in URLs.
437+
line = re.sub(
438+
pattern=r'(^|\s)([Aa]uthor):(?=\S)',
439+
repl=r'\1\2 ',
440+
string=line,
441+
)
442+
434443
for tok in splitter(line):
435444
# strip trailing quotes+comma
436445
if tok.endswith("',"):
@@ -1805,6 +1814,9 @@ def build_detection_from_node(
18051814
# Proper Nouns
18061815
############################################################################
18071816

1817+
# Dotted proper names such as Frankie.Chu
1818+
(r'^[A-Z][a-z]+(?:\.[A-Z][a-z]+)+$', 'NAME'),
1819+
18081820
# Title case word with a trailing parens is an NNP, including with an optional trailing period
18091821
(r'^[A-Z][a-z]{3,}\)\.?$', 'NNP'),
18101822
# Title case word with a leading parens is an NNP

tests/cluecode/test_copyrights_basic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ def test_detect_with_lines_only_holders(self):
319319
))
320320
assert results == expected
321321

322+
def test_detect_author_without_space_and_with_dotted_name(self):
323+
numbered_lines = [
324+
(1, '// Date:9 April,2012'),
325+
(2, '// Author:Frankie.Chu'),
326+
]
327+
expected = [
328+
copyrights.AuthorDetection('Frankie.Chu', 2, 2),
329+
]
330+
results = list(copyrights.detect_copyrights_from_lines(
331+
numbered_lines,
332+
include_copyrights=False,
333+
include_holders=False,
334+
include_authors=True,
335+
))
336+
assert results == expected
337+
322338

323339
def check_full_detections(expected, test_file):
324340
"""

0 commit comments

Comments
 (0)