[英]Empty output for NLTK function in CGI script
I want to use python NLTK library's function in CGI script to tokenize some text, recieved via WEB.我想在 CGI 脚本中使用 python NLTK 库的 function 来标记一些文本,通过 WEB 收到。
If i simply use:如果我只是使用:
someamountoftext = "someamountoftext someamountoftext someamountoftext"
and then然后
nltk.word_tokenize(someamountoftext)
or或者
nltk.sent_tokenize(someamountoftext)
It will work.它会起作用。
BUT: If I use this:但是:如果我使用这个:
#!C:\Users\HP\AppData\Local\Programs\Python\Python310-32\python.exe
import os
import urllib.parse
import nltk
query_dict = urllib.parse.parse_qs(os.environ['QUERY_STRING'])
def tknz_wrd(someamountoftext):
return(nltk.word_tokenize(someamountoftext))
print("Content-Type: text/html\n")
print (tknz_wrd(someamountoftext))
(Above is all my code of sigle file, no frameworks or something). (以上是我所有的单文件代码,没有框架之类的)。
It does not print anything on screen.它不会在屏幕上打印任何内容。 No erros, just white browser screen.
没有错误,只是白色的浏览器屏幕。 Ofcourse, I tried manual input like:
当然,我尝试过手动输入,例如:
http://localhost/speciallocationforproject/local/tokenize/morgot.py?someamountoftext=somekindoftext http://localhost/speciallocationforproject/local/tokenize/morgot.py?someamountoftext=somekindoftext
It did not change anything.它没有改变任何东西。
morgot.py - name of my CGI file. morgot.py - 我的 CGI 文件的名称。
Where is my mistake?我的错误在哪里? And\or how to make tokenization via WEB?
和/或如何通过 WEB 进行标记化?
I use: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.28我使用:Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.28
python 3.10.4 python 3.10.4
Problem solved.问题解决了。 So i made few mistakes, and the correct code is:
所以我犯了一些错误,正确的代码是:
#!C:\Users\HP\AppData\Local\Programs\Python\Python310-32\python.exe
import os
import urllib.parse
import nltk
query_dict = urllib.parse.parse_qs(os.environ[‘QUERY_STRING’])
input_something = str(query_dict[‘someamountoftext’])[2: -2]
def tknz_wrd(someamountoftext):
return(nltk.word_tokenize(someamountoftext))
print(“Content-Type: text/html\n”)
print (tknz_wrd(input_something))
It processes data, recieved from browser line, like: http://localhost/speciallocation/local/tokenize/morgot.py?someamountoftext=Enter%20your%20text%20here它处理从浏览器行收到的数据,例如:http://localhost/speciallocation/local/tokenize/morgot.py?someamountoftext=Enter%20your%20text%20here
morgot.py - name of CGI file. morgot.py - CGI 文件的名称。
'?someamountoftext=' This is how you enter data into variable '?someamountoftext=' 这是将数据输入变量的方式
%20 - spacebar in browser line. %20 - 浏览器行中的空格键。
Output: ['Enter', 'your', 'text', 'here'] Output:['输入','你的','文本','这里']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.