我发现了几个这方面的主题,我找到了这个解决方案:
sentence=re.sub(ur"[^\P{P}'|-]+",'',sentence)
Run Code Online (Sandbox Code Playgroud)
这应该删除除了'之外的每个标点符号,问题是它还会删除句子中的所有其他标点符号.
例:
>>> sentence="warhol's art used many types of media, including hand drawing, painting, printmaking, photography, silk screening, sculpture, film, and music."
>>> sentence=re.sub(ur"[^\P{P}']+",'',sentence)
>>> print sentence
'
Run Code Online (Sandbox Code Playgroud)
当然我想要的是保持句子没有标点符号,"warhol"保持原样
期望的输出:
"warhol's art used many types of media including hand drawing painting printmaking photography silk screening sculpture film and music"
"austro-hungarian empire"
Run Code Online (Sandbox Code Playgroud)
编辑:我也试过用
tbl = dict.fromkeys(i for i in xrange(sys.maxunicode)
if unicodedata.category(unichr(i)).startswith('P'))
sentence = sentence.translate(tbl)
Run Code Online (Sandbox Code Playgroud)
但这会删除每个标点符号
在 MS Access 中,我正在从另一个对话框窗体打开一个对话框窗体。
于是formA,打开formB。但是他们的用户可能会formB作为独立打开,我想避免在这种情况下出现错误。
我考虑过检查formB.
但是当我这样做时,我仍然收到错误 2452:您输入的表达式对 Parent 属性无效。
我试过:
If Not IsError(Me.Parent) Then
Me.Parent.cboTraining.Requery
End If
Run Code Online (Sandbox Code Playgroud)
和
If Not IsNull(Me.Parent) Then
Me.Parent.cboTraining.Requery
End If
Run Code Online (Sandbox Code Playgroud) 所以我从json文件中提取数据,我计划将其提供给第三方程序Qanta,这是一个RNN.
好吧,无论如何,我试图以一种方式打包我的数据,所以Qanta的预处理脚本可以使用它.
来自qanta的代码:
for key in split:
hist = split[key]
for text, ans, qid in hist:
Run Code Online (Sandbox Code Playgroud)
现在,我从json文件中获取了一个危险问题解答的提取数据集,并将其打包成一个字典,如下所示:
dic{}
result //is the result of removing some formatting elements and stuff from the Question, so is a question string
answer //is the answer for the Q
i // is the counter for Q & A pairs
Run Code Online (Sandbox Code Playgroud)
所以我有
this = (result,answer,i)
dic[this]=this
Run Code Online (Sandbox Code Playgroud)
当我尝试从qanta复制原始代码时,我得到太多的值来解压错误
for key in dic:
print(key)
hist = dic[key]
print(hist[0])
print(hist[1])
print(hist[2])
for text, ans, qid in hist[0:2]: // EDIT: changing …Run Code Online (Sandbox Code Playgroud)