Я делаю API, в котором мне нужна помощь, как сделать запрос?.
Я могу отобразить результат, используя 127.0.0.1:8000/Naturallanguageprocessing/
Он получает все атрибуты, в которые я включил частиречь, лемматизация и т. д., но я должен отображать таким образом 127.0.0.1:8000/?q = "querytext"&all = 1
Он должен отображать все части речи, лемматизации и т. д., и если я звоню 127.0.0.1:8000/?q = "querytext" & partsofspeech = 1 & lemmatization = 1
.
Он должен отображатьчасти речи и лемматизация.
Ниже приведены мои views.py.
from django.shortcuts import render,redirect,HttpResponse
from django.views.generic.edit import FormView
from rest_framework.decorators import api_view
from django.http import JsonResponse
from django.conf import settings
from rest_framework.response import Response
from django.views import View
import json
import spacy
import pdb
nlp = spacy.load('en_core_web_sm')
@api_view(["POST"])
def Naturallanguageprocessing(requestdata):
try:
text = str(requestdata.body)
stopwordsremoval = []
partsofspeech= []
nounphrases = []
word_lemma = []
tokenization = []
nameentityrecognization = []
for word in (nlp(text)):
a = (word.is_stop, word.text)
b = (word.text, word.pos_, word.tag_)
d = (word.lemma_)
e = (word.text)
tokenization.append(e)
word_lemma.append(d)
stopwordsremoval.append(a)
partsofspeech.append(b)
for word in (nlp(text).noun_chunks):
c = (word.text)
nounphrases.append(c)
for word in (nlp(text).ents):
f = (word.text,word.label_)
nameentityrecognization.append(f)
output = {"stopwordremoval": stopwordsremoval,
"partsofspeech": partsofspeech,
"nounphrases" : nounphrases,
"word_lemma":word_lemma,
"tokenization":tokenization,
"nameentityrecognization":nameentityrecognization
}
return JsonResponse(output,safe = False)
except ValueError as e:
return Response(e.args[0],status.HTTP_400_BAD_REQUEST)