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

Create papers2sheet.py #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions bin/papers2sheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Converts papers.xml (extracted from OpenReview) into a tab-separated file to be copy-pasted
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: xml -> yml

# to a Google sheet for workshop chairs (use Ctrl+Shift+V)
#
# Ivan Habernal, July 2024
# MIT License

from pathlib import Path
from typing import List
import yaml


def generate_sheet_tsv(input_file_yml: Path, output_file_tsv: Path) -> None:
yaml_load: List[dict] = yaml.safe_load(input_file_yml.read_text('utf-8'))

with open(output_file_tsv, 'wt', encoding='utf-8') as output_f:
# Iterate over papers
for entry in yaml_load:
# print(entry.keys())
# -> abstract', 'attributes', 'authors', 'file', 'id', 'openreview_id', 'pdf_file', 'title

# Single paper output container
single_output_line_list: List[str] = []

# Paper ID
single_output_line_list.append(entry.get('id'))
# Title
single_output_line_list.append(entry.get('title'))
# Abstract to a single line
single_output_line_list.append(entry.get('abstract').replace('\n', ' '))

# Collect authors
authors: List[dict] = entry.get('authors')
for author in authors:
# keys: ['emails', 'first_name', 'google_scholar_id', 'homepage', 'last_name', 'name', 'username'])
# We need: author X first name; author X last name; author X email
single_output_line_list.append(author.get('first_name'))
single_output_line_list.append(author.get('last_name'))
single_output_line_list.append(author.get('emails'))

# explicitly re-type to string ... because yaml and Python
output_line = '\t'.join([str(_) for _ in single_output_line_list])
print(output_line)

output_f.write(output_line + '\n')


if __name__ == '__main__':
# example usage
generate_sheet_tsv(Path('examples/privatenlp24ws/papers.yml'),
Path('examples/privatenlp24ws/papers.tsv'))