-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_indexes.py
48 lines (37 loc) · 1.51 KB
/
create_indexes.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
"""
This script iterates over a specified collection of nxml articles and extracts a
specified set of data from them.
You can specify the url for the Mongo server, as well as the name of the
database and collection.
You *must* also specify one or more of the extractor functions from the
pubcrawler.extractors module. But specify them by just their name; this package
adds the correct suffix automatically. This should be fixed in a later version,
but it was the only good way to allow an argument from the command line.
You can also specify a -skip_field. You don't have to do this, but it's best to,
because this is what's used to report progress (because of ugly multiprocess
stuff, and because python's Queue.qsize() method is not implemented on macOS).
You can also specify a limit, as well as the number of worker processes you
want.
"""
import time
import sys
import pymongo
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"-u", "--mongo_url", default="localhost", dest = "u"
)
parser.add_argument(
"-d", "--mongo_db", default="pmc", dest = "d"
)
parser.add_argument(
"-c", "--mongo_collection", default="articles", dest = "c"
)
args = parser.parse_args()
print("Making connection.")
articles = pymongo.MongoClient(args.u)[args.d][args.c]
# articles.create_index("index.meta")
# articles.create_index("index.keywords")
# articles.create_index("index.geonames")
articles.create_index("index")