def applicationhelp(self): """Display the OLD Application help page. This page is generated from the entry with name='help' of the page table of the model. This page can be edited by administrators. """ # Get the helppage from the model helppage_q = meta.Session.query(model.Page).filter(model.Page.name == u"help") helppage = helppage_q.first() c.heading = helppage.heading # Get the help page content and translate it to HTML content = helppage.content content = h.literal(h.rst2html(content)) c.content = content return render("/derived/help/help.html")
def applicationhelp(self): """Display the OLD Application help page. This page is generated from the entry with name='help' of the page table of the model. This page can be edited by administrators. """ # Get the helppage from the model helppage_q = meta.Session.query( model.Page).filter(model.Page.name == u'help') helppage = helppage_q.first() c.heading = helppage.heading # Get the help page content and translate it to HTML content = helppage.content content = h.literal(h.rst2html(content)) c.content = content return render('/derived/help/help.html')
def getSVGTree(self, id): """Draw a tree using NLTK and the svg-tree-drawer JavaScript library. """ # PTB Tree #ptbTree = '(S (NP (N John)) (VP (V ran)))' #ptbTree = '(TOP (S (NP-SBJ (PRP It)) (VP (VBZ has) (NP (NP (DT no) (NN bearing)) (PP-DIR (IN on) (NP (NP (PRP$ our) (NN work) (NN force)) (NP-TMP (NN today)))))) (. .)))' #ptbTree = u"(TP (DP (D the) (NP (NP (N dog)) (CP (DP 0) (C' (C that) (TP (DP I) (T' (T 0_PAST) (VP (V see) (DP who)))))))) (T' (T 0_PAST) (VP (V be) (AP (A black)))))" #ptbTree = u'(TOP (S (NP-SBJ (NP (NNP Pierre) (NNP Vinken)) (, ,) (ADJP (NP (CD 61) (NNS years)) (JJ old)) (, ,)) (VP (MD will) (VP (VB join) (NP (DT the) (NN board)) (PP-CLR (IN as) (NP (DT a) (JJ nonexecutive) (NN director))) (NP-TMP (NNP Nov.) (CD 29)))) (. .)))' ptbTree = id # NLTK Tree nltkTree = ptb2nltk(ptbTree) # SVG Tree if nltkTree: svgTree = nltk2svg(nltkTree) result = h.literal(svgTree) else: result = u'Invalid Tree' return result
def browse(self, id=None): """Generates page for browsing Forms as dictionary entries. Id variable (regex '[0-9]+_(ol|ml)') encodes both the index of the first letter of the words being browsed and the language (object or meta-) being browsed. A first letter index of 1000000 means browse everything. """ # Get OL orthography as an HTML table of links to browse actions OLOrthography = app_globals.defaultOutputOrthography[1] OLOrthographyAsList = OLOrthography.orthographyAsList OLOrthographyX = [ '<a href="%s" %s>%s</a>' % (url(controller='dictionary', action='browse', id=str(OLOrthographyAsList.index(x)) + '_ol', anchor='hl'), 'title="browse by %s character \'%s\'"' % (app_globals.objectLanguageName, h.storageToOutputTranslate( x[0])), h.storageToOutputTranslate(x[0])) for x in OLOrthographyAsList ] c.OLOrthographyTable = h.literal( h.tablify(OLOrthographyX, 14, 'orthographyAsLinks')) # Get ML orthography as an HTML table of links to browse actions MLOrthography = app_globals.metaLanguageOrthography MLOrthographyAsList = MLOrthography.orthographyAsList MLOrthographyX = [ '<a href="%s" %s>%s</a>' % (url(controller='dictionary', action='browse', id=str(MLOrthographyAsList.index(x)) + '_ml', anchor='hl'), 'title="browse by %s character \'%s\'"' % (app_globals.metaLanguageName, x[0]), x[0]) for x in MLOrthographyAsList ] c.MLOrthographyTable = h.literal( h.tablify(MLOrthographyX, 14, 'orthographyAsLinks')) # If there is a valid first-letter index, # build a query and return the appropriate variables. patt = re.compile('^[0-9]+_(ol|ml)$') if id and patt.search(id): headCharIndex = id.split('_')[0] c.languageToSortBy = id.split('_')[1] langToOrth = { 'ol': [ app_globals.storageOrthography[1], OLOrthographyAsList, 'transcription' ], 'ml': [MLOrthography, MLOrthographyAsList, 'gloss'] } orthography = langToOrth[c.languageToSortBy][0] orthographyAsList = langToOrth[c.languageToSortBy][1] try: c.headChar = orthographyAsList[int(headCharIndex)] except IndexError: c.headChar = None wordList_q = meta.Session.query(model.Form) wordList_q = wordList_q.filter( not_(model.Form.transcription.like(u'% %'))) # The default case # Non-empty headChar means a letter was clicked on if id and c.headChar: # filter and sort wordList for object-language-to-metalanguage view if c.languageToSortBy == 'ol': wordList_q = wordList_q.filter( model.Form.transcription.op('regexp')( '^(%s)' % '|'.join(c.headChar))) # existence of supergraphs means we have to filter the query # of Forms whose transcription/gloss begins with a supergraph superGraphs = getSuperGraphs(c.headChar, OLOrthographyAsList) if superGraphs: wordList_q = wordList_q.filter( not_( model.Form.transcription.op('regexp')( '^(%s)' % '|'.join(superGraphs)))) # sort wordList using functions.CustomSorter class c.wordList = wordList_q.all() if c.wordList: cs = h.CustomSorter(orthography) c.wordList = cs.sort(c.wordList) # filter and sort wordList for metalanguage-to-object-metalanguage view elif c.languageToSortBy == 'ml': wordList_q = wordList_q.outerjoin(model.Form.glosses) wordList_q = wordList_q.filter( model.Gloss.gloss.op('regexp')('^(%s)' % '|'.join(c.headChar))) # existence of supergraphs means we have to filter the query # of Forms whose transcription/gloss begins with a supergraph superGraphs = getSuperGraphs(c.headChar, MLOrthographyAsList) if superGraphs: wordList_q = wordList_q.filter( not_( model.Gloss.gloss.op('regexp')( '^(%s)' % '|'.join(superGraphs)))) wordList = wordList_q.all() if wordList: patt = re.compile('^%s' % c.headChar) newWordList = [] for form in wordList: goodGlosses = [ gloss.gloss for gloss in form.glosses if patt.match(gloss.gloss) ] for gg in goodGlosses: newForm = ThinForm(form.id, gg, form.transcription, form.keywords) newWordList.append(newForm) cs = h.CustomSorter(orthography) c.wordList = cs.sort(newWordList) # The special case # id of a million means we are browsing everything! elif id and int(headCharIndex) == 1000000: wordList = wordList_q.all() if c.languageToSortBy == 'ml': newWordList = [] for form in wordList: goodGlosses = [gloss.gloss for gloss in form.glosses] for gg in goodGlosses: newForm = ThinForm(form.id, gg, form.transcription, form.keywords) newWordList.append(newForm) cs = h.CustomSorter(orthography) c.wordList = cs.sort(newWordList) else: cs = h.CustomSorter(orthography) c.wordList = cs.sort(wordList) return render('/derived/dictionary/browse.html')
abort(404) # Get the Form(s) formID = result['formID'] patt = re.compile('^[0-9 ]+$') formIDs = [int(ID.strip().replace(' ', '')) for ID in formID.split(',') if patt.match(ID)] forms = meta.Session.query(model.Form).filter( model.Form.id.in_(formIDs)).all() if forms: for form in forms: if form in file.forms: msg = '<p>Form %s is already associated ' % form.id + \ 'to File %s.</p>' % file.id h.appendMsgToFlash(h.literal(msg)) else: if h.userIsAuthorizedToAccessForm(session['user'], form): file.forms.append(form) msg = '<p>Form %d successfully ' % form.id + \ 'associated to File %d.' % file.id h.appendMsgToFlash(h.literal(msg)) else: msg = '<p>Sorry, you are not authorized to ' + \ 'access form %d.</p>' % form.id h.appendMsgToFlash(h.literal(msg)) meta.Session.commit() session.save() else: msg = u'<p>Sorry, no Forms have any of the following ' + \ u'IDs: %s.</p>' % formID
# Get the Form(s) formID = result['formID'] patt = re.compile('^[0-9 ]+$') formIDs = [ int(ID.strip().replace(' ', '')) for ID in formID.split(',') if patt.match(ID) ] forms = meta.Session.query(model.Form).filter( model.Form.id.in_(formIDs)).all() if forms: for form in forms: if form in file.forms: msg = '<p>Form %s is already associated ' % form.id + \ 'to File %s.</p>' % file.id h.appendMsgToFlash(h.literal(msg)) else: if h.userIsAuthorizedToAccessForm( session['user'], form): file.forms.append(form) msg = '<p>Form %d successfully ' % form.id + \ 'associated to File %d.' % file.id h.appendMsgToFlash(h.literal(msg)) else: msg = '<p>Sorry, you are not authorized to ' + \ 'access form %d.</p>' % form.id h.appendMsgToFlash(h.literal(msg)) meta.Session.commit() session.save() else: msg = u'<p>Sorry, no Forms have any of the following ' + \
def browse(self, id=None): """Generates page for browsing Forms as dictionary entries. Id variable (regex '[0-9]+_(ol|ml)') encodes both the index of the first letter of the words being browsed and the language (object or meta-) being browsed. A first letter index of 1000000 means browse everything. """ # Get OL orthography as an HTML table of links to browse actions OLOrthography = app_globals.defaultOutputOrthography[1] OLOrthographyAsList = OLOrthography.orthographyAsList OLOrthographyX = ['<a href="%s" %s>%s</a>' % ( url( controller='dictionary', action='browse', id=str(OLOrthographyAsList.index(x)) + '_ol', anchor='hl' ), 'title="browse by %s character \'%s\'"' % ( app_globals.objectLanguageName, h.storageToOutputTranslate(x[0]) ), h.storageToOutputTranslate(x[0]) ) for x in OLOrthographyAsList] c.OLOrthographyTable = h.literal( h.tablify(OLOrthographyX, 14, 'orthographyAsLinks')) # Get ML orthography as an HTML table of links to browse actions MLOrthography = app_globals.metaLanguageOrthography MLOrthographyAsList = MLOrthography.orthographyAsList MLOrthographyX = ['<a href="%s" %s>%s</a>' % ( url( controller='dictionary', action='browse', id=str(MLOrthographyAsList.index(x)) + '_ml', anchor='hl' ), 'title="browse by %s character \'%s\'"' % ( app_globals.metaLanguageName, x[0]), x[0] ) for x in MLOrthographyAsList] c.MLOrthographyTable = h.literal( h.tablify(MLOrthographyX, 14, 'orthographyAsLinks')) # If there is a valid first-letter index, # build a query and return the appropriate variables. patt = re.compile('^[0-9]+_(ol|ml)$') if id and patt.search(id): headCharIndex = id.split('_')[0] c.languageToSortBy = id.split('_')[1] langToOrth = { 'ol': [app_globals.storageOrthography[1], OLOrthographyAsList, 'transcription'], 'ml': [MLOrthography, MLOrthographyAsList, 'gloss'] } orthography = langToOrth[c.languageToSortBy][0] orthographyAsList = langToOrth[c.languageToSortBy][1] try: c.headChar = orthographyAsList[int(headCharIndex)] except IndexError: c.headChar = None wordList_q = meta.Session.query(model.Form) wordList_q = wordList_q.filter( not_(model.Form.transcription.like(u'% %')) ) # The default case # Non-empty headChar means a letter was clicked on if id and c.headChar: # filter and sort wordList for object-language-to-metalanguage view if c.languageToSortBy == 'ol': wordList_q = wordList_q.filter( model.Form.transcription.op('regexp')( '^(%s)' % '|'.join(c.headChar)) ) # existence of supergraphs means we have to filter the query # of Forms whose transcription/gloss begins with a supergraph superGraphs = getSuperGraphs(c.headChar, OLOrthographyAsList) if superGraphs: wordList_q = wordList_q.filter( not_(model.Form.transcription.op('regexp')( '^(%s)' % '|'.join(superGraphs))) ) # sort wordList using functions.CustomSorter class c.wordList = wordList_q.all() if c.wordList: cs = h.CustomSorter(orthography) c.wordList = cs.sort(c.wordList) # filter and sort wordList for metalanguage-to-object-metalanguage view elif c.languageToSortBy == 'ml': wordList_q = wordList_q.outerjoin( model.Form.glosses ) wordList_q = wordList_q.filter( model.Gloss.gloss.op('regexp')('^(%s)' % '|'.join(c.headChar)) ) # existence of supergraphs means we have to filter the query # of Forms whose transcription/gloss begins with a supergraph superGraphs = getSuperGraphs(c.headChar, MLOrthographyAsList) if superGraphs: wordList_q = wordList_q.filter( not_(model.Gloss.gloss.op('regexp')( '^(%s)' % '|'.join(superGraphs))) ) wordList = wordList_q.all() if wordList: patt = re.compile('^%s' % c.headChar) newWordList = [] for form in wordList: goodGlosses = [gloss.gloss for gloss in form.glosses if patt.match(gloss.gloss)] for gg in goodGlosses: newForm = ThinForm(form.id, gg, form.transcription, form.keywords) newWordList.append(newForm) cs = h.CustomSorter(orthography) c.wordList = cs.sort(newWordList) # The special case # id of a million means we are browsing everything! elif id and int(headCharIndex) == 1000000: wordList = wordList_q.all() if c.languageToSortBy == 'ml': newWordList = [] for form in wordList: goodGlosses = [gloss.gloss for gloss in form.glosses] for gg in goodGlosses: newForm = ThinForm(form.id, gg, form.transcription, form.keywords) newWordList.append(newForm) cs = h.CustomSorter(orthography) c.wordList = cs.sort(newWordList) else: cs = h.CustomSorter(orthography) c.wordList = cs.sort(wordList) return render('/derived/dictionary/browse.html')