Skip to content

Commit

Permalink
feat: add go and ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
k4black committed Nov 17, 2023
1 parent beb64bb commit 3863be4
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
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\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:
Expand Down

0 comments on commit 3863be4

Please sign in to comment.