| 1 | | # Create your views here. |
|---|
| | 1 | import os |
|---|
| | 2 | import sys |
|---|
| | 3 | |
|---|
| | 4 | from models import * |
|---|
| | 5 | |
|---|
| | 6 | from django.http import HttpResponse, HttpResponseRedirect |
|---|
| | 7 | from django.shortcuts import render_to_response |
|---|
| | 8 | from django.utils import simplejson |
|---|
| | 9 | |
|---|
| | 10 | def querySubjectIs(request, subject): |
|---|
| | 11 | # get subject object in possessive, singular, and plural form |
|---|
| | 12 | # create regex |
|---|
| | 13 | subject_regex = r"" % (subject.__str__(),) |
|---|
| | 14 | subject_obj = NounPhrase.objects.filter(noun_phrase__regex = subject_regex) |
|---|
| | 15 | # get verbs - is, are, was, were |
|---|
| | 16 | is_obj = Relation.objects.get(relation = 'is') |
|---|
| | 17 | are_obj = Relation.objects.get(relation = 'are') |
|---|
| | 18 | was_obj = Relation.objects.get(relation = 'was') |
|---|
| | 19 | were_obj = Relation.objects.get(relation = 'were') |
|---|
| | 20 | # query for each verb |
|---|
| | 21 | |
|---|
| | 22 | |
|---|
| | 23 | |
|---|
| | 24 | return HttpResponse(simplejson.dumps(results), mimetype='application/json') |
|---|
| | 25 | |
|---|
| | 26 | def queryIsObject(request, object): |
|---|
| | 27 | # create regex for object |
|---|
| | 28 | object_regex = r"" % (object.__str__(),) |
|---|
| | 29 | object_obj = NounPhrase.objects.filter(noun_phrase__regex = object_regex) |
|---|
| | 30 | |
|---|
| | 31 | # get verbs - is, are, was, were |
|---|
| | 32 | is_obj = Relation.objects.get(relation = 'is') |
|---|
| | 33 | are_obj = Relation.objects.get(relation = 'are') |
|---|
| | 34 | was_obj = Relation.objects.get(relation = 'was') |
|---|
| | 35 | were_obj = Relation.objects.get(relation = 'were') |
|---|
| | 36 | # query for each verb |
|---|
| | 37 | |
|---|
| | 38 | return HttpResponse(simplejson.dumps(results), mimetype='application/json') |
|---|