Stanford CoreNLP法语POS标签

问题描述 投票:0回答:1

我正在寻找一种方法来使用Python对法语句子进行Pos标记。我看到我们可以使用Stanford CoreNLP,但经过谷歌的几次搜索后,我没有找到可以满足我的真实例子。有一段代码向我展示如何解决我的问题会很棒

python nlp stanford-nlp part-of-speech french
1个回答
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)

结果是一个JSON数据结构(您可以通过为outputFormat属性指定不同的值来选择其他格式,例如'text','xml'...)和所有注释,包括POS标记(每个标记的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': '.'}]}]}
© www.soinside.com 2019 - 2024. All rights reserved.