Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fcs-clarin-endpoint-hamburg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkhangelskiy, Timofey
fcs-clarin-endpoint-hamburg
Commits
d8f76456
Commit
d8f76456
authored
2 years ago
by
Arkhangelskiy, Timofey
Browse files
Options
Downloads
Patches
Plain Diff
Build GET string for simple Tsakorpus queries
parent
cd9724df
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/tsakorpus_query_parser.py
+23
-3
23 additions, 3 deletions
common/tsakorpus_query_parser.py
with
23 additions
and
3 deletions
common/tsakorpus_query_parser.py
+
23
−
3
View file @
d8f76456
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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment