Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting two names from same sentence in nltk python
    primarykey
    data
    text
    <p>Hi I started playing around with Python these days and it seems easy so I found the corpus in nltk in Python. When I tried out </p> <pre><code>text1.concordance("Moby") </code></pre> <p>it gave me the number of sentences and a display of the sentences containing the word Moby, cool.</p> <p>So I tried to test out if I could find all the sentences with the names Moby and Ahab but sadly I get errors out of that. </p> <p>Am I doing something wrong or should I be able to get all the sentences containing those both names? Is there another function from nltk I should use? O.o</p> <p>It's probably easy but not so much for me to see it atm...hope someone could help, thanks.</p> <p>PS: If I need to write some code, an example would be great.^^</p> <p>Edit: Since someone asked for the error I will write the code I wrote too.</p> <pre><code>import nltk from nltk.book import * text1.concordance("Moby","Ahab") </code></pre> <p>gives me the error:</p> <pre><code>Traceback (most recent call last): File "&lt;pyshell#2&gt;", line 1, in &lt;module&gt; text1.concordance('Moby','Ahab') File "C:\Programmering\Python27\lib\site-packages\nltk\text.py", line 314, in concordance self._concordance_index.print_concordance(word, width, lines) File "C:\Programmering\Python27\lib\site-packages\nltk\text.py", line 174, in print_concordance half_width = (width - len(word) - 2) / 2 TypeError: unsupported operand type(s) for -: 'str' and 'int' </code></pre> <p>I had guessed that I would get some matches like with just running:</p> <pre><code>text1.concordance("Moby") </code></pre> <p>where I got 84 matches.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload