- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Jupyter notebook 上运行代码,我修改了这个 link 中的代码所以它从 Jupyter 笔记本而不是控制台获取它并迭代文件列表。
"""Demonstrates how to make a simple call to the Natural Language API."""
import argparse
import requests
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
def print_result(annotations, movie_review_filename):
score = annotations.document_sentiment.score
magnitude = annotations.document_sentiment.magnitude
file_path_split = movie_review_filename.split("/")
fileName = file_path_split[len(file_path_split) - 1][:-4]
sentencelist = []
statuslist = []
for index, sentence in enumerate(annotations.sentences):
sentence_sentiment = sentence.sentiment.score
singlesentence = [fileName, sentence.text.content, sentence.sentiment.magnitude, sentence_sentiment]
sentencelist.append(singlesentence)
outputdf = pd.DataFrame(sentencelist, columns = ['status_id', 'sentence', 'sentence_magnitude', 'sentence_sentiment'])
outputdf.to_csv("/Users/abhi/Desktop/RetrySentenceCSVs/" + fileName + ".csv", index = False)
return 0
def analyze(movie_review_filename):
"""Run a sentiment analysis request on text within a passed filename."""
client = language.LanguageServiceClient()
with open(movie_review_filename, 'r') as review_file:
# Instantiates a plain text document.
content = review_file.read()
document = types.Document(
content=content,
type=enums.Document.Type.PLAIN_TEXT)
annotations = client.analyze_sentiment(document=document)
# Print the results
print_result(annotations, movie_review_filename)
if __name__ == '__main__':
import glob
csv_file_list = glob.glob("/Users/abhi/Desktop/mytxtfilepath/*.txt")
for file in csv_file_list: #Iterate through a list of file paths
analyze(file)
ERROR:root:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x113b76588>" raised exception!
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 56, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
conn.connect()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
conn = self._new_conn()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/requests.py", line 120, in __call__
**kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 513, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/grpc/_plugin_wrapping.py", line 77, in __call__
callback_state, callback))
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/grpc.py", line 77, in __call__
callback(self._get_authorization_headers(context), None)
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/grpc.py", line 65, in _get_authorization_headers
headers)
File "/anaconda3/lib/python3.6/site-packages/google/auth/credentials.py", line 122, in before_request
self.refresh(request)
File "/anaconda3/lib/python3.6/site-packages/google/oauth2/service_account.py", line 322, in refresh
request, self._token_uri, assertion)
File "/anaconda3/lib/python3.6/site-packages/google/oauth2/_client.py", line 145, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/anaconda3/lib/python3.6/site-packages/google/oauth2/_client.py", line 106, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)
File "/anaconda3/lib/python3.6/site-packages/google/auth/transport/requests.py", line 124, in __call__
six.raise_from(new_exc, caught_exc)
File "<string>", line 3, in raise_from
google.auth.exceptions.TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x113b840b8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
ERROR:root:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x113b76588>" raised exception!
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 56, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 849, in _validate_conn
conn.connect()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 314, in connect
conn = self._new_conn()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x113b84470>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
...
RendezVous
停止。错误(忘记捕获此消息)我想知道的是,代码如何为某些文件集工作一段时间并抛出错误消息,工作多一点,抛出错误消息,然后在一段时间后完全停止工作观点?
.txt
包含文字的文件。
sleep(10)
这似乎可以正常工作一段时间,但再次开始抛出错误..
最佳答案
我想到了。您将不必一次读取所有 600 个文件,而是尝试分批读取 50 个文件。 (创建 12 个文件夹,每个文件夹包含 50 个文件),并在每次扫描完文件夹时手动运行代码。我不确定为什么这似乎可行,但它确实有效。
关于python-3.x - Cloud Natural Language API 返回 socket.gaierror : nodename nor servname provided after performing Sentiment Analysis every now and then,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51775484/
我有一个关于使用的类型的性质的理论问题 很多解释 Coyoneda 引理的例子。它们通常被称为 作为“自然变换”,据我所知,仿函数之间的映射。 令我困惑的是,在这些示例中,它们有时映射自 Set。到某
这是一个小设计,在自然键上具有常见的 NOT NULL UNIQUE 约束: CREATE TABLE 'users' { id int(10) NOT NULL AUTO_INCREMENT
下面是代码 postgres=# SELECT title,name,borrower.address WHERE library_branch NATURAL JOIN book NATURAL J
问题:我想在 javascript 中混合两种颜色,并得到结果颜色。SO 上有很多类似的问题,但是我没有发现任何实际工作正常的问题。我知道混合两种不同颜色的油漆(颜料)和灯光会产生非常不同的结果(ht
在我的应用程序中,我有一个用于输入 url 的编辑文本,然后编辑文本具有: android:imeOptions="actionDone" 因此,当有人按下键盘的回车键时,应用程序会连接并且键盘会消失
问题:我想在 javascript 中混合两种颜色,并得到结果颜色。SO 上有很多类似的问题,但是我没有发现任何实际工作正常的问题。我知道混合两种不同颜色的油漆(颜料)和灯光会产生非常不同的结果(ht
C-x C-b 显示缓冲区列表。首先是自然顺序,最近使用的缓冲区在顶部,隐藏的缓冲区在底部。 在那里,我现在可以按名称、大小、模式和文件对缓冲区进行排序。但是一旦我点击了这样的选项,我就无法回到原来的
我最近看到了一种叫做 supernova 的编程语言他们在网页上说: The Supernova Programming language is a modern scripting language
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我一直在使用带有附加类型级奇偶校验信息的自然数。 succ 已以最直接的方式成功实现: succ :: Natural p -> Natural (Opp p) succ = Succ 但是,我仍然在
我正在阅读有关 SQL 连接的 NATURAL 速记形式的内容,我发现了一些陷阱: 它只是自动获取所有相同命名的列对(使用 USING 指定显式列列表) 如果添加了一些新列,那么连接输出也可能会“意外
我对 lambda 演算中的自然数有如下定义,这是我的主要目标。 -- Apply a function n times on x apply = \f -> \n -> \x -> foldr ($
我正在尝试按标题对数据库中的项目进行排序。商品有 iphone 5、iphone 6/6S、iphone 11、.. 当我用代码对项目进行排序时 SELECT * FROM ".FPD_PRODUCT
我需要为我的 Web 应用程序对较大的数组(1000-2000 个键)进行复杂的排序。我在 Safari 12.0/FF 66.0 中可以正常使用它,但 chrome 74.0 似乎完全可以做其他事情
我有三个这样描述的表: +----------+ +-----------------+ +----------+ | products | | products_stores |
我创建了一个函数“ADD”来修改变量的值: function ADD(xs, n) { var nom_variable = xs; var XS = eval(xs); no
The Third Commandment的 The Little Schemer状态: When building a list, describe the first typical elemen
我刚看到this我想知道实现这样的自然排序的最佳方法是什么? 通常在 1,4,11,12 列表中,字符串排序(用于列表项)返回 1,11,12,4。如何实现自然排序? 最佳答案 元素也可以是 [ 's
我编写了一些采用异构列表并为其编制索引的代码。 {-# Language GADTs, FunctionalDependencies, MultiParamTypeClasses, KindSigna
所以这个想法是计算机代理将被编程为两层,有意识的和无意识的。 无意识部分本质上是一组输入和输出设备,我通常认为它们是传感器(键盘、温度等,你的想象力的极限)和输出方法(屏幕和扬声器,特别是在家用 PC
我是一名优秀的程序员,十分优秀!