小编sha*_*han的帖子

Spacy中的命名实体识别

我试图找到一个句子的命名实体,如下所示

import spacy.lang.en
parser = spacy.lang.en.English()
ParsedSentence = parser(u"Alphabet is a new startup in China")
for Entity in  ParsedSentence.ents:  
    print (Entity.label, Entity.label_, ' '.join(t.orth_ for t in Entity))
Run Code Online (Sandbox Code Playgroud)

我期待得到结果"字母","中国",但我得到一个空集作为结果.我在这做错了什么

python named-entity-recognition spacy

11
推荐指数
1
解决办法
1万
查看次数

RangeIndex 对象不可调用

我正在从文本文件中读取值,并尝试查找子字符串的索引,如下所示

df=pd.read_csv('break_sent.txt', index_col=False,encoding='utf-8',delimiter="\n",names=['sent'])
#print(df[:50])
#df.index = list(df.index)
df1= df[40:50]
print(len(df))
print(df1.index)
print("-------------------------------------------")
for i,row in df1.iterrows():
    string = row['sent']
    #print("string",string)
    d = df1[df1.sent.str.match(string)] # if the result includes more than 1 value then we know that substring and its matching parent string are present, then I will eliminate the substring from the dataframe
    if len(d.index > 2):
        index_val = df.index(string)
        df.drop(df.index(string),inpace=True)
        df.reset_index(level=None, drop=True, inplace=True)
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,出现以下错误

Traceback (most recent call last):
  File "process.py", line 15, in <module>
    index_val = df.index(string)
    TypeError: …
Run Code Online (Sandbox Code Playgroud)

python indexing slice python-3.x pandas

6
推荐指数
1
解决办法
5万
查看次数

python中数值范围的正则表达式

我需要找到“数字-数字”格式的数字范围。数字应在 0-3000 范围内。所以我想出了这个正则表达式

match = re.search(r'^[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]-[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]',sentence)
Run Code Online (Sandbox Code Playgroud)

当我运行该程序时,我只想提取句子中的 56-900,但该程序提取了其他数字,例如 2016、CLP2012 等。我只想提取中间有“-”的数字。我的模式有什么问题。

python regex

3
推荐指数
1
解决办法
4681
查看次数

使用带有特殊字符的正则表达式在python中查找匹配项

我正在提取一个字符串,需要检查它是否遵循特定模式

<![any word]>

如果是这样我需要用""替换它.我正在尝试以下代码

string1 = "<![if support]> hello"
string = re.sub(re.compile("<![.*?]>"),"",string1)
print(string)
Run Code Online (Sandbox Code Playgroud)

但是我得到了输出

<![if support]> hello 
Run Code Online (Sandbox Code Playgroud)

我希望输出为hello.我在这做错了什么?

python regex string

1
推荐指数
1
解决办法
3686
查看次数