【问题标题】:Stanford CoreNLP POS tagging in French斯坦福 CoreNLP POS 标记法文
【发布时间】:2018-09-04 15:16:48
【问题描述】:

我正在寻找一种使用 Python 对法语句子使用 Pos 标记的方法。我看到我们可以使用斯坦福 CoreNLP,但是在谷歌上搜索了几次之后,我没有找到可以满足我的真实示例.. 如果有一段代码告诉我如何解决我的问题,那就太好了

【问题讨论】:

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


    【解决方案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': '.'}]}]}
    

    【讨论】:

    • 感谢您的回答。但似乎我无法连接到 locaslhost 9000。我收到错误:无法连接,因为目标机器主动拒绝它
    • 您是否下载了 Stanford CoreNLP 并首先运行服务器(请参阅我帖子中的链接)?如果你在运行脚本之前不这样做,那么你会得到一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多