Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/zbmath_rest2oai/software_quickstatements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

JSON schema::

{"rows": [{"qP13": "825", "Len": "SageMath", "P29": "...", ...}, ...]}
[{"qP13": "825", "Len": "SageMath", "P29": "...", ...}, ...]

Key conventions (matching MathSearch QuickStatements job):
- ``qP<id>`` – look up item whose property P<id> equals the value.
Expand Down Expand Up @@ -124,7 +124,7 @@ def to_reference_rows(result: dict) -> list[dict]:
return rows


def build_metadata_json(results: list[dict]) -> dict:
def build_metadata_json(results: list[dict]) -> list[dict]:
"""Build the metadata QuickStatements JSON structure.

Parameters
Expand All @@ -134,13 +134,13 @@ def build_metadata_json(results: list[dict]) -> dict:

Returns
-------
dict
``{"rows": [...]}`` ready to be serialised with ``json.dumps``.
list[dict]
List of rows ready to be serialised with ``json.dumps``.
"""
return {"rows": [to_metadata_row(r) for r in results]}
return [to_metadata_row(r) for r in results]


def build_references_json(results: list[dict]) -> dict:
def build_references_json(results: list[dict]) -> list[dict]:
"""Build the references QuickStatements JSON structure.

Parameters
Expand All @@ -150,10 +150,10 @@ def build_references_json(results: list[dict]) -> dict:

Returns
-------
dict
``{"rows": [...]}`` ready to be serialised with ``json.dumps``.
list[dict]
List of rows ready to be serialised with ``json.dumps``.
"""
rows: list[dict] = []
for r in results:
rows.extend(to_reference_rows(r))
return {"rows": rows}
return rows
196 changes: 97 additions & 99 deletions test/data/software/sagemath_825_metadata.json
Original file line number Diff line number Diff line change
@@ -1,99 +1,97 @@
{
"rows": [
{
"qP13": "825",
"Len": "SageMath",
"P29": "https://www.sagemath.org/",
"P339": "https://github.com/sagemath/sage",
"P226_1": "05",
"P226_2": "11",
"P226_3": "14",
"P226_4": "20",
"P226_5": "68",
"P226_6": "00",
"P226_7": "01",
"P226_8": "03",
"P226_9": "06",
"P226_10": "08",
"P226_11": "12",
"P226_12": "13",
"P226_13": "15",
"P226_14": "16",
"P226_15": "17",
"P226_16": "18",
"P226_17": "19",
"P226_18": "22",
"P226_19": "26",
"P226_20": "28",
"P226_21": "30",
"P226_22": "31",
"P226_23": "32",
"P226_24": "33",
"P226_25": "34",
"P226_26": "35",
"P226_27": "37",
"P226_28": "39",
"P226_29": "40",
"P226_30": "41",
"P226_31": "42",
"P226_32": "43",
"P226_33": "44",
"P226_34": "46",
"P226_35": "47",
"P226_36": "49",
"P226_37": "51",
"P226_38": "52",
"P226_39": "53",
"P226_40": "54",
"P226_41": "55",
"P226_42": "57",
"P226_43": "58",
"P226_44": "60",
"P226_45": "62",
"P226_46": "65",
"P226_47": "70",
"P226_48": "74",
"P226_49": "76",
"P226_50": "78",
"P226_51": "80",
"P226_52": "81",
"P226_53": "82",
"P226_54": "83",
"P226_55": "85",
"P226_56": "86",
"P226_57": "90",
"P226_58": "91",
"P226_59": "92",
"P226_60": "93",
"P226_61": "94",
"P226_62": "97",
"P1458q13_1": "540",
"P1458q13_2": "23170",
"P1458q13_3": "320",
"P1458q13_4": "7248",
"P1458q13_5": "680",
"P1458q13_6": "866",
"P1458q13_7": "537",
"P1458q13_8": "554",
"P1458q13_9": "16448",
"P1458q13_10": "7249",
"P1458q13_11": "545",
"P1458q13_12": "14460",
"P1458q13_13": "27596",
"P1458q13_14": "611",
"P1458q13_15": "7823",
"P1458q13_16": "23728",
"P1458q13_17": "4968",
"P1458q13_18": "724",
"P1458q13_19": "560",
"P1458q13_20": "6874",
"P286q1459_1": "7045592",
"P286q1459_2": "6418360",
"P286q1459_3": "6532438",
"P286q1459_4": "6462232",
"P286q1459_5": "6114556",
"P286q1459_6": "5785538",
"P286q1459_7": "5380273"
}
]
}
[
{
"qP13": "825",
"Len": "SageMath",
"P29": "https://www.sagemath.org/",
"P339": "https://github.com/sagemath/sage",
"P226_1": "05",
"P226_2": "11",
"P226_3": "14",
"P226_4": "20",
"P226_5": "68",
"P226_6": "00",
"P226_7": "01",
"P226_8": "03",
"P226_9": "06",
"P226_10": "08",
"P226_11": "12",
"P226_12": "13",
"P226_13": "15",
"P226_14": "16",
"P226_15": "17",
"P226_16": "18",
"P226_17": "19",
"P226_18": "22",
"P226_19": "26",
"P226_20": "28",
"P226_21": "30",
"P226_22": "31",
"P226_23": "32",
"P226_24": "33",
"P226_25": "34",
"P226_26": "35",
"P226_27": "37",
"P226_28": "39",
"P226_29": "40",
"P226_30": "41",
"P226_31": "42",
"P226_32": "43",
"P226_33": "44",
"P226_34": "46",
"P226_35": "47",
"P226_36": "49",
"P226_37": "51",
"P226_38": "52",
"P226_39": "53",
"P226_40": "54",
"P226_41": "55",
"P226_42": "57",
"P226_43": "58",
"P226_44": "60",
"P226_45": "62",
"P226_46": "65",
"P226_47": "70",
"P226_48": "74",
"P226_49": "76",
"P226_50": "78",
"P226_51": "80",
"P226_52": "81",
"P226_53": "82",
"P226_54": "83",
"P226_55": "85",
"P226_56": "86",
"P226_57": "90",
"P226_58": "91",
"P226_59": "92",
"P226_60": "93",
"P226_61": "94",
"P226_62": "97",
"P1458q13_1": "540",
"P1458q13_2": "23170",
"P1458q13_3": "320",
"P1458q13_4": "7248",
"P1458q13_5": "680",
"P1458q13_6": "866",
"P1458q13_7": "537",
"P1458q13_8": "554",
"P1458q13_9": "16448",
"P1458q13_10": "7249",
"P1458q13_11": "545",
"P1458q13_12": "14460",
"P1458q13_13": "27596",
"P1458q13_14": "611",
"P1458q13_15": "7823",
"P1458q13_16": "23728",
"P1458q13_17": "4968",
"P1458q13_18": "724",
"P1458q13_19": "560",
"P1458q13_20": "6874",
"P286q1459_1": "7045592",
"P286q1459_2": "6418360",
"P286q1459_3": "6532438",
"P286q1459_4": "6462232",
"P286q1459_5": "6114556",
"P286q1459_6": "5785538",
"P286q1459_7": "5380273"
}
]
30 changes: 14 additions & 16 deletions test/data/software/sagemath_825_references.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"rows": [
{
"qP1451": "6383667",
"P1463q13": "825"
},
{
"qP1451": "6414141",
"P1463q13": "825"
},
{
"qP1451": "6462232",
"P1463q13": "825"
}
]
}
[
{
"qP1451": "6383667",
"P1463q13": "825"
},
{
"qP1451": "6414141",
"P1463q13": "825"
},
{
"qP1451": "6462232",
"P1463q13": "825"
}
]
20 changes: 10 additions & 10 deletions test/test_software_quickstatements.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ class TestBuildMetadataJson(unittest.TestCase):
def test_structure(self):
results = [{"id": 1, "name": "A"}, {"id": 2, "name": "B"}]
output = build_metadata_json(results)
self.assertIn("rows", output)
self.assertEqual(len(output["rows"]), 2)
self.assertEqual(output["rows"][0]["qP13"], "1")
self.assertEqual(output["rows"][1]["qP13"], "2")
self.assertIsInstance(output, list)
self.assertEqual(len(output), 2)
self.assertEqual(output[0]["qP13"], "1")
self.assertEqual(output[1]["qP13"], "2")


