Changeset 210

Show
Ignore:
Timestamp:
11/09/09 15:25:51 (2 years ago)
Author:
sjohns67
Message:

beginning work on an API.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • knowledge/website/kb/views.py

    r197 r210  
    1 # Create your views here. 
     1import os 
     2import sys 
     3 
     4from models import * 
     5 
     6from django.http import HttpResponse, HttpResponseRedirect 
     7from django.shortcuts import render_to_response 
     8from django.utils import simplejson 
     9 
     10def 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 
     26def 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')