Java Stanford NLP:语音标签的一部分?


172

此处演示的Stanford NLP 给出如下输出:

Colorless/JJ green/JJ ideas/NNS sleep/VBP furiously/RB ./.

词性标签是什么意思?我找不到正式名单。是斯坦福大学自己的系统,还是使用通用标签?(JJ例如,什么是?)

同样,当我遍历句子时,例如寻找名词时,我最终会做类似检查标签是否的事情.contains('N')。这感觉很虚弱。是否有更好的方法以编程方式搜索语音的某个部分?


这可能是一个小问题,但是您应该使用.starts_with('N')而不是contains,因为'IN'和'VBN'也包含'N'。这可能是找到标记者认为哪些单词是名词的最佳方法。
2012年

Answers:


276

宾夕法尼亚树木树项目。查看词性标记 ps。

JJ是形容词。NNS是名词,复数。VBP是动词现在时。RB是副词。

那是英语。对于中国人来说,这是宾州中国树库。对于德语,这是NEGRA语料库。

  1. CC协调连词
  2. CD基数
  3. DT确定器
  4. EX存在
  5. FW外来词
  6. IN介词或从属连词
  7. JJ形容词
  8. JJR形容词,比较
  9. JJS形容词,最高级
  10. LS清单项目标记
  11. MD模态
  12. NN名词,奇数或质量
  13. NNS名词,复数
  14. NNP专有名词,单数
  15. NNPS专有名词,复数
  16. PDT预定器
  17. POS所有权结局
  18. PRP人称代词
  19. PRP $所有代词
  20. RB副词
  21. RBR副词,比较
  22. RBS副词,最高级
  23. RP粒子
  24. SYM符号
  25. UH感叹词
  26. VB动词,基本形式
  27. VBD动词,过去时
  28. VBG动词,动名词或现在分词
  29. VBN动词,过去分词
  30. VBP动词,非第三人称单数形式的礼物
  31. VBZ动词,第三人称单数礼物
  32. WDT决定者
  33. WP Whpronoun
  34. WP $专有名词
  35. WRB副词

我关于修改此答案中的缺陷的编辑的建议被拒绝。因此,还请参见我下面发布的答案,其中包含此答案中缺少的一些信息。
Jules 2014年

3
第十个LS到底是多少?
Devavrata 2014年

3
“到”必须是特殊的。有自己的标签
quequeful

4
对此非常有用的参考是Erwin R. Komen的“词性标签列表和说明”。同样有趣的还有Komen的英语研究和Komen的主页erwinkomen.ruhosting.nl
CoolHandLouis 2015年

1
Stanford POS Tagger和Penn Tree bank中使用的标签是否相同?
gokul_uf

113
Explanation of each tag from the documentation :

CC: conjunction, coordinating
    & 'n and both but either et for less minus neither nor or plus so
    therefore times v. versus vs. whether yet
CD: numeral, cardinal
    mid-1890 nine-thirty forty-two one-tenth ten million 0.5 one forty-
    seven 1987 twenty '79 zero two 78-degrees eighty-four IX '60s .025
    fifteen 271,124 dozen quintillion DM2,000 ...
DT: determiner
    all an another any both del each either every half la many much nary
    neither no some such that the them these this those
EX: existential there
    there
FW: foreign word
    gemeinschaft hund ich jeux habeas Haementeria Herr K'ang-si vous
    lutihaw alai je jour objets salutaris fille quibusdam pas trop Monte
    terram fiche oui corporis ...
IN: preposition or conjunction, subordinating
    astride among uppon whether out inside pro despite on by throughout
    below within for towards near behind atop around if like until below
    next into if beside ...
JJ: adjective or numeral, ordinal
    third ill-mannered pre-war regrettable oiled calamitous first separable
    ectoplasmic battery-powered participatory fourth still-to-be-named
    multilingual multi-disciplinary ...
JJR: adjective, comparative
    bleaker braver breezier briefer brighter brisker broader bumper busier
    calmer cheaper choosier cleaner clearer closer colder commoner costlier
    cozier creamier crunchier cuter ...
JJS: adjective, superlative
    calmest cheapest choicest classiest cleanest clearest closest commonest
    corniest costliest crassest creepiest crudest cutest darkest deadliest
    dearest deepest densest dinkiest ...
LS: list item marker
    A A. B B. C C. D E F First G H I J K One SP-44001 SP-44002 SP-44005
    SP-44007 Second Third Three Two * a b c d first five four one six three
    two
MD: modal auxiliary
    can cannot could couldn't dare may might must need ought shall should
    shouldn't will would
NN: noun, common, singular or mass
    common-carrier cabbage knuckle-duster Casino afghan shed thermostat
    investment slide humour falloff slick wind hyena override subhumanity
    machinist ...
NNS: noun, common, plural
    undergraduates scotches bric-a-brac products bodyguards facets coasts
    divestitures storehouses designs clubs fragrances averages
    subjectivists apprehensions muses factory-jobs ...
NNP: noun, proper, singular
    Motown Venneboerger Czestochwa Ranzer Conchita Trumplane Christos
    Oceanside Escobar Kreisler Sawyer Cougar Yvette Ervin ODI Darryl CTCA
    Shannon A.K.C. Meltex Liverpool ...
NNPS: noun, proper, plural
    Americans Americas Amharas Amityvilles Amusements Anarcho-Syndicalists
    Andalusians Andes Andruses Angels Animals Anthony Antilles Antiques
    Apache Apaches Apocrypha ...
PDT: pre-determiner
    all both half many quite such sure this
POS: genitive marker
    ' 's
PRP: pronoun, personal
    hers herself him himself hisself it itself me myself one oneself ours
    ourselves ownself self she thee theirs them themselves they thou thy us
PRP$: pronoun, possessive
    her his mine my our ours their thy your
RB: adverb
    occasionally unabatingly maddeningly adventurously professedly
    stirringly prominently technologically magisterially predominately
    swiftly fiscally pitilessly ...
RBR: adverb, comparative
    further gloomier grander graver greater grimmer harder harsher
    healthier heavier higher however larger later leaner lengthier less-
    perfectly lesser lonelier longer louder lower more ...
RBS: adverb, superlative
    best biggest bluntest earliest farthest first furthest hardest
    heartiest highest largest least less most nearest second tightest worst
RP: particle
    aboard about across along apart around aside at away back before behind
    by crop down ever fast for forth from go high i.e. in into just later
    low more off on open out over per pie raising start teeth that through
    under unto up up-pp upon whole with you
SYM: symbol
    % & ' '' ''. ) ). * + ,. < = > @ A[fj] U.S U.S.S.R * ** ***
TO: "to" as preposition or infinitive marker
    to
UH: interjection
    Goodbye Goody Gosh Wow Jeepers Jee-sus Hubba Hey Kee-reist Oops amen
    huh howdy uh dammit whammo shucks heck anyways whodunnit honey golly
    man baby diddle hush sonuvabitch ...
VB: verb, base form
    ask assemble assess assign assume atone attention avoid bake balkanize
    bank begin behold believe bend benefit bevel beware bless boil bomb
    boost brace break bring broil brush build ...
VBD: verb, past tense
    dipped pleaded swiped regummed soaked tidied convened halted registered
    cushioned exacted snubbed strode aimed adopted belied figgered
    speculated wore appreciated contemplated ...
VBG: verb, present participle or gerund
    telegraphing stirring focusing angering judging stalling lactating
    hankerin' alleging veering capping approaching traveling besieging
    encrypting interrupting erasing wincing ...
VBN: verb, past participle
    multihulled dilapidated aerosolized chaired languished panelized used
    experimented flourished imitated reunifed factored condensed sheared
    unsettled primed dubbed desired ...
VBP: verb, present tense, not 3rd person singular
    predominate wrap resort sue twist spill cure lengthen brush terminate
    appear tend stray glisten obtain comprise detest tease attract
    emphasize mold postpone sever return wag ...
VBZ: verb, present tense, 3rd person singular
    bases reconstructs marks mixes displeases seals carps weaves snatches
    slumps stretches authorizes smolders pictures emerges stockpiles
    seduces fizzes uses bolsters slaps speaks pleads ...
WDT: WH-determiner
    that what whatever which whichever
WP: WH-pronoun
    that what whatever whatsoever which who whom whosoever
WP$: WH-pronoun, possessive
    whose
