clips / pattern

Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.
https://github.com/clips/pattern/wiki
BSD 3-Clause "New" or "Revised" License
8.76k stars 1.58k forks source link

minor fixes in pattern.html #215

Closed Ankit-Dhankhar closed 1 year ago

Ankit-Dhankhar commented 6 years ago

This pull request corresponding the issue #108. It solves the issue but while solving this , when I tried to run the program

from pattern.web    import Bing, plaintext
from pattern.en     import parsetree
from pattern.search import search
from pattern.graph  import Graph

g = Graph()
for i in range(10):
    for result in Bing().search('"more important than"', start=i+1, count=50):
        s = r.text.lower() 
        s = plaintext(s)
        s = parsetree(s)
        p = '{NP} (VP) more important than {NP}'
        for m in search(p, s):
            x = m.group(1).string # NP left
            y = m.group(2).string # NP right
            if x not in g:
                g.add_node(x)
            if y not in g:
                g.add_node(y)
            g.add_edge(g[x], g[y], stroke=(0,0,0,0.75)) # R,G,B,A

g = g.split()[0] # Largest subgraph.

for n in g.sorted()[:40]: # Sort by Node.weight.
    n.fill = (0, 0.5, 1, 0.75 * n.weight)

g.export('test', directed=True, weighted=0.6)

But gives the following error:

Traceback (most recent call last):
  File "demo.py", line 8, in <module>
    for result in Bing().search('"more important than"', start=i+1, count=50):
  File "/usr/local/lib/python2.7/dist-packages/pattern/web/__init__.py", line 1281, in search
    data = url.download(cached=cached, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pattern/web/__init__.py", line 437, in download
    data = self.open(timeout, proxy, user_agent, referrer, authentication).read()
  File "/usr/local/lib/python2.7/dist-packages/pattern/web/__init__.py", line 412, in open
    raise URLError(str(e), src=e, url=url)
pattern.web.URLError: Invalid header value 'Basic OlZuSkVLNEhUbG50RTNTeUY1OFFMa1VDTHAvNzh0a1lqVjFGbDNKN2xIYTA9\n'

Is this a specific issue to my installation or a general. If it is a general issue I would like to work on it. For that can someone please guide me, where to start.

Thanks, Ankit