From 833256a45257318409caf24f9b8614dee9813d07 Mon Sep 17 00:00:00 2001
From: daxid <david.rouquet@tetras-libre.fr>
Date: Tue, 18 Jan 2022 10:39:52 +0000
Subject: [PATCH] Add post edit to the OWL extractions to "propagate" the
 instances to subclasses

---
 unsel_dashboard-iterate.ipynb | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/unsel_dashboard-iterate.ipynb b/unsel_dashboard-iterate.ipynb
index 7f5e4a4..f473c79 100644
--- a/unsel_dashboard-iterate.ipynb
+++ b/unsel_dashboard-iterate.ipynb
@@ -44,7 +44,7 @@
     "extractionGraph = '/opt/dashboards/tetras-lab-unl-demos/work_graph.ttl' # -- old --- extractionGraph = '/opt/dashboards/tetras-lab-unl-demos/extraction-data-9.ttl'\n",
     "workDir = 'work-data/'\n",
     "webvowlData = '/opt/webvowl'\n",
-    "pane_width = 1300\n",
+    "pane_width = 1250\n",
     "\n",
     "# Fuseki\n",
     "fusekiBase = \"https://fuseki.unsel.tetras-lab.io/unsel/\"\n",
@@ -471,7 +471,7 @@
     "    work_file = dest_file\n",
     "    inferResult = shaclInfer(work_file, 'infer') # apply SHACL inference\n",
     "    graph.parse(data=inferResult) # update graph with inference\n",
-    "    graph.serialize(destination=dest_file, base=base_ref, format='turtle') # serialize graph after inference\n",
+    "    #graph.serialize(destination=dest_file, base=base_ref, format='turtle') # serialize graph after inference\n",
     "    return graph, inferResult"
    ]
   },
@@ -709,6 +709,22 @@
     "sparqlUpdate.setQuery('INSERT DATA {'+g.serialize(format='nt')+'}')\n",
     "sparqlLog = sparqlUpdate.query()\n",
     "\n",
+    "# Requête de post-traitement pour propager les instances aux sous classes pour chaque phrase\n",
+    "# -> Il faudra sans doute revoir la classe qui accueille les instances à l'extraction\n",
+    "def instToSubclasses():\n",
+    "    instToSubclassesQuery = \"\"\"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
+    "PREFIX sys: <https://unsel.tetras-libre.fr/tenet/frame/system-ontology/>\n",
+    "INSERT {?inst a ?subClass .}\n",
+    "WHERE {  \n",
+    "  ?class rdfs:subClassOf* sys:Structure ; sys:from_structure ?sentence .\n",
+    "  ?subClass rdfs:subClassOf+ ?class ; sys:from_structure ?sentence .  \n",
+    "  ?inst a ?class ; sys:from_structure ?sentence .  \n",
+    "}\"\"\"\n",
+    "    sparqlUpdate.setQuery(instToSubclassesQuery)\n",
+    "    sparqlLog = sparqlUpdate.query()\n",
+    "\n",
+    "instToSubclasses()\n",
+    "    \n",
     "#factoidList = [x.replace('..','/opt/dashboards') for x in glob(storeBase+\"/*/current/*factoid.ttl\")]\n",
     "#owl2vowl(FRAME_DIR + frame_file, importList=factoidList)\n",
     "\n",
@@ -755,6 +771,7 @@
     "    factoidGraph.parse(sentencePath)    \n",
     "    sparqlUpdate.setQuery('INSERT DATA {'+factoidGraph.serialize(format='nt')+'}')\n",
     "    sparqlLog = sparqlUpdate.query()\n",
+    "    instToSubclasses()\n",
     "    createVerificationMessages(storeBase+uuidStr)"
    ]
   },
@@ -770,7 +787,8 @@
     "# Fonctions pour la mise à jour globale du corpus (ne pas exécuter en mode \"Tableau de bord\")\n",
     "\n",
     "def updateAllFactoids():\n",
-    "    dirList = glob('/opt/dashboards/store/CCTP-SRSA-IP-20210831/*')\n",
+    "    dirList = ['/opt/dashboards/store/CCTP-SRSA-IP-20210831/SRSA-IP_STB_PHON_00100']\n",
+    "    #dirList = glob('/opt/dashboards/store/CCTP-SRSA-IP-20210831/*')\n",
     "    for directory in dirList:\n",
     "        if directory.split('/')[-1] != '0_NONE':\n",
     "            print(directory)\n",
@@ -781,6 +799,7 @@
     "        \n",
     "        \n",
     "def updateAllVerificationMessages():\n",
+    "    #dirList = ['/opt/dashboards/store/CCTP-SRSA-IP-20210831/SRSA-IP_STB_PHON_00100']\n",
     "    dirList = glob('/opt/dashboards/store/CCTP-SRSA-IP-20210831/*')\n",
     "    for directory in dirList:\n",
     "        if directory.split('/')[-1] != '0_NONE':\n",
-- 
GitLab