我是学习NLP的初学者。我读到过CFG,我想把它应用于自上而下的解析和自下而上的解析。我从自上而下的解析开始。我想用nltk和python36绘制自上而下的解析树。我写了下面的代码,但是它不能工作。出了什么问题?有没有人可以帮我增强代码?
import nltk
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
from nltk.tree import *
from nltk.draw import tree
from nltk import Nonterminal, nonterminals, Prod
我有一个上下文无关的语法,并使用它来创建句子(使用python中的NLTK )。 # Create a CFG
from nltk import CFG
from nltk.parse.generate import generate
grammar = CFG.fromstring("""
Story -> Introduction MainQuest End
LocationInfo -> 'He found himself in a small village where he grew up.'
Introduction ->
试图用NLTK CFG生成句子。想知道是否可以在下面的程序中连接sql数据库来输入名词和动词。在下面的例子中,门、窗、开、关都是硬编码的。在这个特定的上下文中,如何动态地要求nltk从excel或数据库列来输入名词和动词?
import nltk
from nltk.parse.generate import generate,demo_grammar
from nltk import CFG
grammar = CFG.fromstring("""
S -> VP NP
NP -> Det N
VP -> V
NLTK3.0:
使用如下的CFG配置(非终端团队有4个值,1个值,有2个单词(斯里兰卡)。
当我生成可能的世代列表时,我可以看到结果中出现了这两个字。但是,当我试图用这两个字的语法来解析一个输入句子时,它不会解析。
import nltk
from nltk.parse import generate
from nltk.grammar import Nonterminal
cfg = nltk.CFG.fromstring("""
root -> who_player has the most runs
who_player -> who
who_p
我必须在python中为list创建一个语法nltk。我有一个文本的语法:
grammar1 = nltk.CFG.fromstring("""
S -> NP VP
VP -> V NP | V NP PP
PP -> P NP
V -> "saw" | "ate" | "walked"
NP -> "John" | "Mary" | "Bob" | Det N | Det N PP
Det -&
我正在尝试使用android上的chaquopy工具实时下载nltk所需的软件包。
我试图将模型下载到一个特定的数据目录中,如下所示:
from android.os import Bundle
from android.support.v7.app import AppCompatActivity
from activity import R
from com.chaquo.python import Python
from java import jvoid, Override, static_proxy
import nltk
import os
class MainActivity(
我在openshift中托管了一个Python webservice应用程序,它使用了nltk的RSLP Stemmer模块,但是服务日志报告说:
[...] Resource 'stemmers/rslp/step0.pt' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download()
Searched in:
- '/var/lib/openshift/539a61ab5973caa2410000bf/nltk_data'
-
关于递归定义的给出问题的非终端,我一定缺少了一些基本的东西,但我想做的就是识别一个类似正则表达式的东西,在这个表达式中,一系列数字后面跟着一系列的字母。
from nltk import CFG
import nltk
grammar = CFG.fromstring("""
S -> N L
N -> N | '1' | '2' | '3'
L -> L | 'A' | 'B' | 'C'
""")
from nltk.pars
我正在使用nltk.download()来下载我需要的包。但是我得到了下面的错误。
root@nishant-Inspiron-1545:/home/nishant/Dropbox/DDP/data# python
Python 2.7.3 (default, Apr 10 2013, 05:09:49) [GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import
我是在corportate代理后面运行这个
使用以下命令:RUN python -m nltk.downloader punkt
/usr/local/lib/python3.8/runpy.py:127: RuntimeWarning: 'nltk.downloader' found in sys.modules after import of package 'nltk', but prior to execution of 'nltk.downloader'; this may result in unpredictable behavio
我希望能够在NLTK中使用Boxer作为语义提取器。
我正在使用以下代码进行测试:
#!/bin/env python
import nltk
x = nltk.sem.boxer.Boxer()
x.interpret("The capital of Spain is Madrid .")
失败的原因如下:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packa
我想在我的项目中使用stanford,但是下面会出现错误。
File "C:\Python34\lib\site-packages\nltk\tag\stanford.py", line 59, in tag
return self.tag_sents([tokens])[0]
File "C:\Python34\lib\site-packages\hazm\POSTagger.py", line 25, in tag_sents
return super(stanford.POSTagger, self).tag_sents(refin
编辑的我需要解析以下句子:“给我列出去丹佛的航班的座位”。下面的代码应该可以工作,但不能工作。问题在nltk.CFG.fromstring命令中,我确信其他函数可以工作。有什么办法在这里正确地定义语法规则吗?
import nltk
from nltk.corpus import treebank
# here we define a grammar
import nltk
from nltk.corpus import treebank
grammar = nltk.CFG.fromstring("""
S -> NP VP | VP |IVP
我的问题是:
我有很多句子的文件。对于每个句子,我必须使用nltk编写一个CFG。
grammar1 = nltk.CFG.fromstring("""
S -> NP VP
VP -> V NP | V NP PP
PP -> P NP
V -> "saw" | "ate" | "walked"
NP -> "John" | "Mary" | "Bob" | Det N | Det N PP
Det -> "
我正在使用Python中的nltk库;我的背景是Java。我不理解我编写的代码的控制台输出。为什么Python会返回一个奇怪的表单,尽管我将变量tokens初始化为list。
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
import nltk
def tokenize_sentence(sentence):
tokens=[]
tokens = word_tokenize(sentence)
tokens = (word for word in tokens if
我是python和nltk的新手。我被要求为以下句子创建两种不同的解析树:
Adam slept while Josh ate and the dog barked.
基于这两种结构:
S-> S while S
S-> S and S
以下是我到目前为止所写的,我使用作为指导方针。
import nltk
grammar_string = '''
S -> S 'and' S
S -> S 'or' S
S -> S 'but' S
S -> S 'while' S
任务是定义语法,并使用ChartParser来使用nltk中的ChartParser包解析任何给定的句子。我的代码如下:
import nltk
your_grammar = nltk.CFG.fromstring("""
S -> NP VP
NP -> NP PP
Nom -> N
VP -> V NP | V S | VP PP
PP -> P NP
Det -> 'the'
N -> 'block' | 'table'
V -> 'Put'
P
我试图让TextBlob在Unix服务器上为一些队友启动并运行,当我以root用户的身份运行使用TextBlob的脚本时,它似乎工作得很好,但是当我尝试创建新帐户时,会出现以下错误:
**********************************************************************
Resource u'tokenizers/punkt/english.pickle' not found. Please
use the NLTK Downloader to obtain the resource: >>>