diff --git a/anserini_dependency/README.md b/anserini_dependency/README.md new file mode 100644 index 0000000..47520c0 --- /dev/null +++ b/anserini_dependency/README.md @@ -0,0 +1,46 @@ +## Retrieve Sentences + +#### 1. Clone [Anserini](https://github.com/castorini/Anserini.git) and [Castor](https://github.com/castorini/Castor.git) +```bash +git clone https://github.com/castorini/Anserini.git +git clone https://github.com/castorini/Castor.git +``` + +Your directory structure should look like +``` +├── Anserini +└── Castor +``` + +#### 2. Compile Anserini + +```bash +cd Anserini +mvn package +``` + +This creates `anserini-0.0.1-SNAPSHOT.jar` at `Anserini/target` + +#### 3. Download Dependencies +- Download the index from [here](https://drive.google.com/open?id=0B2u_nClt6NbzcllGZTVtX2Q4bkk) +- Download the Google word2vec file from [here](https://drive.google.com/drive/folders/0B2u_nClt6NbzNWJkWExmaklYNTA?usp=sharing) + +#### 4. Run the following command + +```bash +python ./anserini_dependency/RetrieveSentences.py +``` + +Possible parameters are: + +| option | input format | default | description | +|----------------|--------------|---------|-------------| +| `-index` | string | N/A | Path of the Lucene index | +| `-embeddings` | string | "" | Path of the word2vec index | +| `-topics` | string | "" | topics file | +| `-query` | string | "" | a single query | +| `-hits` | [1, inf) | 100 | max number of hits to return | +| `-scorer` | string | Idf | passage scores (Idf or Wmd) | +| `-k` | [1, inf) | 1 | top-k passages to be retrieved | + +Note: Either a query or a topic must be passed in as an argument; they can't be both empty. diff --git a/anserini_dependency/RetrieveSentences.py b/anserini_dependency/RetrieveSentences.py new file mode 100644 index 0000000..74dd1ef --- /dev/null +++ b/anserini_dependency/RetrieveSentences.py @@ -0,0 +1,69 @@ +import argparse + +import jnius_config +jnius_config.set_classpath("../Anserini/target/anserini-0.0.1-SNAPSHOT.jar") +from jnius import autoclass + + +class CallRetrieveSentences: + """Python class built to call RetrieveSentences + Attributes + ---------- + rs : io.anserini.qa.RetrieveSentences + The RetrieveSentences object + args : io.anserini.qa.RetrieveSentences$Args + The arguments for constructing RetrieveSentences object as well as calling getRankedPassages + + """ + + def __init__(self, args): + """ + Constructor for the CallRetrieveSentences class. + + Parameters + ---------- + args : argparse.Namespace + Arguments needed for constructing an instance of RetrieveSentences class + """ + RetrieveSentences = autoclass("io.anserini.qa.RetrieveSentences") + Args = autoclass("io.anserini.qa.RetrieveSentences$Args") + String = autoclass("java.lang.String") + + self.args = Args() + index = String(args.index) + self.args.index = index + embeddings = String(args.embeddings) + self.args.embeddings = embeddings + topics = String(args.topics) + self.args.topics = topics + query = String(args.query) + self.args.query = query + self.args.hits = int(args.hits) + scorer = String(args.scorer) + self.args.scorer = scorer + self.args.k = int(args.k) + self.rs = RetrieveSentences(self.args) + + def getRankedPassages(self): + """ + Call RetrieveSentneces.getRankedPassages + """ + self.rs.getRankedPassages(self.args) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Retrieve Sentences') + parser.add_argument("-index", help="Lucene index", required=True) + parser.add_argument("-embeddings", help="Path of the word2vec index", default="") + parser.add_argument("-topics", help="topics file", default="") + parser.add_argument("-query", help="a single query", default="") + parser.add_argument("-hits", help="max number of hits to return", default=100) + parser.add_argument("-scorer", help="passage scores", default="Idf") + parser.add_argument("-k", help="top-k passages to be retrieved", default=1) + + args_raw = parser.parse_args() + rs = CallRetrieveSentences(args_raw) + rs.getRankedPassages() + + + +