我正在寻找一种解决方案,允许我根据非官方/已知/书面规则生成名称。
以下是几个示例:
我最初是在考虑机器学习,但是我不知道该怎么做。
非常感谢您
答案 0 :(得分:0)
import random
from nltk import word_tokenize
def generate_name(s):
s_tokenized = word_tokenize(s)
stop_words= ['de']
s_tokenized_list = []
for w in s_tokenized:
if w not in stop_words:
s_tokenized_list.append(w)
name=[]
length_of_list = len(s_tokenized_list)
if length_of_list>=3:
for n in s_tokenized_list[:length_of_list-1]:
name.append(n[0])
elif length_of_list==2:
for n in s_tokenized_list[:length_of_list-1]:
name.append(n[0])
name= ''.join(name)
return ''.join(name+s_tokenized_list[length_of_list-1].upper())