Update process_underscores.py
Browse files- process_underscores.py +66 -57
process_underscores.py
CHANGED
@@ -3,18 +3,24 @@ process_underscores.py
|
|
3 |
|
4 |
Script to handle licensed data for which underlying text cannot be posted online (e.g. LDC data).
|
5 |
Users need a copy of the LDC distribution of an underlying resource to restore text in some of the corpora.
|
6 |
-
|
|
|
7 |
"""
|
8 |
|
9 |
__author__ = "Amir Zeldes+Damien Sileo"
|
10 |
__license__ = "Apache 2.0"
|
11 |
-
__version__ = "
|
12 |
|
13 |
import io, re, os, sys
|
14 |
from glob import glob
|
15 |
from collections import defaultdict
|
16 |
from argparse import ArgumentParser
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
PY3 = sys.version_info[0] == 3
|
19 |
if not PY3:
|
20 |
input = raw_input
|
@@ -542,58 +548,61 @@ def restore_docs(text_dict,dep_files=[],rel_files=[],tok_files=[]):
|
|
542 |
sys.stderr.write("o Restored text in " + str(len(dep_files)) + " .conllu files, " + str(len(tok_files)) +
|
543 |
" .tok files and "+ str(len(rel_files)) + " .rels files\n")
|
544 |
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
if
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
if opts.corpus == "pdtb" or opts.corpus == "all":
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
|
|
|
|
|
|
|
3 |
|
4 |
Script to handle licensed data for which underlying text cannot be posted online (e.g. LDC data).
|
5 |
Users need a copy of the LDC distribution of an underlying resource to restore text in some of the corpora.
|
6 |
+
|
7 |
+
|
8 |
"""
|
9 |
|
10 |
__author__ = "Amir Zeldes+Damien Sileo"
|
11 |
__license__ = "Apache 2.0"
|
12 |
+
__version__ = "0.0.0"
|
13 |
|
14 |
import io, re, os, sys
|
15 |
from glob import glob
|
16 |
from collections import defaultdict
|
17 |
from argparse import ArgumentParser
|
18 |
|
19 |
+
class EDict(dict):
|
20 |
+
def __getattr__(self, k): return self.get(k, None)
|
21 |
+
def __setattr__(self, k, v): self[k] = v
|
22 |
+
def __delattr__(self, k): del self[k]
|
23 |
+
|
24 |
PY3 = sys.version_info[0] == 3
|
25 |
if not PY3:
|
26 |
input = raw_input
|
|
|
548 |
sys.stderr.write("o Restored text in " + str(len(dep_files)) + " .conllu files, " + str(len(tok_files)) +
|
549 |
" .tok files and "+ str(len(rel_files)) + " .rels files\n")
|
550 |
|
551 |
+
def run(corpus="all", rel_files=[], dep_files=[], tok_files=[],
|
552 |
+
rstdt_path=None, pdtb_path=None, cdtb_path=None, tdb_path=None):
|
553 |
+
|
554 |
+
opts = EDict(corpus=corpus,
|
555 |
+
rel_files=rel_files,
|
556 |
+
dep_files=dep_files,
|
557 |
+
tok_files=tok_files)
|
558 |
+
todo = {k: v for k, v in opts.items() if 'files' in k}
|
559 |
+
|
560 |
+
if opts.corpus == "rstdt" or opts.corpus == "all":
|
561 |
+
if rstdt_path is None:
|
562 |
+
raise ValueError("rstdt_path is required for corpus rstdt")
|
563 |
+
if not os.path.isdir(rstdt_path):
|
564 |
+
sys.stderr.write("Can't find directory at: " + rstdt_path + "\n")
|
565 |
+
sys.exit(0)
|
566 |
+
files = glob(os.sep.join([rstdt_path, "RSTtrees-WSJ-main-1.0", "TRAINING", "*.edus"])) + \
|
567 |
+
glob(os.sep.join([rstdt_path, "RSTtrees-WSJ-main-1.0", "TEST", "*.edus"]))
|
568 |
+
docs2text = harvest_text(files)
|
569 |
+
restore_docs(docs2text, **todo)
|
570 |
+
|
571 |
+
if opts.corpus == "pdtb" or opts.corpus == "all":
|
572 |
+
if pdtb_path is None:
|
573 |
+
raise ValueError("pdtb_path is required for corpus pdtb")
|
574 |
+
if not os.path.isdir(pdtb_path):
|
575 |
+
sys.stderr.write("Can't find directory at: " + pdtb_path + "\n")
|
576 |
+
sys.exit(0)
|
577 |
+
files = []
|
578 |
+
for i in range(0, 25):
|
579 |
+
dir_name = str(i) if i > 9 else "0" + str(i)
|
580 |
+
files += glob(os.sep.join([pdtb_path, dir_name, "wsj_*"]))
|
581 |
+
docs2text = harvest_text(files)
|
582 |
+
restore_docs(docs2text, **todo)
|
583 |
+
|
584 |
+
if opts.corpus == "cdtb" or opts.corpus == "all":
|
585 |
+
if cdtb_path is None:
|
586 |
+
raise ValueError("cdtb_path is required for corpus cdtb")
|
587 |
+
if not os.path.isdir(cdtb_path):
|
588 |
+
sys.stderr.write("Can't find directory at: " + cdtb_path + "\n")
|
589 |
+
sys.exit(0)
|
590 |
+
files = glob(os.sep.join([cdtb_path, "*.raw"]))
|
591 |
+
docs2text = harvest_text(files)
|
592 |
+
restore_docs(docs2text, **todo)
|
593 |
+
|
594 |
+
if opts.corpus == "tdb" or opts.corpus == "all":
|
595 |
+
if tdb_path is None:
|
596 |
+
raise ValueError("tdb_path is required for corpus tdb")
|
597 |
+
if not os.path.isdir(tdb_path):
|
598 |
+
sys.stderr.write("Can't find directory at: " + tdb_path + "\n")
|
599 |
+
sys.exit(0)
|
600 |
+
files = glob(os.sep.join([tdb_path, "*.txt"]))
|
601 |
+
docs2text = harvest_text(files)
|
602 |
+
restore_docs(docs2text, **todo)
|
603 |
+
|
604 |
+
if opts.corpus == "gum" or opts.corpus == "all":
|
605 |
+
print("Retrieving reddit data by proxy...")
|
606 |
+
data = get_proxy_data()
|
607 |
+
docs2text = get_no_space_strings(data)
|
608 |
+
restore_docs(docs2text, **todo)
|