python - 如何提取 WordNet 同义词集的偏移量以在 Python NLTK 中提供同义词集?

标签 python nlp nltk semantics wordnet

WordNet 中的意义偏移量是一个 8 位数字,后跟一个 POS 标记。例如,同义词集“dog.n.01”的偏移量是“02084071-n”。我尝试了以下代码:

    from nltk.corpus import wordnet as wn

    ss = wn.synset('dog.n.01')
    offset = str(ss.offset)
    print (offset)

但是,我得到了这个输出:

    <bound method Synset.offset of Synset('dog.n.01')>

如何获得这种格式的实际偏移量:'02084071-n'?

最佳答案

>>> from nltk.corpus import wordnet as wn
>>> ss = wn.synset('dog.n.01')
>>> offset = str(ss.offset()).zfill(8) + '-' + ss.pos()
>>> offset
u'02084071-n'

关于python - 如何提取 WordNet 同义词集的偏移量以在 Python NLTK 中提供同义词集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31223082/

相关文章:

python - 检查列表中是否有任何条目以指定字符串结尾

python - 在 SQLAlchemy 过滤器表达式中执行 "ilike or ilike"时出现类型错误

machine-learning - 计算词性标注器准确度的参数

python - 我有一个印地文 wordnet 数据库和 API。我想从 NLTK python 访问这个 wordnet。有没有办法将我们自己的wordnet添加到NLTK中?

python - 元组python中的最大第二个元素

python - 电子邮件解析 : TypeError: parse() takes at least 2 arguments (2 given)

java - 无法在 .\stanford-corenlp-4.0.0 找到 stanford-parser\.jar jar 文件

java - 在 openNLP 中编写我们自己的模型

python - 使用样本语料库训练机器学习算法,然后从任意文本中提取相似部分

python - 组合常见搭配的 NLP 过程