-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to look up doc text from qrels for MS MARCO passage (#498)
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import argparse | ||
import json | ||
import sys | ||
|
||
# We're going to explicitly use a local installation of Pyserini (as opposed to a pip-installed one). | ||
# Comment these lines out to use a pip-installed one instead. | ||
sys.path.insert(0, './') | ||
|
||
from pyserini.search import SimpleSearcher | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--qrels', type=str, help='qrels file', required=True) | ||
parser.add_argument('--index', type=str, help='index location', required=True) | ||
args = parser.parse_args() | ||
|
||
searcher = SimpleSearcher(args.index) | ||
with open(args.qrels, 'r') as reader: | ||
for line in reader.readlines(): | ||
arr = line.split('\t') | ||
doc = json.loads(searcher.doc(arr[2]).raw())['contents'] | ||
print(f'{arr[2]}\t{doc}') |