-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathdata.py
127 lines (104 loc) · 4.11 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -*- coding: utf-8 -*-
#
# Copyright 2019 Marcel Bollmann <marcel@bollmann.me>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
# This file contains all constants and functions that have hardcoded data (such
# as URLs or journal titles) which does not come from the XML. This is to
# provide a single file where such hardcoded data can be looked up and/or
# changed.
################################################################################
import os
from enum import Enum
# this is the canonical URL. In contrast to all other
# URL templates, it always links to the official anthology.
CANONICAL_URL_TEMPLATE = "https://aclanthology.org/{}"
# the prefix is used in different programs and we need to set it everywhere
# We use a environment variable to set this and not have to forward the value
# through all the programs. If this does not look like the best idea, keep in mind
# that the structure is historically grown -- from 2019 to 2020 :-)
try:
ANTHOLOGY_PREFIX = os.environ["ANTHOLOGY_PREFIX"]
except:
ANTHOLOGY_PREFIX = "https://aclanthology.org"
ATTACHMENT_PREFIX = ANTHOLOGY_PREFIX + "/attachments"
ATTACHMENT_TEMPLATE = ATTACHMENT_PREFIX + "/{}"
PDF_LOCATION_TEMPLATE = ANTHOLOGY_PREFIX + "/{}.pdf"
PDF_THUMBNAIL_LOCATION_TEMPLATE = ANTHOLOGY_PREFIX + "/thumb/{}.jpg"
VIDEO_LOCATION_TEMPLATE = ANTHOLOGY_PREFIX + "/{}"
# Regular expression matching full Anthology IDs
ANTHOLOGY_ID_REGEX = r"[A-Z]\d{2}-\d{4}"
# Anthology file location on server
# Defaults to ~/anthology-files
ANTHOLOGY_FILE_DIR = os.environ.get(
"ANTHOLOGY_FILES", os.path.join(os.environ["HOME"], "anthology-files")
)
# Anthology pdf location
# Defaults to {ANTHOLOGY_FILE_DIR}/pdf
ANTHOLOGY_PDF_DIR = os.environ.get(
"ANTHOLOGY_PDFS", os.path.join(ANTHOLOGY_FILE_DIR, "pdf")
)
# Anthology attachments location
# Defaults to {ANTHOLOGY_FILE_DIR}/attachments
ANTHOLOGY_ATTACHMENTS_DIR = os.environ.get(
"ANTHOLOGY_ATTACHMENTS", os.path.join(ANTHOLOGY_FILE_DIR, "attachments")
)
# Anthology data location
# Defaults to {git_repo_root}/data
_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
ANTHOLOGY_DATA_DIR = os.environ.get(
"ANTHOLOGY_DATA", os.path.abspath(os.path.join(_SCRIPT_DIR, "..", "..", "data"))
)
# Names of XML elements that may appear multiple times
LIST_ELEMENTS = (
"attachment",
"author",
"editor",
"video",
"revision",
"erratum",
"award",
"pwcdataset",
"video",
"venue",
"colocated",
)
# New-style IDs that should be handled as journals
JOURNAL_IDS = ("cl", "tacl")
# Constants associated with DOI assignation
DOI_URL_PREFIX = "https://dx.doi.org/"
DOI_PREFIX = "10.18653/v1/"
# Default ingestion date (= unknown)
UNKNOWN_INGEST_DATE = "1900-01-01"
# The venue format must match this pattern
VENUE_FORMAT = r"^[a-z\d]+$"
def get_journal_title(top_level_id, volume_title):
# TODO: consider moving this from code to data (perhaps
# under <booktitle> in the volume metadata
top_level_id = top_level_id.split(".")[-1] # for new-style IDs; is a no-op otherwise
if top_level_id == "cl":
return "Computational Linguistics"
if top_level_id[0] == "J":
year = int(top_level_id[1:3])
if year >= 65 and year <= 83:
return "American Journal of Computational Linguistics"
else:
return "Computational Linguistics"
elif top_level_id[0] == "Q" or top_level_id == "tacl":
return "Transactions of the Association for Computational Linguistics"
else:
return volume_title
class ResourceType(Enum):
PDF = 'pdf'
ATTACHMENT = 'attachments'