Skip to content

Commit

Permalink
Merge pull request #199 from axif0/qid-json
Browse files Browse the repository at this point in the history
qid & testing add
  • Loading branch information
andrewtavis authored Sep 20, 2024
2 parents 8504672 + a910d12 commit a4a33de
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
10 changes: 3 additions & 7 deletions src/scribe_data/cli/total.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
from scribe_data.cli.cli_utils import language_to_qid
from scribe_data.wikidata.wikidata_utils import sparql

# Dictionary to map data types to their Wikidata Q-IDs.
data_type_to_qid = {
"nouns": "Q1084",
"prepositions": "Q37649",
"verbs": "Q24905",
"translations": "Q7553789",
}
from scribe_data.cli.cli_utils import data_type_metadata as data_type_to_qid

data_type_to_qid = data_type_to_qid["data-types"]


def get_qid_by_input(input_str):
Expand Down
16 changes: 8 additions & 8 deletions src/scribe_data/resources/data_type_metadata.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"data-types": [
"autosuggestions",
"emoji_keywords",
"nouns",
"prepositions",
"translations",
"verbs"
]
"data-types": {
"autosuggestions":"",
"emoji_keywords":"",
"nouns": "Q1084",
"prepositions": "Q37649",
"translations": "Q7553789",
"verbs": "Q24905"
}
}
24 changes: 23 additions & 1 deletion tests/cli/test_total.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import unittest
from unittest.mock import MagicMock, call, patch

from scribe_data.cli.total import get_total_lexemes
from scribe_data.cli.total import get_total_lexemes, get_qid_by_input


class TestTotalLexemes(unittest.TestCase):
Expand Down Expand Up @@ -125,3 +125,25 @@ def test_get_total_lexemes_various_data_types(self, mock_query, mock_get_qid):
call("Language: English\nData type: nouns\nTotal number of lexemes: 30"),
]
mock_print.assert_has_calls(expected_calls)


class TestGetQidByInput(unittest.TestCase):
def setUp(self):
self.valid_data_types = {
"english": "Q1860",
"nouns": "Q1084",
"verbs": "Q24905",
}

@patch("scribe_data.cli.total.data_type_to_qid", new_callable=dict)
def test_get_qid_by_input_valid(self, mock_data_type_to_qid):
mock_data_type_to_qid.update(self.valid_data_types)

for data_type, expected_qid in self.valid_data_types.items():
self.assertEqual(get_qid_by_input(data_type), expected_qid)

@patch("scribe_data.cli.total.data_type_to_qid", new_callable=dict)
def test_get_qid_by_input_invalid(self, mock_data_type_to_qid):
mock_data_type_to_qid.update(self.valid_data_types)

self.assertIsNone(get_qid_by_input("invalid_data_type"))

0 comments on commit a4a33de

Please sign in to comment.