mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Add first things to get more context for one match.
This commit is contained in:
		@@ -294,4 +294,7 @@ class CQiWrapper(CQiClient):
 | 
			
		||||
        t1 = time.time()
 | 
			
		||||
        t_total = t1 - t0
 | 
			
		||||
        logger.warning('Got all sentences informations in {} seconds'. format(t_total))
 | 
			
		||||
        return context_sentences, all_cpos_infos, text_lookup
 | 
			
		||||
        match_context = {'context_s_cpos': context_sentences,
 | 
			
		||||
                         'cpos_lookup': all_cpos_infos,
 | 
			
		||||
                         'text_lookup': text_lookup}
 | 
			
		||||
        return match_context
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,7 @@ def corpus_analysis(message):
 | 
			
		||||
        socketio.emit('query', '[424]: Failed Dependency',
 | 
			
		||||
                      room=request.sid)
 | 
			
		||||
        return
 | 
			
		||||
    """ Prepare and execute a query """
 | 
			
		||||
    # Prepare and execute a query
 | 
			
		||||
    corpus_name = 'CORPUS'
 | 
			
		||||
    query = str(message['query'])
 | 
			
		||||
    result_len = int(message['hits_per_page'])
 | 
			
		||||
@@ -57,6 +57,21 @@ def corpus_analysis(message):
 | 
			
		||||
    socketio.emit('corpus_analysis', results, room=request.sid)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@socketio.on('inspect_match')
 | 
			
		||||
@login_required
 | 
			
		||||
def inspect_match(message):
 | 
			
		||||
    client = corpus_analysis_clients.get(request.sid)
 | 
			
		||||
    if client is None:
 | 
			
		||||
        socketio.emit('query', '[424]: Failed Dependency',
 | 
			
		||||
                      room=request.sid)
 | 
			
		||||
        return
 | 
			
		||||
    # Get more context for given match CPOS
 | 
			
		||||
    match_context = client.get_sentences(message['cpos'],
 | 
			
		||||
                                         get_surrounding_s=True,
 | 
			
		||||
                                         l_r_s_context_additional_len=3)
 | 
			
		||||
    socketio.emit('match_context', match_context, room=request.sid)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def corpus_analysis_session_handler(app, corpus_id, session_id):
 | 
			
		||||
    with app.app_context():
 | 
			
		||||
        ''' Setup analysis session '''
 | 
			
		||||
 
 | 
			
		||||
@@ -137,6 +137,16 @@
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div id="context-modal" class="modal">
 | 
			
		||||
  <div class="modal-content">
 | 
			
		||||
    <h4>Modal Header</h4>
 | 
			
		||||
    <p>A bunch of text</p>
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="modal-footer">
 | 
			
		||||
    <a href="#!" class="modal-close waves-effect waves-green btn-flat">Agree</a>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
  var loadingModal;
 | 
			
		||||
  document.addEventListener("DOMContentLoaded", function() {
 | 
			
		||||
@@ -196,9 +206,10 @@
 | 
			
		||||
 | 
			
		||||
    queryResultsElement.innerHTML = "";
 | 
			
		||||
 | 
			
		||||
    for (let match of result['matches']) {
 | 
			
		||||
    for (let [index, match] of result['matches'].entries()) {
 | 
			
		||||
      matchElement = document.createElement("tr");
 | 
			
		||||
      matchElement.classList.add("match");
 | 
			
		||||
      matchElement.dataset.index = index;
 | 
			
		||||
      matchTextTitlesElement = document.createElement("td");
 | 
			
		||||
      matchTextTitlesElement.classList.add("text-titles");
 | 
			
		||||
      matchElement.append(matchTextTitlesElement);
 | 
			
		||||
@@ -237,6 +248,16 @@
 | 
			
		||||
        tokenElements.push(tokenElement);
 | 
			
		||||
        textTitles.add(result["text_lookup"][token["text"]]["title"]);
 | 
			
		||||
      }
 | 
			
		||||
      var moreContextBtn = document.createElement("a");
 | 
			
		||||
      moreContextBtn.setAttribute("class", "btn-floating btn waves-effect waves-light teal right");
 | 
			
		||||
      moreContextBtn.innerHTML = '<i class="material-icons">search</i>';
 | 
			
		||||
      matchHitElement.append(document.createElement("br"), document.createElement("br"));
 | 
			
		||||
      matchHitElement.append(moreContextBtn);
 | 
			
		||||
      moreContextBtn.onclick = function(){
 | 
			
		||||
        var cpos = match["hit"];
 | 
			
		||||
        socket.emit("inspect_match", {"cpos": cpos});
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      matchTextTitlesElement.innerText = [...textTitles].join(",");
 | 
			
		||||
      matchElement.append(matchHitElement);
 | 
			
		||||
      matchRightContextElement = document.createElement("td");
 | 
			
		||||
@@ -277,15 +298,22 @@
 | 
			
		||||
                                 </td>
 | 
			
		||||
                                 <td class="left-align">
 | 
			
		||||
                                   Title: ${result["text_lookup"][token["text"]]["title"]}<br>
 | 
			
		||||
                                   Author: ${result["text_lookup"][token["text"]]["title"]}<br>
 | 
			
		||||
                                   Author: ${result["text_lookup"][token["text"]]["author"]}<br>
 | 
			
		||||
                                   Publishing year: ${result["text_lookup"][token["text"]]["publishing_year"]}
 | 
			
		||||
                                 </td>
 | 
			
		||||
                               </tr>
 | 
			
		||||
                             </table>`,
 | 
			
		||||
                   "inDuration": 2500,
 | 
			
		||||
                   "inDuration": 1500,
 | 
			
		||||
                   "margin": 15,
 | 
			
		||||
                   "position": "top",
 | 
			
		||||
                   "transitionMovement": 0});
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  socket.on("match_context", function(message) {
 | 
			
		||||
    console.log(message);
 | 
			
		||||
    var elems = document.querySelectorAll('.modal');
 | 
			
		||||
    var instances = M.Modal.init(elems);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user