简体   繁体   English

比较2个字符串与重复部分

[英]Compare 2 strings with repetitive parts

I am developing a speak reconition trainer and I want to get the hits and errors of the trainer result. 我正在开发一个语音复习教练,我想知道教练结果的成败。 I have the real sentence and the predicted sentence and I have something like this: 我有真实的句子和预测的句子,并且我有这样的东西:

if real == predicted:
    hits += 1
else:
    errors += 1

My problem comes now... The predicted strings are with the form: 我的问题来了...预测的字符串具有以下形式:

- 'command' 'time' 'unit'

Where 'unit' can be [minute,minutes,second,seconds] And I want to count as hit the sentence with minute or minutes and second or secons. “单位”可以是[分钟,分钟,秒,秒],而我想算为命中分钟或分钟,秒或秒数的句子。 For example. 例如。

Real: stop five minutes and walk one second Predicted1: stop five minute and walk one second Predicted2: stop five minutes and walk one seconds Predicted3: stop three minute and walk one seconds 真实:停止五分钟,走一秒钟Predicted1:停止五分钟,走一秒钟Predicted2:停止五分钟,走一秒钟Predicted3:停止三分钟,走一秒钟

Where Predicted1 and Predicted2 are hits and Predicted3 an error. 命中Predicted1和Predicted2,Predicted3是错误。 There are a fast way without turning all as lists and this kind of things 有一种快速的方法可以不将所有内容都列出来

A quick solution would be to strip the rightmost s from the units and then compare. 一种快速的解决方案是从单元中剥离最右边的s ,然后进行比较。

That is, if the unit is in variable unit , then unit.rstrip('s') returns the units without the rightmost s , and doesn't change the unit if it didn't have an s in the first place. 也就是说,如果该单元是在可变unit ,然后unit.rstrip('s')返回单元而不最右边的s ,并且如果它不具有不改变单元s在首位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM