From 0ec3429576b285cbcca5431654c911e39f1dd292 Mon Sep 17 00:00:00 2001
From: Cyrille Berger <cyrille.berger@liu.se>
Date: Tue, 10 Oct 2023 10:03:30 +0200
Subject: [PATCH] update script to include the model in the dataset

---
 generate.py | 45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/generate.py b/generate.py
index 958aa3c..b775f14 100755
--- a/generate.py
+++ b/generate.py
@@ -1,6 +1,27 @@
 #!/usr/bin/python3
 
 import itertools
+import sys
+
+#
+# ./generate.py [options]
+# --validate indicates that you want to validate and show the model for the queries generated by the script
+# --localhost indicates that you want to use a scql_analyser server located on this computer (default is to use terra8 webserver)
+# --no-model indicates that you want to generate dataset without generating models
+
+validate  = '--validate' in sys.argv
+localhost = '--localhost' in sys.argv
+nomodel   = '--no-model' in sys.argv
+
+if localhost:
+  WEBSERVER_URI = 'http://localhost:8181/api/get_model'
+  WEBSERVER_AUTH = None
+else:
+  WEBSERVER_URI = 'http://terra8.ida.liu.se/scql_analyser/api/get_model'
+  WEBSERVER_AUTH = ('TDDE19', 'TDDE19')
+
+
+
 
 class select_query:
   def __init__(self, variables, constraints, restrictions):
@@ -50,13 +71,23 @@ def add_query(queries, sentence_fragments, query_def):
   for s in sentences:
     queries.append([s, query_def])
   return queries
-  
+
 def generate_scql(queries):
   # Take a list of queries and generate the scQL query
   for s,q in queries:
     print(s)
     print(q.to_scql())
 
+def generate_model_scql(queries):
+  import requests
+  # Take a list of queries and generate the scQL query
+  for s,q in queries:
+    print(s)
+    print(q.to_scql())
+    payload = {'query': q.to_scql()}
+    r = requests.post(WEBSERVER_URI, data=payload, auth=WEBSERVER_AUTH).json()
+    print(r["model"]["models"])
+
 def validate_scql(queries):
   import requests
   from termcolor import colored
@@ -64,7 +95,8 @@ def validate_scql(queries):
   results = []
   for s,q in queries:
     payload = {'query': q.to_scql()}
-    r = requests.post('http://localhost:8181/api/get_model', data=payload).json()
+    
+    r = requests.post(WEBSERVER_URI, data=payload, auth=WEBSERVER_AUTH).json()
     # print(r)
     if not r['model']['parse']:
       print(f"Failed to parse: '{colored(q.to_scql(), 'blue')}' with error '{colored(r['model']['message'], 'red')}'")
@@ -160,5 +192,10 @@ for bbd in human_sick_injured_statuses:
 queries = add_query(queries, [desire_perf, human_in_need_statuses], select_query([[mu("scql_types:salient_point"), "human"]], [["human.klass", "=", mu("ex:human")], ["human.status",  "in", all_human_bad_statuses]], []))
 
 
-generate_scql(queries)
-# validate_scql(queries)
+if validate:
+  validate_scql(queries)
+elif nomodel:
+  generate_scql(queries)
+else:
+  generate_model_scql(queries)
+
-- 
GitLab