Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
SFB 1288 - INF
nopaque
Commits
4f531225
Commit
4f531225
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Use CQiClient for testing purpose.
parent
0d441a93
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/corpora/events.py
+31
-17
31 additions, 17 deletions
app/corpora/events.py
with
31 additions
and
17 deletions
app/corpora/events.py
+
31
−
17
View file @
4f531225
...
@@ -3,7 +3,8 @@ from app.events import connected_sessions
...
@@ -3,7 +3,8 @@ from app.events import connected_sessions
from
app.models
import
Corpus
from
app.models
import
Corpus
from
flask
import
current_app
,
request
from
flask
import
current_app
,
request
from
flask_login
import
current_user
,
login_required
from
flask_login
import
current_user
,
login_required
from
.CQiWrapper.CQiWrapper
import
CQiWrapper
from
.CQiWrapper.CQiClient
import
CQiClient
from
.CQiWrapper.CQi
import
CONST_FIELD_MATCH
,
CONST_FIELD_MATCHEND
'''
'''
...
@@ -40,17 +41,32 @@ def init_corpus_analysis(corpus_id):
...
@@ -40,17 +41,32 @@ def init_corpus_analysis(corpus_id):
def
recv_query
(
message
):
def
recv_query
(
message
):
logger
.
warning
(
message
)
logger
.
warning
(
message
)
analysis_client
=
analysis_clients
[
request
.
sid
]
analysis_client
=
analysis_clients
[
request
.
sid
]
corpus_name
=
'
CORPUS
'
"""
Prepare and execute a query
"""
result_subcorpus_name
=
'
Query-results
'
# should be set by the user somehow
corpus
=
'
CORPUS
'
query
=
message
[
'
query
'
]
query
=
'"
and
"
;
'
analysis_client
.
set_corpus_name
(
corpus_name
)
query_subcorpus
=
'
Results
'
analysis_client
.
create_attribute_strings
()
analysis_client
.
cqp_query
(
corpus
,
query_subcorpus
,
query
)
analysis_client
.
query_subcorpus
(
result_subcorpus_name
,
query
)
"""
Evaluate query results
"""
logger
.
warning
(
'
Vorher
'
)
match_corpus
=
'
{}:{}
'
.
format
(
corpus
,
query_subcorpus
)
#results = analysis_client.show_results()
match_num
=
analysis_client
.
cqp_subcorpus_size
(
match_corpus
)
results
=
analysis_client
.
get_cpos_info
([
1995
,
2000
],
analysis_client
)
match_num
=
min
(
19
,
match_num
)
logger
.
warning
(
'
Nacher
'
)
if
match_num
==
0
:
logger
.
warning
(
'
Query results: {}
'
.
format
(
str
(
results
)))
print
(
'
No matches found.
'
)
exit
()
if
not
analysis_client
.
cqp_subcorpus_has_field
(
match_corpus
,
CONST_FIELD_MATCH
):
print
(
'
Error.
'
)
exit
()
if
not
analysis_client
.
cqp_subcorpus_has_field
(
match_corpus
,
CONST_FIELD_MATCHEND
):
print
(
'
Error
'
)
exit
()
match_boundaries
=
zip
(
analysis_client
.
cqp_dump_subcorpus
(
match_corpus
,
CONST_FIELD_MATCH
,
0
,
match_num
-
1
),
analysis_client
.
cqp_dump_subcorpus
(
match_corpus
,
CONST_FIELD_MATCHEND
,
0
,
match_num
-
1
))
matches
=
[]
for
match_start
,
match_end
in
match_boundaries
:
tokens
=
analysis_client
.
cl_cpos2str
(
'
{}.word
'
.
format
(
corpus
),
range
(
match_start
,
match_end
+
1
))
pos
=
analysis_client
.
cl_cpos2str
(
'
{}.pos
'
.
format
(
corpus
),
range
(
match_start
,
match_end
+
1
))
matches
.
append
({
'
tokens
'
:
tokens
,
'
pos
'
:
pos
})
logger
.
warning
(
matches
)
def
observe_corpus_analysis_connection
(
app
,
corpus_id
,
session_id
):
def
observe_corpus_analysis_connection
(
app
,
corpus_id
,
session_id
):
...
@@ -59,10 +75,8 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
...
@@ -59,10 +75,8 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
while
corpus
.
status
!=
'
analysing
'
:
while
corpus
.
status
!=
'
analysing
'
:
db
.
session
.
refresh
(
corpus
)
db
.
session
.
refresh
(
corpus
)
socketio
.
sleep
(
3
)
socketio
.
sleep
(
3
)
analysis_client
=
CQiWrapper
(
host
=
'
{}_analysis_container{}
'
.
format
(
corpus
.
creator
.
username
,
corpus
.
id
),
analysis_client
=
CQiClient
(
host
=
'
{}_analysis_container{}
'
.
format
(
corpus
.
creator
.
username
,
corpus
.
id
),
port
=
4877
)
password
=
'
opaque
'
,
port
=
4877
,
analysis_client
.
ctrl_connect
(
'
opaque
'
,
'
opaque
'
)
username
=
'
opaque
'
)
analysis_client
.
connect
()
analysis_clients
[
session_id
]
=
analysis_client
analysis_clients
[
session_id
]
=
analysis_client
socketio
.
emit
(
'
init_corpus_analysis
'
,
'
Ready
'
,
room
=
session_id
)
socketio
.
emit
(
'
init_corpus_analysis
'
,
'
Ready
'
,
room
=
session_id
)
while
session_id
in
connected_sessions
:
while
session_id
in
connected_sessions
:
...
@@ -76,7 +90,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
...
@@ -76,7 +90,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
socketio.sleep(3)
socketio.sleep(3)
'''
'''
socketio
.
sleep
(
3
)
socketio
.
sleep
(
3
)
analysis_client
.
disconnect
()
analysis_client
.
ctrl_bye
()
analysis_clients
.
pop
(
session_id
,
None
)
analysis_clients
.
pop
(
session_id
,
None
)
analysis_sessions
[
str
(
corpus_id
)].
remove
(
session_id
)
analysis_sessions
[
str
(
corpus_id
)].
remove
(
session_id
)
if
not
analysis_sessions
[
str
(
corpus_id
)]:
if
not
analysis_sessions
[
str
(
corpus_id
)]:
...
...
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