Empty output for NLTK function

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Empty output for NLTK function

Postby stanislav » 25. April 2022 10:34

Hi! I use python NLTK library in CGI script to tokenize some text in XAMPP web server. 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:
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)

It does not print anything on screen. No erros, just white browser screen.
I know it's not releted directly to apache, but maybe anyone encountered such problems before? Or I simply made some shamefully silly mistake......

I use: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.28
python 3.10.4
stanislav
 
Posts: 4
Joined: 19. April 2022 12:35
XAMPP version: 7.4.28
Operating System: Windows

Re: Empty output for NLTK function

Postby stanislav » 29. April 2022 11:05

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

morgot.py - name of CGI file.

'?someamountoftext=' This is how you enter data into variable

%20 - spacebar in browser line.
stanislav
 
Posts: 4
Joined: 19. April 2022 12:35
XAMPP version: 7.4.28
Operating System: Windows


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 96 guests