Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:CentreForResearchInAppliedLingui…
Browse files Browse the repository at this point in the history
…stics/clic into develop
  • Loading branch information
jdejoode committed Feb 18, 2015
2 parents 1360559 + dddf24a commit 704b0a2
Show file tree
Hide file tree
Showing 12 changed files with 539 additions and 286 deletions.
15 changes: 1 addition & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@ CLiC Project

Cheshire3 databases and applications for the CLiC Project.


Install
-------

::

python setup.py develop


Run
---

Start a web-server to make the interface available locally::

python -m clic.dickens.web.index


Then open a web-browser and go to http://127.0.0.1:8000/dickens/

:: sudo su -c "uwsgi --http :8080 --wsgi-file clic/dickens/web/flask/api.py --callable app" cheshire
44 changes: 44 additions & 0 deletions clic/dickens/chapter_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json
import os

from cheshire3.baseObjects import Session
from cheshire3.document import StringDocument
from cheshire3.internal import cheshire3Root
from cheshire3.server import SimpleServer

BASE_DIR = os.path.dirname(__file__)
raw_booklist = open(os.path.join(BASE_DIR, 'booklist.json'), 'r')
booklist = json.load(raw_booklist)

class Chapter_Repository(object):

def __init__(self):
self.session = Session()
self.session.database = 'db_dickens'
self.serv = SimpleServer(self.session,
os.path.join(cheshire3Root, 'configs', 'serverConfig.xml')
)
self.db = self.serv.get_object(self.session, self.session.database)
self.qf = self.db.get_object(self.session, 'defaultQueryFactory')

def get_chapter(self, chapter_number, book):
""" Returns transformed XML for given chapter & book """
query = self.qf.get_query(self.session, 'c3.book-idx = "%s"' % book)
result_set = self.db.search(self.session, query)
chapter_ptr = result_set[chapter_number - 1]
chapter = chapter_ptr.fetch_record(self.session)
transformer = self.db.get_object(self.session, 'chapterView-Txr')
formatted_chapter = transformer.process_record(self.session, chapter).get_raw(self.session)
for b in booklist:
if (b[0][0] == book):
book_title = b[0][1]
return formatted_chapter, book_title

def get_raw_chapter(self, chapter_number, book):
""" Returns raw chapter XML for given chapter & book """
query = self.qf.get_query(self.session, 'c3.book-idx = "%s"' % book)
result_set = self.db.search(self.session, query)
chapter_ptr = result_set[chapter_number - 1]
chapter = chapter_ptr.fetch_record(self.session)
return chapter.get_dom(self.session)

21 changes: 12 additions & 9 deletions clic/dickens/web/flask/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import ## help python find modules within clic package (see John H email 09.04.2014)
from flask import Flask
import json
import urllib

app = Flask(__name__,static_url_path='')

Expand All @@ -11,6 +12,7 @@
from clic.dickens.keywords import Keywords
from clic.dickens.clusters import Clusters
from clic.dickens.concordance_new import Concordancer_New
from clic.dickens.chapter_repository import Chapter_Repository

from flask import request
from flask import render_template
Expand All @@ -23,6 +25,10 @@

cache = CacheManager(**parse_cache_config_options(cache_opts))

@app.route('/', methods=['GET'])
def index():
return render_template("concordance-form.html")

@app.route('/keywords/', methods=['GET'])
def keywords():
## get search specifications (args):
Expand All @@ -32,12 +38,6 @@ def keywords():
keywords = json.dumps(keyword_result) # return keyword list as json
return keywords

## ajax route: not in use here
# @app.route('/ajax-keywords',methods=['GET'])
# def ajax_keyords():
# args = request.args
# #return json.dumps(fetchKeywords(args))

@app.route('/clusters/', methods=['GET'])
def clusters():
args = request.args
Expand All @@ -51,26 +51,29 @@ def concordances():
concordances_result = fetchConcordance(args)
concordances = json.dumps(concordances_result)
return concordances

@app.route('/chapter/<book>/<int:number>/')
def chapterView(number, book):
chapterRepository = Chapter_Repository()
chapter, book_title = chapterRepository.get_chapter(number, book)
return render_template("chapter-view.html", content=chapter, book_title=book_title)

#@cache.cache('keywords', expire=3600) ## expires after 3600 secs
def fetchKeywords(args):

keyworder = Keywords()
args = processArgs(args, 'keywords')
keywords = keyworder.list_keywords(args[0], args[1], args[2], args[3], args[4])
return {'keywords':keywords}

#@cache.cache('clusters', expire=3600)
def fetchClusters(args):

cluster = Clusters()
args = processArgs(args, 'clusters')
clusterlist = cluster.list_clusters(args[0], args[1])
return {'clusters' : clusterlist}

#@cache.cache('concordances', expire=3600)
def fetchConcordance(args):

concordancer = Concordancer_New()
args = processArgs(args, 'concordances')
concordances = concordancer.create_concordance(args[0], args[1], args[2], args[3])
Expand Down
7 changes: 6 additions & 1 deletion clic/dickens/web/flask/static/concordanceResults.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ <h2 class="with-pills">Concordance Results</h2>
<script>
$(function () {

$('#dataTableConcordance tbody').on( 'click', 'tr', function () {
window.location = $(this).data('url');
} );

$('#plotWrap').hide();

// custom sort functions see http://www.datatables.net/release-datatables/examples/basic_init/multi_col_sort.html
Expand Down Expand Up @@ -294,8 +298,9 @@ <h2 class="with-pills">Concordance Results</h2>
var wordsLhs = '';
var wordsRhs = '';
var node = '';
var chapterViewUrl = '/chapter/' + data.concordances[x][3][0] + '/' + data.concordances[x][3][2] + '/';

content += '<tr>';
content += '<tr class="clickable_row" data-url="' + chapterViewUrl + '">';
// counter
content += '<td>' + x + '</td>';
// words left
Expand Down
10 changes: 10 additions & 0 deletions clic/dickens/web/flask/templates/chapter-view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "layout/default.html" %}

{% block title %}
Chapter {{ super() }}
{% endblock %}

{% block body %}
<h2>{{ book_title }}</h2>
{{ content|safe }}
{% endblock %}
84 changes: 0 additions & 84 deletions clic/dickens/web/flask/templates/clusters.html

This file was deleted.

Loading

0 comments on commit 704b0a2

Please sign in to comment.