from pattern.web import Google, plaintext
from pattern.search import search
def learn(concept):
q = 'I think %s is *' % concept
p = []
g = Google(language='en')
for i in range(10):
for result in g.search(q, start=i, cached=True):
m = plaintext(result.description)
m = search(q, m) # use * as wildcard
if m:
p.append(m[0][-1].string)
return [w for w in p if w in PROPERTIES]
for p in learn('Brussels'):
g.add_edge(p, 'Brussels', type='is-property-of')
throws the error
Traceback (most recent call last):
File "E:\WPy-3710\python-3.7.1.amd64\lib\site-packages\pattern3\web\__init__.py", line 571, in open
return urllib.request.urlopen(request)
File "E:\WPy-3710\python-3.7.1.amd64\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "E:\WPy-3710\python-3.7.1.amd64\lib\urllib\request.py", line 531, in open
response = meth(req, response)
File "E:\WPy-3710\python-3.7.1.amd64\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "E:\WPy-3710\python-3.7.1.amd64\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "E:\WPy-3710\python-3.7.1.amd64\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "E:\WPy-3710\python-3.7.1.amd64\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in learn
File "E:\WPy-3710\python-3.7.1.amd64\lib\site-packages\pattern3\web\__init__.py", line 1400, in search
data = url.download(cached=cached, **kwargs)
File "E:\WPy-3710\python-3.7.1.amd64\lib\site-packages\pattern3\web\__init__.py", line 638, in download
timeout, proxy, user_agent, referrer, authentication).read()
File "E:\WPy-3710\python-3.7.1.amd64\lib\site-packages\pattern3\web\__init__.py", line 576, in open
raise HTTP400BadRequest(src=e, url=url)
pattern3.web.HTTP400BadRequest
on
`WinPython 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32`
The "Modeling creativity with a semantic network of common sense" (https://www.clips.uantwerpen.be/pages/modeling-creativity-with-a-semantic-network-of-common-sense) example throws an error with pattern3.
throws the error