Stanford parser with NLTK produces empty output

2024/11/17 18:45:29

I am trying to use the Stanford parser in a small application written in Python with the NLTK interface. I tried the code given below.

Everything seems to work right, no errors, Java is launched but I systematically get an empty iterator () and the program does not display the parsing tree.

I use Windows 7, Python 3.4.3, JRE jre1.8.0_51. I did the same with the POS tagger but got the same empty result.


import os
from nltk.parse import stanford
os.environ['STANFORD_PARSER'] = 'path\\jars'
os.environ['STANFORD_MODELS'] = 'path\\jars'
os.environ['JAVAHOME']= "path\\Java\jre1.8.0_51\\bin"parser = stanford.StanfordParser(model_path="path\\englishPCFG.ser.gz")
sentences = parser.raw_parse_sents(("Hello the world.", "Thank you for helping me with this problem."))
print(sentences)for line in sentences:for sentence in line:sentence.draw() 
Answer

Try:

sentences = list(parser.raw_parse_sents(("Hello the world.", "Thank you for helping me with this problem.")))for line in sentences:for sentence in line:sentence.draw() 
https://en.xdnf.cn/q/120172.html

Related Q&A

How do you return a list of the matched item in string with regex? [duplicate]

This question already has answers here:Regular expression to match a dot [duplicate](8 answers)Closed 3 years ago.I made this simple functions that searches for emails in the source code of a page , th…

Indentation Error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

open csv file in python to customize dictionary [duplicate]

This question already has answers here:Creating a dictionary from a CSV file(4 answers)Closed 9 years ago.I would like to know to load this csv file:Epitope,ID,Frequency,AssayAVNIVGYSNAQGVDY,123431,27.…

How does UserPassesTestMixin in django work?

views.pyclass ProfileEdit(UserPassesTestMixin, UpdateView):model = Userform_class = ProfileFormtemplate_name="profile/profile_new.html"def test_func(self):x = self.request.user.idprint (x)y =…

How to extract URL from HTML anchor element using Python3? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…

Why does using open(filename) fail with filename is not defined?

I want to open a text file containing a column of words and create a list or, alternatively, a string containing these words. Why do I get this error: >>> with open(some_file.txt, r) as some_f…

Read Excel file which has one of the column as Hyperlink through python

I have to read an Excel file Using python. By the time I use xl = pd.ExcelFile("abc.xlsx")The column values which had hyperlink assigned to it becomes a simple number without any hyperlink.Is…

How can I create n number of files in python?

say user gives a number n=3 then I have to create 3 files dynamically. How will I do that? What can be the names of those files. Specifically I want n number of .jpg file created.

For loop doesnt append info correctly into 2D array

I have created an empty 2D array. When I try to add stuff inside of it, it doesnt do so properly. Each index contains the appropriate info, but for some reason, carries the info from the previous into …

How to merge two strings in python?

I need to merge strings together to create one string. For example the strings for "hello" that need to be combined are: [H----], [-E---], [--LL-], and [----O]This is the current code I have …