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

Changes "duplicates_list" to "duplicates_dict" (since it's dict) #265

Merged
merged 1 commit into from
Aug 22, 2022
Merged
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
6 changes: 3 additions & 3 deletions measurements/text_duplicates/text_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

Returns:
`duplicate_fraction` (`float`) : the fraction of strings that are duplicated.
`duplicates_list` (`dict`) (optional) : a dictionary containing tuples with the duplicate strings and the number of times they are repeated.
`duplicates_dict` (`dict`) (optional) : a dictionary containing tuples with the duplicate strings and the number of times they are repeated.

Examples:
>>> data = ["hello sun","hello moon", "hello sun"]
Expand All @@ -45,7 +45,7 @@
>>> duplicates = evaluate.load("text_duplicates")
>>> results = duplicates.compute(data=data, list_duplicates=True)
>>> print(results)
{'duplicate_fraction': 0.33333333333333337, 'duplicates_list': {'hello sun': 2}}
{'duplicate_fraction': 0.33333333333333337, 'duplicates_dict': {'hello sun': 2}}
"""

# TODO: Add BibTeX citation
Expand Down Expand Up @@ -84,7 +84,7 @@ def _compute(self, data, list_duplicates=False):
n_dedup = len(set([get_hash(d) for d in data]))
c = Counter(data)
duplicates = {k: v for k, v in c.items() if v > 1}
return {"duplicate_fraction": 1 - (n_dedup / len(data)), "duplicates_list": duplicates}
return {"duplicate_fraction": 1 - (n_dedup / len(data)), "duplicates_dict": duplicates}
else:
n_dedup = len(set([get_hash(d) for d in data]))
return {"duplicate_fraction": 1 - (n_dedup / len(data))}