-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
404 additions
and
57 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
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
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,95 @@ | ||
from django.urls import path | ||
from rest_framework.decorators import api_view | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
|
||
from ... import model as modeldb | ||
|
||
|
||
@api_view(["GET"]) | ||
def topics(request: Request, dataset_id: str) -> Response: | ||
"""Get topics for the specified dataset id. | ||
Args: | ||
request (Request): The request that triggered the REST API call. | ||
dataset_id (str): The TIRA dataset id for which the topics should be returned | ||
Returns: | ||
Response: The topics. | ||
""" | ||
ret = [] | ||
import ir_datasets | ||
|
||
dataset = modeldb.Dataset.objects.get(dataset_id=dataset_id) | ||
|
||
if not dataset.ir_datasets_id: | ||
raise ValueError(f'No ir dataset id specified for TIRA dataset "{dataset_id}".') | ||
|
||
ir_dataset = ir_datasets.load(dataset.ir_datasets_id) | ||
queries_iter = ir_dataset.queries_iter() | ||
for q in queries_iter: | ||
ret += [{"qid": q.query_id, "dataset_id": dataset_id, "default_text": q.default_text()}] | ||
|
||
return Response(ret) | ||
|
||
|
||
@api_view(["GET"]) | ||
def topic(request: Request, dataset_id: str, qid: str) -> Response: | ||
"""Get topic for the specified dataset id. | ||
Args: | ||
request (Request): The request that triggered the REST API call. | ||
dataset_id (str): The TIRA dataset id for which the topic should be returned | ||
qid (str): The query id of the topic that should be returned | ||
Returns: | ||
Response: The topics. | ||
""" | ||
ret = [] | ||
import ir_datasets | ||
|
||
dataset = modeldb.Dataset.objects.get(dataset_id=dataset_id) | ||
|
||
if not dataset.ir_datasets_id: | ||
raise ValueError(f'No ir dataset id specified for TIRA dataset "{dataset_id}".') | ||
|
||
ir_dataset = ir_datasets.load(dataset.ir_datasets_id) | ||
queries_iter = ir_dataset.queries_iter() | ||
for q in queries_iter: | ||
if str(q.query_id) == qid: | ||
ret = {"qid": qid, "dataset_id": dataset_id, "default_text": q.default_text(), "docs": {}} | ||
try: | ||
ret["description"] = q.description | ||
ret["narrative"] = q.narrative | ||
except: | ||
pass | ||
return Response(ret) | ||
|
||
raise ValueError(f"No topic found with id {qid}.") | ||
|
||
|
||
@api_view(["GET"]) | ||
def run_by_uuid(request: Request, run_uuid: str) -> Response: | ||
"""Get meta data for the specified run. | ||
Args: | ||
request (Request): The request that triggered the REST API call. | ||
run_uuid (str): The UUID for the run | ||
Returns: | ||
Response: The topics. | ||
""" | ||
dataset_id = "clueweb09-en-trec-web-2009-20230107-training" | ||
run_id = f"uuid-{run_uuid}" | ||
ranking = {} | ||
for i in range(0, 50): | ||
ranking[str(i)] = [{"rank": j, "score": 10 - j, "doc_id": f"doc-{j}"} for j in range(1, 11)] | ||
|
||
return Response({"tira_run": run_id, "dataset": dataset_id, "team": "", "run": run_id, "ranking": ranking}) | ||
|
||
|
||
endpoints = [ | ||
path("topics/<str:dataset_id>", topics), | ||
path("topic/<str:dataset_id>/<str:qid>", topic), | ||
path("runs-by-uuid/<str:run_uuid>", run_by_uuid), | ||
] |
24 changes: 24 additions & 0 deletions
24
application/src/tira_app/management/commands/add_mirror_to_dataset.py
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,24 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from tira_app.endpoints.v1._datasets import add_mirrored_resource | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Add a mirror to a dataset.""" | ||
|
||
def handle(self, *args, **options): | ||
if "dataset_id" not in options or not options["dataset_id"]: | ||
raise ValueError("Please pass --dataset_id") | ||
|
||
if "url" not in options or not options["url"]: | ||
raise ValueError("Please pass --url") | ||
|
||
if "name" not in options or not options["name"]: | ||
raise ValueError("Please pass --name") | ||
|
||
add_mirrored_resource(options["dataset_id"], options["url"], options["name"]) | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("--dataset_id", default=None, type=str) | ||
parser.add_argument("--url", default=None, type=str) | ||
parser.add_argument("--name", default=None, type=str) |
34 changes: 34 additions & 0 deletions
34
application/src/tira_app/migrations/0004_mirroredresource_datasethasmirroredresource.py
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,34 @@ | ||
# Generated by Django 5.0.9 on 2024-12-01 10:33 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("tira", "0003_dataset_chatnoir_id_dataset_ir_datasets_id"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="MirroredResource", | ||
fields=[ | ||
("md5_sum", models.CharField(max_length=150, primary_key=True, serialize=False)), | ||
("md5_first_kilobyte", models.CharField(max_length=150)), | ||
("size", models.BigIntegerField()), | ||
("mirrors", models.CharField(default=None, max_length=500, null=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="DatasetHasMirroredResource", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("dataset", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="tira.dataset")), | ||
( | ||
"mirrored_resource", | ||
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="tira.mirroredresource"), | ||
), | ||
], | ||
), | ||
] |
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
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
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
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
Oops, something went wrong.