Skip to content
Snippets Groups Projects
Commit d8f76456 authored by Arkhangelskiy, Timofey's avatar Arkhangelskiy, Timofey
Browse files

Build GET string for simple Tsakorpus queries

parent cd9724df
Branches
No related tags found
No related merge requests found
import copy
from urllib.parse import quote
import re
from .query_parser import QueryParser
from .config import ResourceConfig
......@@ -11,6 +11,22 @@ class TsakorpusQueryParser(QueryParser):
rxTsakorpusBool = re.compile('[()|,]')
def build_get_string(self, getParams, config):
"""
Build a GET string (everything after the ?) from a description
of the GET parameters in the getParams list.
"""
nWords = len(self.term_indexes(getParams))
s = 'n_words=' + str(nWords)
for param in getParams:
if type(param[1]) is list:
index = '_'.join(str(v) for v in param[1])
else:
index = str(param[1])
s += '&' + param[0] + index + '=' + quote(param[2])
s += '&page_size=' + str(config.max_hits)
return s
def term_query(self, query, config):
"""
Return list of query parameters for one term or sequence of terms.
......@@ -95,13 +111,17 @@ class TsakorpusQueryParser(QueryParser):
The function is recursive and only looks at the part of the string
delimited by start and end parameters.
"""
print(query, start, end)
if end == -1:
# Top-level call, so return a finalized GET string
end = len(query)
if end == 0:
raise Diagnostic(DiagnosticTypes.sru, 27)
if self.rxTermQuery.search(query) is not None:
return self.term_query(query, config)
return self.build_get_string(self.term_query(query, config), config)
return self.build_get_string(self.translate_fcsql(query, config,
basicSearch=basicSearch,
start=start, end=end),
config)
# if query.count('(') != query.count(')'):
# return None
if len(query) <= 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment