Skip to content

Commit

Permalink
Fix empty answers in majority voting
Browse files Browse the repository at this point in the history
  • Loading branch information
tongyx361 committed Sep 14, 2024
1 parent 372ae07 commit c9f5cad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ test_eq(math_evaluator.eq("\\frac{2003}{2}", "1001"), False)
#### Normalized Majority Voting

``` python
math_evaluator.get_maj_answers(["1", "2", "3", "3", "3"])
math_evaluator.get_maj_answers(["", "", "1", "2", "2", "3", "3", "3"])
```

['1', '1', '1', '3', '3']
['', '', '1', '1', '2', '2', '2', '3']

### Parsing LaTeX

Expand Down
4 changes: 2 additions & 2 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
{
"data": {
"text/plain": [
"['1', '1', '1', '3', '3']"
"['', '', '1', '1', '2', '2', '2', '3']"
]
},
"execution_count": null,
Expand All @@ -511,7 +511,7 @@
}
],
"source": [
"math_evaluator.get_maj_answers([\"1\", \"2\", \"3\", \"3\", \"3\"])"
"math_evaluator.get_maj_answers([\"\", \"\", \"1\", \"2\", \"2\", \"3\", \"3\", \"3\"])"
]
},
{
Expand Down
8 changes: 5 additions & 3 deletions symeval/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def get_maj_answers(self, answers: List[str]) -> List[str]:
break
else:
ans_votes[answer] += 1
maj_ans: str = ans_votes.most_common(1)[0][0]
maj_ans = ans_votes.most_common(1)[0][0]
if maj_ans == "" and len(ans_votes) > 1:
maj_ans = ans_votes.most_common(2)[1][0]
maj_answers.append(maj_ans)

return maj_answers
Expand Down Expand Up @@ -506,14 +508,14 @@ def latex2sympy_interval(
DEF_PERCENT_REL_TOL = 1e-3


def has_non_ascii(s) -> bool:
def has_non_ascii(s: str) -> bool:
for char in s:
if ord(char) > 127:
return True
return False


def is_querying4set(query) -> bool:
def is_querying4set(query: str) -> bool:
return "ind the" in query or ("all" in query and "separate" in query)


Expand Down

0 comments on commit c9f5cad

Please sign in to comment.