[djangodb commit] r685 - minor update

1 view
Skip to first unread message

codesite...@google.com

unread,
Jun 29, 2009, 2:36:04 AM6/29/09
to compute...@googlegroups.com
Author: PatrickChan7
Date: Sun Jun 28 22:37:06 2009
New Revision: 685

Added:
trunk/misc/patrick/django_monty/monty/
trunk/misc/patrick/django_monty/monty/__init__.py
trunk/misc/patrick/django_monty/monty/forms.py
trunk/misc/patrick/django_monty/monty/models.py
trunk/misc/patrick/django_monty/monty/monty_process.py (contents,
props changed)
trunk/misc/patrick/django_monty/monty/views.py (contents, props
changed)
trunk/misc/patrick/django_monty/templates/
trunk/misc/patrick/django_monty/templates/main_page.html

Log:
minor update

Added: trunk/misc/patrick/django_monty/monty/__init__.py
==============================================================================

Added: trunk/misc/patrick/django_monty/monty/forms.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/django_monty/monty/forms.py Sun Jun 28 22:37:06 2009
@@ -0,0 +1,27 @@
+import re
+from django.contrib.auth.models import User
+from django import forms
+
+class InputForm(forms.Form):
+ inputtext = forms.CharField(label=u'Inputtext', max_length=9000,
widget=forms.Textarea)
+
+ """
+ def clean_password2(self):
+ if 'password1' in self.cleaned_data:
+ password1 = self.cleaned_data['password1']
+ password2 = self.cleaned_data['password2']
+ if password1 == password2:
+ return password2
+ raise forms.ValidationError('Passwords do not match.')
+
+ def clean_username(self):
+ username = self.cleaned_data['username']
+ if not re.search(r'^\w+$', username):
+ raise forms.ValidationError('Username can only contain '
+ 'alphanumeric characters and the underscore.')
+ try:
+ User.objects.get(username=username)
+ except User.DoesNotExist:
+ return username
+ raise forms.ValidationError('Username is already taken.')
+ """

Added: trunk/misc/patrick/django_monty/monty/models.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/django_monty/monty/models.py Sun Jun 28 22:37:06 2009
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.

Added: trunk/misc/patrick/django_monty/monty/monty_process.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/django_monty/monty/monty_process.py Sun Jun 28
22:37:06 2009
@@ -0,0 +1,21 @@
+import montylingua3
+import string
+
+global m #a monty lingua instance.
+m = montylingua3.MontyLingua() #we only have to instantiate it once
(...takes around 5 secs!)
+
+
+def process_text(inputtext):
+ """Given an input text, returns a sentence and tagged sentence tuple
using monty lingua"""
+ global m
+
+ sentences = m.split_sentences(inputtext)
+ tokenized = map(m.tokenize,sentences)
+ tagged = map(m.tag_tokenized,tokenized)
+
+ #print "tagged: " + string.join(tagged,'\n ')
+ #chunked = map(m.chunk_tagged,tagged)
+ #print "CHUNKED: " + string.join(chunked,'\n ')
+ #extracted = map(m.extract_info,chunked)
+
+ return [sentences, tagged]

Added: trunk/misc/patrick/django_monty/monty/views.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/django_monty/monty/views.py Sun Jun 28 22:37:06 2009
@@ -0,0 +1,39 @@
+# Create your views here.
+from monty.forms import *
+
+
+from django.http import HttpResponse
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
+
+
+import monty_process
+import string
+import unicodedata
+
+
+def main_page(request):
+
+
+
+ output_sentences = []
+ output_tags = []
+
+ if request.method == 'POST':
+ form = InputForm(request.POST)
+ if form.is_valid():
+ inputtext=form.cleaned_data['inputtext']
+
+ [output_sentences, output_tags] =
monty_process.process_text(inputtext)
+
+ else:
+ form = InputForm()
+
+ variables = RequestContext(request, {
+ 'form': form,
+ 'output_sentences': output_sentences,
+ 'output_tags': output_tags,
+ })
+ return render_to_response( 'main_page.html', variables)
+

Added: trunk/misc/patrick/django_monty/templates/main_page.html
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/django_monty/templates/main_page.html Sun Jun 28
22:37:06 2009
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>Web interface to MontyLingua</title>
+ </head>
+
+ <body>
+ <form method="post" action=".">
+ {{ form.inputtext }}
+ <input type="submit" value="submit" />
+ </form>
+
+ <h2> List of sentences </h2>
+ {% for sentence in output_sentences %}
+ <li> {{ sentence }} </li>
+ {% endfor %}
+
+
+ <h2> List of words tagged with Penn Treebank Tagset </h2>
+ {% for token in output_tags %}
+ <li> {{ token }} </li>
+ {% endfor %}
+ </body>
+</html>

Reply all
Reply to author
Forward
0 new messages