diff --git a/AUTHORS.rst b/AUTHORS.rst index 9a8224dc7da..75157485207 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -27,6 +27,7 @@ The following organizations or individuals have contributed to ScanCode: - Daniel Eder @daniel-eder - Dan Kegel @dankegel - Dennis Clark @DennisClark +- Dhruv @DHRUV-1-star - Divyansh Sharma @Divyansh2512 - Duncan Howe @Duncan-Howe - Felix Kauselmann @selmf diff --git a/CHANGELOG.rst b/CHANGELOG.rst index abc3ae41ad2..247b082cdc5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,9 @@ Next release - Improve copyright detection for statements with parens or trailing "authors" +- Improve author detection for compact declarations and dotted author names. + https://github.com/aboutcode-org/scancode-toolkit/issues/4229 + - Add experimental option for using cached results during scan time. When the ``--use-cached-results`` option is enabled in the ScanCode CLI, during scan time for a given Resource, we iterate through the active scanners and see if we diff --git a/src/cluecode/copyrights.py b/src/cluecode/copyrights.py index 29876084168..781621dcc4b 100644 --- a/src/cluecode/copyrights.py +++ b/src/cluecode/copyrights.py @@ -431,6 +431,21 @@ def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split): # space before in some cases: exclude (digit , (s , (c , (- # this allows to recover from words like KISA(Korean line = re.sub(pattern=r'(\([^rsc\-\d])', repl=r' \g<1>', string=line) + + # Split compact author prefix such as Author:Frankie.Chu while + # preserving colons elsewhere (e.g. in URLs). + line = re.sub( + pattern=r'(^|\s)([Aa]uthors?):(?=\S)', + repl=r'\1\2: ', + string=line, + ) + + # Normalize dotted names only when they follow an Author tag. + line = re.sub( + pattern=r'(^|\s)([Aa]uthors?):\s+([A-Z][a-z]+)\.([A-Z][a-z]+)(?=\b|[,;])', + repl=r'\1\2 \3 \4', + string=line, + ) for tok in splitter(line): # strip trailing quotes+comma if tok.endswith("',"): diff --git a/tests/cluecode/test_copyrights_basic.py b/tests/cluecode/test_copyrights_basic.py index 1fbafcf5488..1b6963bd28a 100644 --- a/tests/cluecode/test_copyrights_basic.py +++ b/tests/cluecode/test_copyrights_basic.py @@ -319,6 +319,38 @@ def test_detect_with_lines_only_holders(self): )) assert results == expected + def test_detect_author_without_space_and_with_dotted_name(self): + numbered_lines = [ + (1, '// Date:9 April,2012'), + (2, '// Author:Frankie.Chu'), + ] + expected = [ + copyrights.AuthorDetection('Frankie Chu', 2, 2), + ] + results = list(copyrights.detect_copyrights_from_lines( + numbered_lines, + include_copyrights=False, + include_holders=False, + include_authors=True, + )) + assert results == expected + + def test_detect_author_with_space_and_with_dotted_name(self): + numbered_lines = [ + (1, '// Date:9 April,2012'), + (2, '// Author: Frankie.Chu'), + ] + expected = [ + copyrights.AuthorDetection('Frankie Chu', 2, 2), + ] + results = list(copyrights.detect_copyrights_from_lines( + numbered_lines, + include_copyrights=False, + include_holders=False, + include_authors=True, + )) + assert results == expected + def check_full_detections(expected, test_file): """