Stanford CoreNLP POS法语标记

时间:2018-09-04 15:16:49

标签: python nlp stanford-nlp part-of-speech french

我正在寻找一种使用Python对法语句子使用Pos标记的方法。我看到我们可以使用Stanford CoreNLP,但是在Google上进行了几次搜索后,我没有找到能让我满意的真实示例。 拥有一段代码向我展示如何解决我的问题将是很棒的

1 个答案:

答案 0 :(得分:1)

Stanford CoreNLP有许多Python包装器。有一个列表here(以及其他语言的包装器)。您需要先运行Stanford CoreNLP server。以下是使用pycorenlp的一些代码:

from pycorenlp import StanfordCoreNLP

nlp = StanfordCoreNLP('http://localhost:9000')

text = "Ceci est un test de l'étiqueteur morpho-syntaxique du français."

output = nlp.annotate(text, properties={
  'annotators': 'tokenize, ssplit, pos',
  'outputFormat': 'json'
  })

from pprint import pprint
pprint(output)

结果是带有所有注释(包括POS标签)的JSON数据结构(您可以为outputFormat属性指定其他值来选择其他格式,例如'text','xml'...) (每个令牌的pos属性),如下所示:

{'sentences': [{'index': 0,
                'tokens': [{'after': ' ',
                            'before': '',
                            'characterOffsetBegin': 0,
                            'characterOffsetEnd': 4,
                            'index': 1,
                            'originalText': 'Ceci',
                            'pos': 'NNP',
                            'word': 'Ceci'},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 5,
                            'characterOffsetEnd': 8,
                            'index': 2,
                            'originalText': 'est',
                            'pos': 'NNP',
                            'word': 'est'},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 9,
                            'characterOffsetEnd': 11,
                            'index': 3,
                            'originalText': 'un',
                            'pos': 'JJ',
                            'word': 'un'},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 12,
                            'characterOffsetEnd': 16,
                            'index': 4,
                            'originalText': 'test',
                            'pos': 'NN',
                            'word': 'test'},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 17,
                            'characterOffsetEnd': 19,
                            'index': 5,
                            'originalText': 'de',
                            'pos': 'IN',
                            'word': 'de'},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 20,
                            'characterOffsetEnd': 32,
                            'index': 6,
                            'originalText': "l'étiqueteur",
                            'pos': 'JJ',
                            'word': "l'étiqueteur"},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 33,
                            'characterOffsetEnd': 50,
                            'index': 7,
                            'originalText': 'morpho-syntaxique',
                            'pos': 'JJ',
                            'word': 'morpho-syntaxique'},
                           {'after': ' ',
                            'before': ' ',
                            'characterOffsetBegin': 51,
                            'characterOffsetEnd': 53,
                            'index': 8,
                            'originalText': 'du',
                            'pos': 'NNP',
                            'word': 'du'},
                           {'after': '',
                            'before': ' ',
                            'characterOffsetBegin': 54,
                            'characterOffsetEnd': 62,
                            'index': 9,
                            'originalText': 'français',
                            'pos': 'NN',
                            'word': 'français'},
                           {'after': '',
                            'before': '',
                            'characterOffsetBegin': 62,
                            'characterOffsetEnd': 63,
                            'index': 10,
                            'originalText': '.',
                            'pos': '.',
                            'word': '.'}]}]}
相关问题