如果我想返回一个列表上的操作,但当它返回 null 时它保持不变,我该怎么说呢?
我有一个土耳其语词组列表。我想应用词干分析,我找到了 turkishnlp 包。尽管它有一些缺点,但它经常返回正确的单词。但是,当我将其应用于列表时,我不希望列表的结构发生变化,并且我希望他不知道的单词保持不变。
例如,我有这个列表: mylist = [['yolda','gelirken','kopek', 'gördüm'],['cok', 'tatlıydı']]
我写了这个函数:
from trnlp import TrnlpWord
def tr_stemming(x):
obj = TrnlpWord()
obj.setword(x) if isinstance(x, str) else type(x)(map(tr_stemming, x))
return obj.get_stem if isinstance(x, str) else type(x)(map(tr_stemming, x))
这个函数返回这个列表:
tr_stemming(mylist)
[['yol', 'gelir', '', 'gör'], ['', 'tatlı']]
但是,我想得到这是输出: [['yol', 'gelir', 'kopek', 'gör'], ['cok', 'tatlı']]
如何更新我的函数? 感谢您的帮助!
I have a list-of-list of word groups in Turkish. I want to apply stemming and I found turkishnlp package. Although it has some shortcomings, it often returns the right word. However, when I apply this to the list, I don't want the structure of my list to change and I want the words that he doesn't know to stay the same.
For example, I have this list:
mylist = [['yolda','gelirken','kopek', 'gördüm'],['cok', 'tatlıydı']]
And I wrote this function:
from trnlp import TrnlpWord
def tr_stemming(x):
obj = TrnlpWord()
obj.setword(x) if isinstance(x, str) else type(x)(map(tr_stemming, x))
return obj.get_stem if isinstance(x, str) else type(x)(map(tr_stemming, x))
This function returns this list:
tr_stemming(mylist)
[['yol', 'gelir', '', 'gör'], ['', 'tatlı']]
However, I want to get this as the output:
[['yol', 'gelir', 'kopek', 'gör'], ['cok', 'tatlı']]
How can I update my function?
Thank you for your helps!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIUC,您可以将函数修改为:
输出:
IIUC, you could modify your function to:
output: