From a625c91f99e7c1b1a0fd7933c339fccb901a2b90 Mon Sep 17 00:00:00 2001
From: Timofey Arkhangelskiy <timarkh@gmail.com>
Date: Tue, 24 Jan 2023 12:52:32 +0100
Subject: [PATCH] Add some test queries, add word layer to Tsakorpus advanced
 view

---
 common/search_retrieve.py           |  1 +
 common/tsakorpus_query_parser.py    |  1 +
 common/tsakorpus_response_parser.py | 15 +++++++++++++++
 test_queries.txt                    | 10 ++++++++++
 4 files changed, 27 insertions(+)
 create mode 100644 test_queries.txt

diff --git a/common/search_retrieve.py b/common/search_retrieve.py
index 4738e17..b04d523 100644
--- a/common/search_retrieve.py
+++ b/common/search_retrieve.py
@@ -45,6 +45,7 @@ class Record:
             })
         return record
 
+
 if __name__ == '__main__':
     pass
 
diff --git a/common/tsakorpus_query_parser.py b/common/tsakorpus_query_parser.py
index abfe9d3..7ea8e10 100644
--- a/common/tsakorpus_query_parser.py
+++ b/common/tsakorpus_query_parser.py
@@ -6,6 +6,7 @@ from .query_parser import QueryParser
 from .config import ResourceConfig
 from .diagnostics import Diagnostic, DiagnosticTypes
 
+
 class TsakorpusQueryParser(QueryParser):
     """
     Parses search queries for Tsakorpus-based corpora.
diff --git a/common/tsakorpus_response_parser.py b/common/tsakorpus_response_parser.py
index 68b8d29..7658d68 100644
--- a/common/tsakorpus_response_parser.py
+++ b/common/tsakorpus_response_parser.py
@@ -27,6 +27,14 @@ class TsakorpusResponseParser:
         lemmasStr = '_'
         pos = set()
         posStr = '_'
+        word = ''
+        wordNodes = annoTree.xpath('div[@class="popup_word"]/span[@class="popup_wf"]')
+        for node in wordNodes:
+            if node.text is not None:
+                if len(word) > 0:
+                    # This should not happen, but just in case
+                    word += '|'
+                word += node.text
         lexNodes = annoTree.xpath('div[@class="popup_word"]/div[@class="popup_ana"]/span[@class="popup_lex"]')
         for node in lexNodes:
             if node.text is not None:
@@ -42,6 +50,13 @@ class TsakorpusResponseParser:
         if len(pos) > 0:
             posStr = '|'.join(p for p in sorted(pos))
 
+        if 'word' not in record.layers:
+            record.layers['word'] = []
+        record.layers['word'].append({
+            'ref': segID,
+            'value': word
+        })
+
         if 'pos' not in record.layers:
             record.layers['pos'] = []
         record.layers['pos'].append({
diff --git a/test_queries.txt b/test_queries.txt
new file mode 100644
index 0000000..c9143d0
--- /dev/null
+++ b/test_queries.txt
@@ -0,0 +1,10 @@
+http://127.0.0.1:5000/fcs-endpoint/flc	Implicit explain
+http://127.0.0.1:5000/fcs-endpoint/flc?operation=explain	Explicit explain
+http://127.0.0.1:5000/fcs-endpoint/flc?operation=searchRetrieve&query=regnum%20domni	Formulae -- Simple search ("regnum domni", 11 hits)
+http://127.0.0.1:5000/fcs-endpoint/flc?operation=searchRetrieve&query=regnum%20domni%20AND%20in	Formulae -- Simple search with boolean operator ("regnum domni" AND "in", 6 hits)
+http://127.0.0.1:5000/fcs-endpoint/flc?operation=searchRetrieve&query=regnum%20OR%20dominus	Formulae -- Simple search with boolean operator ("regnum" OR "dominus", 815 hits)
+http://127.0.0.1:5000/fcs-endpoint/test?operation=searchRetrieve&query=ke%20OR%20no	Tsakorpus -- Simple search with boolean operator ("ke" OR "no")
+http://127.0.0.1:5000/fcs-endpoint/test?operation=searchRetrieve&query=ke%20AND%20no	Tsakorpus -- Simple search with boolean operator ("ke" AND "no", 103 hits)
+http://127.0.0.1:5000/fcs-endpoint/test?operation=searchRetrieve&query=ke%20no	Tsakorpus -- Simple search with multiple words ("ke no", 18 hits)
+http://127.0.0.1:5000/fcs-endpoint/test?operation=searchRetrieve&query=ke%20no	Tsakorpus -- Simple search with multiple words ("ke no", 18 hits)
+http://127.0.0.1:5000/fcs-endpoint/test?operation=searchRetrieve&query=ke%20AND%20no&x-fcs-dataviews=adv	Tsakorpus -- Simple search with boolean operator, advanced view ("ke" AND "no", 103 hits)
-- 
GitLab