WRB: Wh-adverb
    how however whence whenever where whereby whereever wherein whereof why

2
能否请您引用出处?
David Portabella

标点符号呢?例如,“,”令牌获得PoS“,”。是否有包含这些PoS的列表?
David Portabella

关于“(”令牌的PoS“ -LRB-”呢?
David Portabella

34

上面接受的答案缺少以下信息:

还定义了9个标点符号(在某些参考文献中未列出,请参见此处)。这些是:

  1. $
  2. ''(用于所有形式的结束语)
  3. ((用于所有形式的左括号)
  4. )(用于所有形式的右括号)
  5. 。(用于所有句子结尾的标点符号)
  6. :(用于冒号,分号和椭圆)
  7. ``(用于所有形式的开盘报价)

17

这是Penn Treebank 的标签的完整列表(为完整起见在此处发布):

http://www.surdeanu.info/mihai/teaching/ista555-fall13/readings/PennTreebankConstituents.html

它还包括条款和短语级别的标签。

条款等级

- S
- SBAR
- SBARQ
- SINV
- SQ

词组水平

- ADJP
- ADVP
- CONJP
- FRAG
- INTJ
- LST
- NAC
- NP
- NX
- PP
- PRN
- PRT
- QP
- RRC
- UCP
- VP
- WHADJP
- WHAVP
- WHNP
- WHPP
- X

(链接中的描述)


2
你知道吗?这是人们需要的真实清单!不仅仅是Penn Treebank POS标签,因为它们只是为了单词
windweller

您可以在缩写旁边添加说明吗?
Petrus Theron

12

万一您想对其进行编码...

/**
 * Represents the English parts-of-speech, encoded using the
 * de facto <a href="http://www.cis.upenn.edu/~treebank/">Penn Treebank
 * Project</a> standard.
 * 
 * @see <a href="ftp://ftp.cis.upenn.edu/pub/treebank/doc/tagguide.ps.gz">Penn Treebank Specification</a>
 */
public enum PartOfSpeech {
  ADJECTIVE( "JJ" ),
  ADJECTIVE_COMPARATIVE( ADJECTIVE + "R" ),
  ADJECTIVE_SUPERLATIVE( ADJECTIVE + "S" ),

  /* This category includes most words that end in -ly as well as degree
   * words like quite, too and very, posthead modi ers like enough and
   * indeed (as in good enough, very well indeed), and negative markers like
   * not, n't and never.
   */
  ADVERB( "RB" ),

  /* Adverbs with the comparative ending -er but without a strictly comparative
   * meaning, like <i>later</i> in <i>We can always come by later</i>, should
   * simply be tagged as RB.
   */
  ADVERB_COMPARATIVE( ADVERB + "R" ),
  ADVERB_SUPERLATIVE( ADVERB + "S" ),

  /* This category includes how, where, why, etc.
   */
  ADVERB_WH( "W" + ADVERB ),

  /* This category includes and, but, nor, or, yet (as in Y et it's cheap,
   * cheap yet good), as well as the mathematical operators plus, minus, less,
   * times (in the sense of "multiplied by") and over (in the sense of "divided
   * by"), when they are spelled out. <i>For</i> in the sense of "because" is
   * a coordinating conjunction (CC) rather than a subordinating conjunction.
   */
  CONJUNCTION_COORDINATING( "CC" ),
  CONJUNCTION_SUBORDINATING( "IN" ),
  CARDINAL_NUMBER( "CD" ),
  DETERMINER( "DT" ),

  /* This category includes which, as well as that when it is used as a
   * relative pronoun.
   */
  DETERMINER_WH( "W" + DETERMINER ),
  EXISTENTIAL_THERE( "EX" ),
  FOREIGN_WORD( "FW" ),

  LIST_ITEM_MARKER( "LS" ),

  NOUN( "NN" ),
  NOUN_PLURAL( NOUN + "S" ),
  NOUN_PROPER_SINGULAR( NOUN + "P" ),
  NOUN_PROPER_PLURAL( NOUN + "PS" ),

  PREDETERMINER( "PDT" ),
  POSSESSIVE_ENDING( "POS" ),

  PRONOUN_PERSONAL( "PRP" ),
  PRONOUN_POSSESSIVE( "PRP$" ),

  /* This category includes the wh-word whose.
   */
  PRONOUN_POSSESSIVE_WH( "WP$" ),

  /* This category includes what, who and whom.
   */
  PRONOUN_WH( "WP" ),

  PARTICLE( "RP" ),

  /* This tag should be used for mathematical, scientific and technical symbols
   * or expressions that aren't English words. It should not used for any and
   * all technical expressions. For instance, the names of chemicals, units of
   * measurements (including abbreviations thereof) and the like should be
   * tagged as nouns.
   */
  SYMBOL( "SYM" ),
  TO( "TO" ),

  /* This category includes my (as in M y, what a gorgeous day), oh, please,
   * see (as in See, it's like this), uh, well and yes, among others.
   */
  INTERJECTION( "UH" ),

  VERB( "VB" ),
  VERB_PAST_TENSE( VERB + "D" ),
  VERB_PARTICIPLE_PRESENT( VERB + "G" ),
  VERB_PARTICIPLE_PAST( VERB + "N" ),
  VERB_SINGULAR_PRESENT_NONTHIRD_PERSON( VERB + "P" ),
  VERB_SINGULAR_PRESENT_THIRD_PERSON( VERB + "Z" ),

  /* This category includes all verbs that don't take an -s ending in the
   * third person singular present: can, could, (dare), may, might, must,
   * ought, shall, should, will, would.
   */
  VERB_MODAL( "MD" ),

  /* Stanford.
   */
  SENTENCE_TERMINATOR( "." );

  private final String tag;

  private PartOfSpeech( String tag ) {
    this.tag = tag;
  }

  /**
   * Returns the encoding for this part-of-speech.
   * 
   * @return A string representing a Penn Treebank encoding for an English
   * part-of-speech.
   */
  public String toString() {
    return getTag();
  }

  protected String getTag() {
    return this.tag;
  }

  public static PartOfSpeech get( String value ) {
    for( PartOfSpeech v : values() ) {
      if( value.equals( v.getTag() ) ) {
        return v;
      }
    }

    throw new IllegalArgumentException( "Unknown part of speech: '" + value + "'." );
  }
}

7

我在这里提供整个列表,并提供参考链接

1.  CC   Coordinating conjunction
2.  CD   Cardinal number
3.  DT   Determiner
4.  EX   Existential there
5.  FW   Foreign word
6.  IN   Preposition or subordinating conjunction
7.  JJ   Adjective
8.  JJR  Adjective, comparative
9.  JJS  Adjective, superlative
10. LS   List item marker
11. MD   Modal
12. NN   Noun, singular or mass
13. NNS  Noun, plural
14. NNP  Proper noun, singular
15. NNPS Proper noun, plural
16. PDT  Predeterminer
17. POS  Possessive ending
18. PRP  Personal pronoun
19. PRP$ Possessive pronoun
20. RB   Adverb
21. RBR  Adverb, comparative
22. RBS  Adverb, superlative
23. RP   Particle
24. SYM  Symbol
25. TO   to
26. UH   Interjection
27. VB   Verb, base form
28. VBD  Verb, past tense
29. VBG  Verb, gerund or present participle
30. VBN  Verb, past participle
31. VBP  Verb, non-3rd person singular present
32. VBZ  Verb, 3rd person singular present
33. WDT  Wh-determiner
34. WP   Wh-pronoun
35. WP$  Possessive wh-pronoun
36. WRB  Wh-adverb

您可以在此处找到词性标签的完整列表。


4

关于找到特定POS(例如,名词)标记的单词/块的第二个问题,这是您可以遵循的示例代码。

public static void main(String[] args) {
    Properties properties = new Properties();
    properties.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(properties);

    String input = "Colorless green ideas sleep furiously.";
    Annotation annotation = pipeline.process(input);
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    List<String> output = new ArrayList<>();
    String regex = "([{pos:/NN|NNS|NNP/}])"; //Noun
    for (CoreMap sentence : sentences) {
        List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
        TokenSequencePattern pattern = TokenSequencePattern.compile(regex);
        TokenSequenceMatcher matcher = pattern.getMatcher(tokens);
        while (matcher.find()) {
            output.add(matcher.group());
        }
    }
    System.out.println("Input: "+input);
    System.out.println("Output: "+output);
}

输出为:

Input: Colorless green ideas sleep furiously.
Output: [ideas]

2

它们似乎是布朗语料库标签


14
不,它们是Penn English Treebank POS标签,是Brown Corpus标签集的简化版。
Christopher Manning 2010年

你确定吗?上面引用的示例包括标签“”。它是在Brown Corpus中定义的,但没有在上面的Penn Treebank标签列表中定义,因此,可以肯定的是,至少答案并不像它们只是Penn Treebank标签那样简单。
2013年

经过更多研究,似乎它们 Penn Treebank标签,但是上面引用的此类标签文档不完整:Penn Treebank标签还包括9个标点符号标签,这些标签在已接受的答案中已从列表中省略。请参阅我的其他答案以获取更多详细信息。
Jules 2014年

2

Stanford CoreNLP其他语言的标签:法语,西班牙语,德语...

我看到您使用英语的解析器,这是默认模型。您可以将解析器用于其他语言(法语,西班牙语,德语...),并且请注意,每种语言的标记器和部分语音标记器都不同。如果要这样做,则必须下载该语言的特定模型(例如,使用Maven之类的构建器),然后设置要使用的模型。 在这里,您有关于此的更多信息。

这里是不同语言的标签列表:

  1. Stanford CoreNLP POS西班牙文标签
  2. 适用于德语的Stanford CoreNLP POS Tagger使用斯图加特-蒂宾根标签集(STTS)
  3. 法语的Stanford CoreNLP POS标记器使用以下标记:

法语标签:

法语的部分语音标签

A     (adjective)
Adv   (adverb)
CC    (coordinating conjunction)
Cl    (weak clitic pronoun)
CS    (subordinating conjunction)
D     (determiner)
ET    (foreign word)
I     (interjection)
NC    (common noun)
NP    (proper noun)
P     (preposition)
PREF  (prefix)
PRO   (strong pronoun)
V     (verb)
PONCT (punctuation mark)

法语的短语分类标签:

AP     (adjectival phrases)
AdP    (adverbial phrases)
COORD  (coordinated phrases)
NP     (noun phrases)
PP     (prepositional phrases)
VN     (verbal nucleus)
VPinf  (infinitive clauses)
VPpart (nonfinite clauses)
SENT   (sentences)
Sint, Srel, Ssub (finite clauses)

法语的语法功能:

SUJ    (subject)
OBJ    (direct object)
ATS    (predicative complement of a subject)
ATO    (predicative complement of a direct object)
MOD    (modifier or adjunct)
A-OBJ  (indirect complement introduced by à)
DE-OBJ (indirect complement introduced by de)
P-OBJ  (indirect complement introduced by another preposition)

@AMArostegui:谢谢您的提示。请共享一个链接,其中明确提到通用依赖项用于西班牙语。该链接用于UD,但没有暗示它们在Stanfoird Core NLP中实际上是用于西班牙语的,Stanford的官方文档也没有提及。
Catalina Chircu

0

我认为这是很快的,在一个低端笔记本中它将像这样运行:

import spacy
import time

start = time.time()

with open('d:/dictionary/e-store.txt') as f:
    input = f.read()

word = 0
result = []

nlp = spacy.load("en_core_web_sm")
doc = nlp(input)

for token in doc:
    if token.pos_ == "NOUN":
        result.append(token.text)
    word += 1

elapsed = time.time() - start

print("From", word, "words, there is", len(result), "NOUN found in", elapsed, "seconds")

在几个试验中的输出:

From 3547 words, there is 913 NOUN found in 7.768507719039917 seconds
From 3547 words, there is 913 NOUN found in 7.408619403839111 seconds
From 3547 words, there is 913 NOUN found in 7.431427955627441 seconds

因此,我认为您无需担心每个POS标签检查的循环:)

当禁用某些管道时,我得到了更多改进:

nlp = spacy.load("en_core_web_sm", disable = 'ner')

因此,结果更快:

From 3547 words, there is 913 NOUN found in 6.212834596633911 seconds
From 3547 words, there is 913 NOUN found in 6.257707595825195 seconds
From 3547 words, there is 913 NOUN found in 6.371225833892822 seconds
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.