Extracting quotations/citations with nltk (not regex)
<p>The input list of sentences:</p>

<pre><code>sentences = [
    """Well, I've tried to say "How Doth the Little Busy Bee," but it all came different!""",
    """Alice replied in a very melancholy voice. She continued, 'I'll try again.'"""
]
</code></pre>

<p>The desired output:</p>

<pre><code>How Doth the Little Busy Bee,
I'll try again.
</code></pre>

<p>Is there a way to extract the citations (can appear in both single and double quotes) with <code>nltk</code> with built-in or third-party tokenizers?</p>

<hr>

<p>I've tried using the <a href="http://www.nltk.org/_modules/nltk/tokenize/sexpr.html" rel="nofollow"><code>SExprTokenizer</code> tokenizer</a> providing the single and double quotes as <code>parens</code> values but the result was far from the desired, e.g.:</p>

<pre><code>In [1]: from nltk import SExprTokenizer
    ...: 
    ...: 
    ...: sentences = [
    ...:     """Well, I've tried to say "How Doth the Little Busy Bee," but it all came different!""",
    ...:     """Alice replied in a very melancholy voice. She continued, 'I'll try again.'"""
    ...: ]
    ...: 
    ...: tokenizer = SExprTokenizer(parens='""', strict=False)
    ...: for sentence in sentences:
    ...:     for item in tokenizer.tokenize(sentence):
    ...:         print(item)
    ...:     print("----")
    ...:     
Well,
I've
tried
to
say
"
How
Doth
the
Little
Busy
Bee,
"
 but it all came different!
----
Alice replied in a very melancholy voice. She continued, 'I'll try again.'
</code></pre>

<hr>

<p>There were similar threads like <a href="http://stackoverflow.com/questions/37936461/how-to-extract-quotations-from-text-using-nltk">this</a> and <a href="http://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks">this</a>, but all of them suggest a regex-based approach, but, I'm curious if this can be solved with <code>nltk</code> only - sounds like a common task in Natural Language Processing.</p>

<p>Well, under the hood, <code>SExprTokenizer</code> is a regex-based approach as well, as can be seen from the source code you linked to.<br>
What also can be seen from the source is that the authors apparently didn't consider that the opening and closing "paren" are represented with the same character.
The depth of the nesting is increased and decreased in the same iteration, so the quote seen by the tokenizer is the empty string.</p>

<p>Identifying quotes is not that common in NLP, I think.
People use quotes in many different ways (especially if you deal with different languages...), so it's quite hard to get it right in a robust approach.
For many NLP applications quoting is just ignored, I'd say...</p>

python nltk tokenize