Is there a way to remove proper nouns from a sentence using python?
<p>Is there any package which i can use to to remove proper nouns from a sentence using Python?</p>

<p>I know of a few packages like NLTK, Stanford and Text Blob which does the job(removes names) but they also remove a lot of words which start with a capital letter but are not proper nouns.</p>

<p>Also, i cannot have a dictionary of names because it'll be huge and will keep extending as the data keeps populating in the DB.</p>

<p>If you want to just remove single words that are proper nouns, you can use <code>nltk</code> and tag your sentence in question, then remove all words with the tags that are proper nouns.</p>

<pre><code>&gt;&gt;&gt; import nltk
&gt;&gt;&gt; nltk.tag.pos_tag("I am named John Doe".split())
[('I', 'PRP'), ('am', 'VBP'), ('named', 'VBN'), ('John', 'NNP'), ('Doe', 'NNP')]
</code></pre>

<p>The default tagger uses the <a href="https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html" rel="nofollow">Penn Treebank POS tagset</a> which has only two proper noun tags: <code>NNP</code> and <code>NNPS</code></p>

<p>So you can just do the following:</p>

<pre><code>&gt;&gt;&gt; sentence = "I am named John Doe"
&gt;&gt;&gt; tagged_sentence = nltk.tag.pos_tag(sentence.split())
&gt;&gt;&gt; edited_sentence = [word for word,tag in tagged_sentence if tag != 'NNP' and tag != 'NNPS']
&gt;&gt;&gt; print(' '.join(edited_sentence))
I am named
</code></pre>

<p>Now, just as a warning, <a href="https://en.wikipedia.org/wiki/Part-of-speech_tagging" rel="nofollow">POS tagging</a> is not 100% accurate and may mistag some ambiguous words. Also, you will not capture <a href="https://en.wikipedia.org/wiki/Named-entity_recognition" rel="nofollow">Named Entities</a> in this way as they are multiword in nature.</p>

python python-2.7