NLPPOS挑战赛

2024-06-16 09:24:52 发布

您现在位置:Python中文网/ 问答频道 /正文

请在hackerrank上找到原始问题

虽然,我的解决方案是不完整的,有人能帮我理解我哪里做错了吗?(在第二个函数中,tagger返回一个2个字母的标签,尽管问题要求一个3个字母的标签。谢谢!你知道吗

import re
import nltk
import string
final_tagged = ""
raw_input(strs)
def tokenize_two(i):
    temp = i
    global strs
    "remove /?? and pos tag"
    for ch in ['/??']:
        if ch in i:
            i=i.replace(ch,"")
            #pos tagging
    tag = nltk.pos_tag([i])
    for item in tag:
        for ch in ['??']:
            if ch in temp:
                temp = temp.replace(ch,item[1])
    replace = i+"/??"
    strs = string.replace(strs,replace,temp)
    return temp;

def tokenize_three(i):
    "remove /??? and pos tag"
    temp = i 
    global strs
    for ch in ['/???']:
        if ch in i:
            i=i.replace(ch,"")
    tag = nltk.pos_tag([i])
    for item in tag:
        for ch in ['???']:
            if ch in temp:
                temp = temp.replace(ch,item[1])
    replace = i+"/???"
    strs = string.replace(strs,replace,temp)
    return temp;

a = [w for w in re.split('\s+',strs)]
for i in a :
    if(i.endswith("/??")):
        tagged = tokenize_two(i)
    if(i.endswith("/???")):
        final_tagged = tokenize_three(i)
print strs

Tags: inposimportforstringiftagch
1条回答
网友
1楼 · 发布于 2024-06-16 09:24:52
tag = nltk.pos_tag([i])

词性标注依赖于上下文。您需要将整个标记化句子作为参数传递给pos_tag,而不是为每个未知单词调用一次pos_tag。你知道吗

相关问题 更多 >