Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add go and ruby support #12

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

---

Expand Down
2 changes: 1 addition & 1 deletion codebleu/codebleu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 27 additions & 0 deletions codebleu/keywords/go.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions codebleu/keywords/python.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ try
while
with
yield
match
case
type
41 changes: 41 additions & 0 deletions codebleu/keywords/ruby.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/test_codebleu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"], ["def bar ( y ) :\n return y"]),
],
)
def test_simple_cases_work_for_all_langs(lang: str, predictions: List[Any], references: List[Any]) -> None:
Expand Down