python - 如何在 NLP Api 中进行查询?
问题描述
我正在制作一个我想要帮助的 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)
解决方案
推荐阅读
- javascript - JavaScript Ajax 和邮件/票证
- php - 如何使用if语句在php中按升序排列数字?
- matplotlib - 如何在朱莉娅冲浪情节中查看?
- java - Spring Boot 和 Swagger 文本/html 响应映射
- c# - 通用列表中的 C# Cast 对象
- c# - ModifierKeys 不存在,尽管使用了 System.Windows.Input
- jenkins - Jenkins 中的大型 terraform 管道
- active-directory - 尝试使用 AD 加入 Linux 服务器时出错
- css - 砌体式放置
- azure - Azure Log Analytics 使用 Azure 函数设置数据