{
"cells": [
{
"cell_type": "code",
"execution_count": 383,
"metadata": {},
"outputs": [],
"source": [
"import rdflib\n",
"from rdflib.plugins.sparql import prepareQuery\n",
"from tabulate import tabulate"
]
},
{
"cell_type": "code",
"execution_count": 384,
"metadata": {},
"outputs": [],
"source": [
"filename = \"06_ABox.ttl\""
]
},
{
"cell_type": "code",
"execution_count": 385,
"metadata": {},
"outputs": [],
"source": [
"text1 = '''MS2_CQ_01\n",
"Provide a list of all Open Access Publications for 2023 for Journal Articles (Gold (APC Driven), Green, Diamond) published by authors affiliated with University of Bologna using the OpenAIRE Graph.\n",
"'''\n",
"\n",
"query1 = '''\n",
"PREFIX tbox: <https://example.org/skg-if/extention/02/schema/>\n",
"PREFIX : <https://example.org/skg-if/extention/02/data/>\n",
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n",
"\n",
"SELECT DISTINCT ?ror_id ?org_name ?article_title (GROUP_CONCAT(DISTINCT ?article_doi; separator=\", \") AS ?article_dois) ?open_access_type (YEAR(?issued_date) AS ?year)\n",
"WHERE {\n",
" \n",
" ?article a tbox:Work ;\n",
" tbox:title ?article_title ;\n",
" tbox:hasIdentifier [ tbox:hasLiteralValue ?article_doi ; tbox:usesIdentifierScheme tbox:doi ] ;\n",
" tbox:isRelatedToRoleInTime [ tbox:withRole tbox:affiliate ; tbox:relatesToOrganization :university-of-bologna ] ;\n",
" tbox:realization [ \n",
" a ?type ;\n",
" tbox:issued ?issued_date ;\n",
" tbox:holdsStatusInTime [ tbox:withStatus ?open_access_type ] \n",
" ] .\n",
" \n",
" :university-of-bologna tbox:name ?org_name ;\n",
" tbox:hasIdentifier [ tbox:hasLiteralValue ?ror_id ; tbox:usesIdentifierScheme tbox:ror ] .\n",
" \n",
" FILTER (\n",
" ?type = tbox:JournalArticle\n",
" &&\n",
" ?issued_date >= \"2023-01-01T00:00:00+00:00\"^^xsd:dateTime \n",
" &&\n",
" ?issued_date <= \"2023-12-31T23:59:59+00:00\"^^xsd:dateTime\n",
" )\n",
"\n",
"}\n",
"GROUP BY ?article\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 386,
"metadata": {},
"outputs": [],
"source": [
"text2 = '''MS2_CQ_02\n",
"Provide a list of all datasets identified in OpenAIRE that are affiliated with University of Bologna, in any year between 2014-2024.\n",
"'''\n",
"\n",
"query2 = '''\n",
"PREFIX tbox: <https://example.org/skg-if/extention/02/schema/>\n",
"PREFIX : <https://example.org/skg-if/extention/02/data/>\n",
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n",
"\n",
"SELECT DISTINCT ?ror_id ?org_name ?dataset_title (GROUP_CONCAT(DISTINCT ?dataset_doi; separator=\", \") AS ?dataset_dois) (YEAR(?issued_date) AS ?year)\n",
"WHERE {\n",
" \n",
" ?dataset a tbox:Dataset ;\n",
" tbox:title ?dataset_title ;\n",
" tbox:hasIdentifier [ tbox:hasLiteralValue ?dataset_doi ; tbox:usesIdentifierScheme tbox:doi ] ;\n",
" tbox:isRelatedToRoleInTime [ tbox:withRole tbox:affiliate ; tbox:relatesToOrganization :university-of-bologna ] ;\n",
" tbox:realization [ tbox:issued ?issued_date ] .\n",
" \n",
" :university-of-bologna tbox:name ?org_name ;\n",
" tbox:hasIdentifier [ tbox:hasLiteralValue ?ror_id ; tbox:usesIdentifierScheme tbox:ror ] .\n",
" \n",
" FILTER (\n",
" ?issued_date >= \"2014-01-01T00:00:00+00:00\"^^xsd:dateTime \n",
" &&\n",
" ?issued_date <= \"2024-12-31T23:59:59+00:00\"^^xsd:dateTime\n",
" )\n",
"\n",
"}\n",
"GROUP BY ?dataset\n",
"\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 387,
"metadata": {},
"outputs": [],
"source": [
"text3 = '''MS2_CQ_03\n",
"Provide a list of all Preprints identified in OpenAIRE that are affiliated with University of Bologna, in any year between 2014-2024.\n",
"'''\n",
"\n",
"query3 = '''\n",
"PREFIX tbox: <https://example.org/skg-if/extention/02/schema/>\n",
"PREFIX : <https://example.org/skg-if/extention/02/data/>\n",
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n",
"\n",
"SELECT DISTINCT ?ror_id ?org_name ?article_title (GROUP_CONCAT(DISTINCT ?article_doi; separator=\", \") AS ?article_dois) ?type_label (YEAR(?issued_date) AS ?year) ?repository_name\n",
"WHERE {\n",
"\n",
" ?article a tbox:Work ;\n",
" tbox:title ?article_title ;\n",
" tbox:hasIdentifier [ tbox:hasLiteralValue ?article_doi ; tbox:usesIdentifierScheme tbox:doi ] ;\n",
" tbox:isRelatedToRoleInTime [ tbox:withRole tbox:affiliate ; tbox:relatesToOrganization :university-of-bologna ] ;\n",
" tbox:realization [ \n",
" a ?type ;\n",
" tbox:issued ?issued_date ;\n",
" tbox:accessService [\n",
" tbox:name ?repository_name\n",
" ]\n",
" ] .\n",
"\n",
" :university-of-bologna tbox:name ?org_name ;\n",
" tbox:hasIdentifier [ tbox:hasLiteralValue ?ror_id ; tbox:usesIdentifierScheme tbox:ror ] .\n",
" \n",
" ?type tbox:prefLabel ?type_label .\n",
" \n",
" FILTER (\n",
" ?type = tbox:Preprint\n",
" &&\n",
" ?issued_date >= \"2014-01-01T00:00:00+00:00\"^^xsd:dateTime \n",
" &&\n",
" ?issued_date <= \"2024-12-31T23:59:59+00:00\"^^xsd:dateTime\n",
" )\n",
" \n",
"}\n",
"GROUP BY ?article\n",
"\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 388,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MS2_CQ_01\n",
"Provide a list of all Open Access Publications for 2023 for Journal Articles (Gold (APC Driven), Green, Diamond) published by authors affiliated with University of Bologna using the OpenAIRE Graph.\n",
"\n",
"+---------------------------+-----------------------+--------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------+------------------------------------------------------------------+--------+\n",
"| ror_id | org_name | article_title | article_dois | open_access_type | year |\n",
"|---------------------------+-----------------------+--------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------+------------------------------------------------------------------+--------|\n",
"| https://ror.org/01111rn36 | University of Bologna | When Operation Technology Meets Information Technology: Challenges and Opportunities | https://doi.org/10.3390/fi15030095 | https://example.org/skg-if/extention/02/schema/gold-open-access | 2023 |\n",
"| https://ror.org/01111rn36 | University of Bologna | Cascaded Rectifiers for Energy Harvesting With a Wide Dynamic Power Range | https://doi.org/10.1109/JRFID.2023.3234805, https://cris.unibo.it/handle/11585/916843 | https://example.org/skg-if/extention/02/schema/green-open-access | 2023 |\n",
"+---------------------------+-----------------------+--------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------+------------------------------------------------------------------+--------+\n",
"\n",
"\n",
"MS2_CQ_02\n",
"Provide a list of all datasets identified in OpenAIRE that are affiliated with University of Bologna, in any year between 2014-2024.\n",
"\n",
"+---------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------+--------+\n",
"| ror_id | org_name | dataset_title | dataset_dois | year |\n",
"|---------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------+--------|\n",
"| https://ror.org/01111rn36 | University of Bologna | Dataset to run the NeuralFRG software for the t-t' Hubbard model on the square lattice. Phys. Rev. Lett. 129, 136402 (2022) | https://doi.org/10.5281/zenodo.7626636 | 2023 |\n",
"| https://ror.org/01111rn36 | University of Bologna | Data from the article 'Supplemental LED Lighting Improves Fruit Growth and Yield of Tomato Grown under the Sub-Optimal Lighting Condition of a Building Integrated Rooftop Greenhouse (i-RTG)' | https://doi.org/10.6092/unibo%2Famsacta%2F7601 | 2022 |\n",
"+---------------------------+-----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------+--------+\n",
"\n",
"\n",
"MS2_CQ_03\n",
"Provide a list of all Preprints identified in OpenAIRE that are affiliated with University of Bologna, in any year between 2014-2024.\n",
"\n",
"+---------------------------+-----------------------+------------------------------------------------------------------------+---------------------------------------------------------------------------------------+--------------+--------+-------------------+\n",
"| ror_id | org_name | article_title | article_dois | type_label | year | repository_name |\n",
"|---------------------------+-----------------------+------------------------------------------------------------------------+---------------------------------------------------------------------------------------+--------------+--------+-------------------|\n",
"| https://ror.org/01111rn36 | University of Bologna | Approaching Digital Humanities at the University: a Cultural Challenge | https://doi.org/10.48550/arxiv.2209.06091 | preprint | 2022 | arXiv |\n",
"| https://ror.org/01111rn36 | University of Bologna | Performing live time-traversal queries via SPARQL on RDF datasets | https://doi.org/10.1109/JRFID.2023.3234805, https://doi.org/10.48550/arxiv.2210.02534 | preprint | 2022 | arXiv |\n",
"+---------------------------+-----------------------+------------------------------------------------------------------------+---------------------------------------------------------------------------------------+--------------+--------+-------------------+\n",
"\n",
"\n"
]
}
],
"source": [
"queries = [(text1, query1),\n",
" (text2, query2),\n",
" (text3, query3)]\n",
"\n",
"g = rdflib.Dataset()\n",
"g.parse(filename, format=\"turtle\", encoding=\"utf-8\")\n",
"\n",
"for query in queries:\n",
" q = prepareQuery(query[1])\n",
" results = g.query(q)\n",
" print(query[0])\n",
" table = []\n",
" for row in results:\n",
" table.append([row[var] for var in results.vars])\n",
" print(tabulate(table, headers=results.vars, tablefmt=\"psql\"))\n",
" print(\"\\n\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}