{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from rdflib import Graph" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ ")>" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = Graph()\n", "g.parse(\n", " data=\"\"\"@prefix rdf: .\n", "@prefix rdfs: .\n", "@prefix xsd: .\n", "@prefix facility: .\n", "@prefix process: .\n", "@prefix resource: .\n", "@prefix iot: .\n", "@prefix time: .\n", "@prefix project: .\n", "@prefix process2: .\n", "@prefix resource_data: .\n", "@prefix task: .\n", "@prefix tracking_tag: .\n", "@prefix resource_type: .\n", "@prefix work_order: .\n", "@prefix dcterms: .\n", "@prefix res_type_req: .\n", "@prefix res_type: .\n", "@prefix element: .\n", "@prefix beo: .\n", "@prefix bot: .\n", "@prefix props: .\n", "\n", "project:079637bb-87d5-4fef-9704-d556364d90ba\n", " a facility:Project ;\n", " process:isRelatedToProcess process2:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28 ;\n", " dcterms:identifier \"079637bb-87d5-4fef-9704-d556364d90ba\"^^xsd:string ;\n", " dcterms:title \"Project test 1\"^^xsd:string .\n", "\n", "process2:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28\n", " a process:Process ;\n", " dcterms:identifier \"FE090C7C-7AEC-42FE-9452-AD0AA8643D28\"^^xsd:string ;\n", " dcterms:title \"rst_advanced_sample_project_MSP2010.xml\"^^xsd:string;\n", " process:hasTask task:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28_8 ;\n", " process:involvesResourceType res_type:Excavator, res_type:Worker ;\n", " process:hasWorkOrder work_order:2985732-49853425-38954 .\n", "\n", "tracking_tag:e9b870d9-5058-4d4a-802b-3457279524e0\n", " a iot:TrackingTag, iot:HumanTag ;\n", " resource:belongsToProject project:079637bb-87d5-4fef-9704-d556364d90ba .\n", "\n", "resource_data:e9b870d9-5058-4d4a-802b-3457279524e0\n", " a resource:Worker ;\n", " resource:hasTrackingTag tracking_tag:e9b870d9-5058-4d4a-802b-3457279524e0;\n", " dcterms:identifier \"e9b870d9-5058-4d4a-802b-3457279524e0\"^^xsd:string;\n", " resource:email ;\n", " resource:belongsToType res_type:Worker .\n", "\n", "work_order:2985732-49853425-38954\n", " a process:WorkOrder ;\n", " dcterms:identifier \"2985732-49853425-38954\"^^xsd:string ;\n", " process:belongsToProcess process2:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28 ;\n", " process:hasMainProvider resource_data:e9b870d9-5058-4d4a-802b-3457279524e0 ;\n", " process:hasComponentTask task:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28_8 .\n", "\n", "element:3954 \n", " a beo:Column , bot:Element, facility:Element ;\n", " facility:hasImage ;\n", " dcterms:title \"M_Concrete-Round-Column:450mm:122512\" ;\n", " process:isControlledByTask task:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28_8 ;\n", " dcterms:identifier \"18YHwga450Mw4Fy6M5t_8h\"^^xsd:string ;\n", " props:hasVolume \"0.556638970864849\"^^xsd:double .\n", "\n", "task:079637bb-87d5-4fef-9704-d556364d90ba_FE090C7C-7AEC-42FE-9452-AD0AA8643D28_8\n", " a process:Task ;\n", " dcterms:identifier \"8\"^^xsd:string ;\n", " dcterms:title \"Beams and Floor Slab (Floor 1)\"^^xsd:string ;\n", " process:plannedStartDate \"2010-06-07T08:00:00\"^^xsd:dateTime ;\n", " process:plannedEndDate \"2010-06-11T17:00:00\"^^xsd:dateTime ;\n", " process:hasAssignedResource resource_data:e9b870d9-5058-4d4a-802b-3457279524e0 ;\n", " process:hasResourceTypeRequirement res_type_req:Excavator, res_type_req:Worker .\n", "\n", "res_type_req:Excavator\n", " a process:ResourceTypeRequirement ;\n", " process:quantityNeeded 1 ;\n", " process:relatesToResourceType res_type:Excavator .\n", "\n", "res_type_req:Worker\n", " a process:ResourceTypeRequirement ;\n", " process:quantityNeeded 2 ;\n", " process:relatesToResourceType res_type:Worker .\n", "\n", "res_type:Excavator\n", " a resource:ResourceType, resource:EquipmentType ;\n", " dcterms:identifier \"4\"^^xsd:string ;\n", " dcterms:title \"Excavator\"^^xsd:string ;\n", " resource:costPerHour 1500 ;\n", " resource:maxUnit 2 .\n", "\n", "res_type:Worker\n", " a resource:ResourceType, resource:WorkerRole ;\n", " dcterms:identifier \"8\"^^xsd:string ;\n", " dcterms:title \"Worker\"^^xsd:string ;\n", " resource:costPerHour 200 ;\n", " resource:maxUnit 10 .\n", " \"\"\",\n", " format=\"turtle\"\n", ")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "qres = g.query(\"\"\"PREFIX rdf: \n", "PREFIX rdfs: \n", "PREFIX facility: \n", "PREFIX process: \n", "PREFIX resource: \n", "\n", "SELECT ?quantityNeeded ?maxUnit WHERE {\n", " ?res_type_req a process:ResourceTypeRequirement .\n", " ?res_type_req process:quantityNeeded ?quantityNeeded .\n", " ?res_type_req process:relatesToResourceType ?res_type .\n", " ?res_type resource:maxUnit ?maxUnit .\n", " FILTER ((?maxUnit >= ?quantityNeeded ))\n", "}\"\"\")\n" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(rdflib.term.Literal('1', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal('2', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')))\n", "(rdflib.term.Literal('2', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal('10', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')))\n" ] } ], "source": [ "\n", "for row in qres:\n", " print(f\"{row.quantityNeeded, row.maxUnit}\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.10.2" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "a9c44c8ff930b067c6bc3f134a348d3cb9f19f01dfb46c39e0c18c228169b636" } } }, "nbformat": 4, "nbformat_minor": 2 }