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

Ingest RANLP 2019 #731

Merged
merged 17 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
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
31 changes: 30 additions & 1 deletion bin/latex_to_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
# Entry(r'\textsc', None, 'sc', 'unary', False),
# Entry(r'\sc', None, 'sc', 'setter', False),
Entry(r"\url", None, "url", "unary", True),
Entry(r"\footnote", None, "fn", "unary", False),
Entry(r"\href", None, "delete", "unary", False),
# \cite and friends. There are a lot more, but these are the most common.
Entry(r"\cite", None, "cite", "unary", False),
Entry(r"\newcite", None, "cite", "unary", False),
Entry(r"\citet", None, "cite", "unary", False),
Entry(r"\citep", None, "cite", "unary", False),
Entry(r"\fixedcase", None, "fixed-case", "unary", False), # for our internal use
Entry(r"", None, None, "trivial", False),
]
Expand Down Expand Up @@ -185,7 +192,7 @@ def latex_to_unicode(s):
s = s.replace(r"\}", "}")

def repl(s):
logging.warning("discarding control sequence {}".format(s.group(0)))
logging.warning(f"discarding control sequence '{s.group(0)}' from '{s.string}'")
return ""

s = re.sub(r"\\[A-Za-z]+ |\\.", repl, s)
Expand Down Expand Up @@ -223,6 +230,27 @@ def visit(node):
return node


def remove_notes(node):
def visit(node, outparent):
if isinstance(node, str):
outparent.append(node)
elif isinstance(node, list):
if openers[node[0].rstrip()].tag in ["fn", "delete"]:
return # without copying
elif openers[node[0].rstrip()].tag == "cite":
outparent.append("(CITATION)")
else:
outnode = []
for child in node:
visit(child, outnode)
outparent.append(outnode)

outroot = []
visit(node, outroot)
assert len(outroot) == 1
return outroot[0]


def append_text(xnode, text):
if len(xnode) == 0:
xnode.text = (xnode.text or "") + text
Expand Down Expand Up @@ -293,6 +321,7 @@ def latex_to_xml(s, fixed_case=False, trivial_math=False):
tree = find_fixed_case(tree, conservative=True)
if trivial_math:
tree = flatten_trivial_math(tree)
tree = remove_notes(tree)
tree = latextree_to_xml(tree)
tree = xml_to_unicode(tree)
return tree
Expand Down
6 changes: 5 additions & 1 deletion bin/normalize_anth.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ def normalize(oldnode, informat):
)
)
oldtext = "".join(oldnode.itertext())
newnode = latex_to_xml(oldtext, trivial_math=True, fixed_case=True)
newnode = latex_to_xml(
oldtext,
trivial_math=True,
fixed_case=oldnode.tag in ["title", "booktitle"],
)
newnode.tag = oldnode.tag
newnode.attrib.update(oldnode.attrib)
replace_node(oldnode, newnode)
Expand Down
791 changes: 395 additions & 396 deletions data/xml/D19.xml

Large diffs are not rendered by default.

1,751 changes: 1,751 additions & 0 deletions data/xml/R19.xml

Large diffs are not rendered by default.

7,378 changes: 3,689 additions & 3,689 deletions data/xml/W17.xml

Large diffs are not rendered by default.

365 changes: 365 additions & 0 deletions data/xml/W19.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions data/yaml/venues_joint_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,6 @@ D19-65: [WS,DiscoMT]
D19-66: WS
D19-67: WS
D19-68: WS
W19-87: RANLP
W19-89: RANLP
W19-90: RANLP