replacing pronoun with its antecedent using python2.7 and nltk

As the title shows I am trying to look for pronouns in a string and replace it with it's antecedent like: [in]: "the princess looked from the palace, she was happy". [out]: "the princess looked from the palace, the princess was happy". I use pos tag to return pronouns and nouns. I need to know how to replace without knowing the sentence, meaning how to specify the subject in the sentence

用python2.7和nltk替代代词

正如标题所示,我正在尝试在字符串中查找代词,并将其替换为前面的代词: [in]: "the princess looked from the palace, she was happy". [out]: "the princess looked from the palace, the princess was happy". 我使用pos标签来返回代词和名词。 我需要知道如何在不知道句子的情况下进行替换,这意味着如何在句子中指定主题来替代代词。 有什么建议么? 我不知道nltk软件包(从来没有用过),但它似乎马上给你答案。

Python 3 regex with diacritics and ligatures,

Names in the form: Ceasar, Julius are to be split into First_name Julius Surname Ceasar. Names may contain diacritics (á à é ..), and ligatures (æ, ø) This code seems to work OK in Python 3.3 import re def doesmatch(pat, str): try: yup = re.search(pat, str) print('Firstname {0} lastname {1}'.format(yup.group(2), yup.group(1))) except AttributeError: print(

Python 3正则表达式与变音符和连字,

形式上的名字:塞萨尔,朱利叶斯将被分成名字朱利叶斯姓氏塞萨尔。 名称可能包含变音符号(áàé..)和连字(æ,ø) 这段代码似乎在Python 3.3中工作正常 import re def doesmatch(pat, str): try: yup = re.search(pat, str) print('Firstname {0} lastname {1}'.format(yup.group(2), yup.group(1))) except AttributeError: print('no match for {0}'.format(str)) s = 'Révèrberë, H

Using google's protobuf in python without installing it

It seems to me that when I'm using protobuf in python I need to install it first so that I also have setuptools installed. To me it seems like this is severly limiting portability as I would have to install protobuf on every machine on which I want to use any kind of python code using protobuf. So my question is: Is there a way to package protobuf for python in such a way, that it can be d

在python中使用谷歌的protobuf而不安装它

在我看来,当我在python中使用protobuf时,我需要先安装它,以便我还安装了setuptools。 对我来说,这似乎是严格限制可移植性,因为我将不得不在每台机器上安装protobuf,我希望使用protobuf来使用任何类型的python代码。 所以我的问题是:有没有办法以这种方式打包protobuf for python,以便可以使用Python代码进行分发? 任何有关这方面的信息将不胜感激。 该软件包包含一个实验性的C ++扩展,安装文件生成Python文件,

write multiple stdin

I need to open an R script and supply it with input formulated by a separate python script. The subprocess module seems to be a good way to do this. I have encountered some puzzling results though, namely that I can apparently write once and only once via p.stdin . Here is what I have so far: from subprocess import Popen, PIPE, STDOUT p = Popen(['r --no-save'],stdin=PIPE,stdout=PIPE,stderr=

写多个stdin

我需要打开一个R脚本并为其提供由单独的python脚本制定的输入。 subprocess模块似乎是一个很好的方法来做到这一点。 虽然我遇到了一些令人费解的结果,也就是说我可以通过p.stdin显然只写一次。 这是我到目前为止: from subprocess import Popen, PIPE, STDOUT p = Popen(['r --no-save'],stdin=PIPE,stdout=PIPE,stderr=PIPE,shell=True) p.stdin.write("source('myrscript.R')n") p.stdin.write('myfirstinput') 当我

Why is 3<<1 == 6 in python?

Possible Duplicate: Absolute Beginner's Guide to Bit Shifting? anyone can explain me that operator << or >> The << and >> operators are bitshift operators. x << 1 shifts all the bits in x up to the next most significant bit, effectively multiplying by 2. More generally, x << n shifts the bits up n positions. To understand how this operation works it

为什么在Python中3 << 1 == 6?

可能重复: 绝对新手指南移位? 任何人都可以解释我那个operator <<或>> <<和>>运算符是位移运算符。 x << 1移中的所有比特x到下一个最显著位,由2乘以有效更一般地, x << n移位的位n个位置。 要理解这个操作是如何工作的,最简单的方法就是查看二进制表示: 3 0000011 = 3 3 << 1 0000110 = 6 3 << 2 0001100 = 12 3 << 3 0011000 = 24

webapp2 with python3

I use webapp2 with python 2.7 with or without googleAppEngine. I'm now trying to use it with Python 3.3 I've used PIP to install webapp2 Install run with success but when I try to import webapp2 from IDLE gaves me the folowing error: File "<pyshell#0>", line 1, in <module> import webapp2 File "C:Python3libwebapp2.py", line 571 except Exception, e:

webapp2与python3

我使用带有或没有googleAppEngine的python 2.7的webapp2。 我现在试图在Python 3.3中使用它 我使用PIP来安装webapp2安装运行成功,但是当我尝试从IDLE导入webapp2给了我下面的错误: File "<pyshell#0>", line 1, in <module> import webapp2 File "C:Python3libwebapp2.py", line 571 except Exception, e: ^ 我怀疑这是一个必须更新才能使用Python3的东西......任何人已经完

Is there a plan for Django to handle NoSQL databases natively?

I really like Django. I've fiddled around a bit with Rails, but I personally prefer Django's logic. I also prefer Python over Ruby. Again, personal preferences. Despite all that, I am now switching back to Rails because of Django's lack of native support for databases like mongodb. I saw there was no plan for Django 1.5 to support NoSQL databases. I've tried to install djan

Django是否有计划在本地处理NoSQL数据库?

我真的很喜欢Django。 我用Rails弄了一下,但我个人更喜欢Django的逻辑。 我也比Python更喜欢Python。 再次,个人喜好。 尽管如此,由于Django缺乏对mongodb等数据库的本地支持,现在我正在切换回Rails。 我看到Django 1.5没有计划支持NoSQL数据库。 我试图安装django-nonrel,因为它看起来很有前途,但没有成功。 即使我成功了,考虑到缺乏积极的发展,我也不能相信django的这个分支。 甚至没有一篇文章告诉你要安装什

Pyramid: sessions and static assets

Let me explain the problem: I am serving my static assets via Pyramid: config.add_static_view(name='static', path='/var/www/static') And it works fine. Now, I have a custom session factory that creates sessions in database. It checks if the browser presents a session cookie. If it does, it finds a session from the DB. If it does not, then a new session is created in DB and a cookie is re

金字塔:会话和静态资产

让我解释一下这个问题: 我通过金字塔服务我的静态资产: config.add_static_view(name='static', path='/var/www/static') 它工作正常。 现在,我有一个自定义会话工厂,可以在数据库中创建会话。 它检查浏览器是否显示会话cookie。 如果有,它会从数据库中找到一个会话。 如果没有,则在数据库中创建一个新的会话,并将cookie返回给浏览器。 到现在为止还挺好。 现在,在我的home_view (生成我的主页)内部,我

Flask, one flash message not getting displayed

This question already has an answer here: Flask flash message no longer works when using ajax 2 answers How to manage a redirect request after a jQuery Ajax call 30 answers I think (but I'm not sure, because you didn't include the code of index ), that the template in index doesn't include the flash. You need to format the index page (or the base template) to display the flash.

烧瓶,一个闪光消息没有得到显示

这个问题在这里已经有了答案: 使用ajax 2答案时,Flask flash消息不再有效 如何在jQuery Ajax调用30个答案后管理重定向请求 我认为(但我不确定,因为您没有包含index代码), index中的模板不包含闪光灯。 您需要格式化索引页(或基本模板)以显示闪光灯。 查看http://flask.pocoo.org/docs/0.12/patterns/flashing/中的例子,实际上: {% with messages = get_flashed_messages() %} {% if messages %} <ul

Understanding Python fork and memory allocation errors

I have a memory intensive Python application (between hundreds of MB to several GB). I have a couple of VERY SMALL Linux executables the main application needs to run, eg child = Popen("make html", cwd = r'../../docs', stdout = PIPE, shell = True) child.wait() When I run these external utilities (once, at the end of the long main process run) using subprocess.Popen I sometimes get OSError: [E

了解Python分叉和内存分配错误

我有一个内存密集型Python应用程序(数百MB到几GB)。 我有几个主要应用程序需要运行的非常小的Linux可执行文件,例如 child = Popen("make html", cwd = r'../../docs', stdout = PIPE, shell = True) child.wait() 当我使用subprocess.Popen运行这些外部实用程序(一次,在长主进程运行结束时),我有时会得到OSError: [Errno 12] Cannot allocate memory 。 我不明白为什么......请求的过程很小! 该系统有足够的内存