From 3863be49ee21752cdc8400788d5972998958585f Mon Sep 17 00:00:00 2001 From: Konstantin Chernyshev Date: Fri, 17 Nov 2023 15:07:17 +0100 Subject: [PATCH 1/2] feat: add go and ruby --- README.md | 2 +- codebleu/codebleu.py | 2 +- codebleu/keywords/go.txt | 27 ++++++++++++++++++++++++ codebleu/keywords/python.txt | 3 +++ codebleu/keywords/ruby.txt | 41 ++++++++++++++++++++++++++++++++++++ tests/test_codebleu.py | 2 ++ 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 codebleu/keywords/go.txt create mode 100644 codebleu/keywords/ruby.txt diff --git a/README.md b/README.md index 510e310..dec0ca7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This repository contains an unofficial `CodeBLEU` implementation that supports ` The code is based on the original [CodeXGLUE/CodeBLEU](https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/code-to-code-trans/evaluator/CodeBLEU) and updated version by [XLCoST/CodeBLEU](https://github.com/reddy-lab-code-research/XLCoST/tree/main/code/translation/evaluator/CodeBLEU). It has been refactored, tested, built for macOS, and multiple improvements have been made to enhance usability -Available for: `Python`, `C`, `C#`, `C++`, `Java`, `JavaScript`, `PHP`. +Available for: `Python`, `C`, `C#`, `C++`, `Java`, `JavaScript`, `PHP`, `Go` and `Ruby`. --- diff --git a/codebleu/codebleu.py b/codebleu/codebleu.py index 2e9adbf..f1beb86 100644 --- a/codebleu/codebleu.py +++ b/codebleu/codebleu.py @@ -7,7 +7,7 @@ from . import bleu, dataflow_match, syntax_match, weighted_ngram_match PACKAGE_DIR = Path(__file__).parent -AVAILABLE_LANGS = ["java", "javascript", "c_sharp", "php", "c", "cpp", "python"] # keywords available +AVAILABLE_LANGS = ["java", "javascript", "c_sharp", "php", "c", "cpp", "python", "go", "ruby"] # keywords available def calc_codebleu( diff --git a/codebleu/keywords/go.txt b/codebleu/keywords/go.txt new file mode 100644 index 0000000..893da4a --- /dev/null +++ b/codebleu/keywords/go.txt @@ -0,0 +1,27 @@ +break +default +func +interface +select +case +defer +go +map +struct +chan +else +goto +package +switch +const +fallthrough +if +range +type +continue +for +import +return +var +false +true diff --git a/codebleu/keywords/python.txt b/codebleu/keywords/python.txt index 08c8222..646b998 100644 --- a/codebleu/keywords/python.txt +++ b/codebleu/keywords/python.txt @@ -33,3 +33,6 @@ try while with yield +match +case +type diff --git a/codebleu/keywords/ruby.txt b/codebleu/keywords/ruby.txt new file mode 100644 index 0000000..c26ade8 --- /dev/null +++ b/codebleu/keywords/ruby.txt @@ -0,0 +1,41 @@ +__ENCODING__ +__LINE__ +__FILE__ +BEGIN +END +alias +and +begin +break +case +class +def +defined? +do +else +elsif +end +ensure +false +for +if +in +module +next +nil +not +or +redo +rescue +retry +return +self +super +then +true +undef +unless +until +when +while +yield diff --git a/tests/test_codebleu.py b/tests/test_codebleu.py index 35414be..4abf37f 100644 --- a/tests/test_codebleu.py +++ b/tests/test_codebleu.py @@ -39,6 +39,8 @@ def test_exact_match_works_for_all_langs(lang: str) -> None: ("c_sharp", ["public int foo ( int x ) { return x }"], ["public int bar ( int y ) {\n return y\n}"]), ("cpp", ["int foo ( int x ) { return x }"], ["int bar ( int y ) {\n return y\n}"]), ("php", ["function foo ( x ) { return x }"], ["function bar ( y ) {\n return y\n}"]), + ("go", ["func foo ( x ) { return x }"], ["func bar ( y ) {\n return y\n}"]), + ("ruby", ["def foo(x)\n return x\nend"], ["def bar(y)\n return y\nend"]) ], ) def test_simple_cases_work_for_all_langs(lang: str, predictions: List[Any], references: List[Any]) -> None: From 2d0b120126274d3fe6b72fbd689074910113e807 Mon Sep 17 00:00:00 2001 From: Konstantin Chernyshev Date: Fri, 17 Nov 2023 15:54:51 +0100 Subject: [PATCH 2/2] test: fix ruby simple test --- tests/test_codebleu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_codebleu.py b/tests/test_codebleu.py index 4abf37f..31c0855 100644 --- a/tests/test_codebleu.py +++ b/tests/test_codebleu.py @@ -40,7 +40,7 @@ def test_exact_match_works_for_all_langs(lang: str) -> None: ("cpp", ["int foo ( int x ) { return x }"], ["int bar ( int y ) {\n return y\n}"]), ("php", ["function foo ( x ) { return x }"], ["function bar ( y ) {\n return y\n}"]), ("go", ["func foo ( x ) { return x }"], ["func bar ( y ) {\n return y\n}"]), - ("ruby", ["def foo(x)\n return x\nend"], ["def bar(y)\n return y\nend"]) + ("ruby", ["def foo ( x ) :\n return x"], ["def bar ( y ) :\n return y"]), ], ) def test_simple_cases_work_for_all_langs(lang: str, predictions: List[Any], references: List[Any]) -> None: