请在处理文本之前对其进行单词标记。另外,请注意,大多数注释系统都是从句子中训练出来的,所以您可以在单词标记化之前进行句子标记化。
alvas@ubi:~$ export STANFORDTOOLSDIR=$HOME
alvas@ubi:~$ export CLASSPATH=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/stanford-ner.jar
alvas@ubi:~$ export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-ner-2015-12-09/classifiers
alvas@ubi:~$ python
Python 2.7.11 (default, Dec 15 2015, 16:46:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk import word_tokenize
>>> from nltk.tag import StanfordNERTagger
>>> from nltk.internals import find_jars_within_path
>>> st = StanfordNERTagger('english.all.3class.distsim.crf.ser.gz')
>>> stanford_dir = st._stanford_jar.rpartition('/')[0]
>>> stanford_jars = find_jars_within_path(stanford_dir)
>>> st._stanford_jar = ':'.join(stanford_jars)
>>>
>>> text = "In the UK, the class is relatively crowded with Zacc competing with Abc's Popol (market leader) and Xyz's Abcvd."
>>> text = word_tokenize(text)
>>> text
['In', 'the', 'UK', ',', 'the', 'class', 'is', 'relatively', 'crowded', 'with', 'Zacc', 'competing', 'with', 'Abc', "'s", 'Popol', '(', 'market', 'leader', ')', 'and', 'Xyz', "'s", 'Abcvd', '.']
>>> st.tag(text)
[(u'In', u'O'), (u'the', u'O'), (u'UK', u'LOCATION'), (u',', u'O'), (u'the', u'O'), (u'class', u'O'), (u'is', u'O'), (u'relatively', u'O'), (u'crowded', u'O'), (u'with', u'O'), (u'Zacc', u'PERSON'), (u'competing', u'O'), (u'with', u'O'), (u'Abc', u'PERSON'), (u"'s", u'O'), (u'Popol', u'O'), (u'(', u'O'), (u'market', u'O'), (u'leader', u'O'), (u')', u'O'), (u'and', u'O'), (u'Xyz', u'ORGANIZATION'), (u"'s", u'O'), (u'Abcvd', u'O'), (u'.', u'O')]