class TestBuildReferencesJson(unittest.TestCase):
Expand All @@ -153,8 +153,8 @@ def test_structure(self):
{"id": 2, "references": [20]},
]
output = build_references_json(results)
self.assertIn("rows", output)
self.assertEqual(len(output["rows"]), 3)
self.assertIsInstance(output, list)
self.assertEqual(len(output), 3)


class TestSageMath825Fixture(unittest.TestCase):
Expand All @@ -179,19 +179,19 @@ def test_references_match_fixture(self):

def test_metadata_qp13_is_825(self):
result = build_metadata_json([self.raw])
self.assertEqual(result["rows"][0]["qP13"], "825")
self.assertEqual(result[0]["qP13"], "825")

def test_metadata_label_is_sagemath(self):
result = build_metadata_json([self.raw])
self.assertEqual(result["rows"][0]["Len"], "SageMath")
self.assertEqual(result[0]["Len"], "SageMath")

def test_metadata_homepage_present(self):
result = build_metadata_json([self.raw])
self.assertIn("P29", result["rows"][0])
self.assertIn("P29", result[0])

def test_metadata_source_code_present(self):
result = build_metadata_json([self.raw])
self.assertIn("P339", result["rows"][0])
self.assertIn("P339", result[0])


if __name__ == "__main__":
Expand Down
Loading