Algorithm 每次击键后进行文本比较的工具/算法

Algorithm 每次击键后进行文本比较的工具/算法,algorithm,text,time,comparison,typing,Algorithm,Text,Time,Comparison,Typing,我正在努力寻找一种文本比较工具或算法,可以将预期的文本与正在键入的文本的当前状态进行比较。 我会让一个实验对象在眼前打字。我的想法是在键入内容时,将文本的当前状态与预期文本进行比较。通过这种方式,我想找出主题在什么时候出错,什么地方出错(我还想找出错误,这些错误不在结果文本中,而是在中间文本中出现了一段时间)。 有人能给我指个方向吗 更新#1 我可以访问csv格式的键入数据: 这是me键入“foOBar”的输出数据示例。每行都有一个表单(时间戳、键、按键/释放) 用Python 给定您输入的cs

我正在努力寻找一种文本比较工具或算法,可以将预期的文本与正在键入的文本的当前状态进行比较。 我会让一个实验对象在眼前打字。我的想法是在键入内容时,将文本的当前状态与预期文本进行比较。通过这种方式,我想找出主题在什么时候出错,什么地方出错(我还想找出错误,这些错误不在结果文本中,而是在中间文本中出现了一段时间)。 有人能给我指个方向吗

更新#1 我可以访问csv格式的键入数据: 这是me键入“foOBar”的输出数据示例。每行都有一个表单(时间戳、键、按键/释放)

用Python 给定您输入的csv文件(我称之为
keyboard\u records.csv

以下代码执行以下操作:

  • 读取其内容并将其存储在名为
    steps
  • 对于每个
    步骤
    中的
    步骤
    可以识别发生了什么,并且
    • 如果是
      shift
      按下或释放相应设置一个标志(
      shift\u on
    • 如果按下箭头,则移动
      光标
      (插入字符的
      当前
      索引)-如果光标位于字符串的开头或结尾,则不应移动,这就是为什么
      min()
      max()
    • 如果是字母/数字/符号,则将其添加到
      curret
      cursor
      位置,并递增
      cursor
  • 给你

    import csv
    
    steps = [] # list of all actions performed by user
    expected = "Hello"
    
    with open("keyboard.csv") as csvfile:
        for row in csv.reader(csvfile, delimiter=','):
            steps.append((float(row[0]), row[1], row[2]))
    
    # Now we parse the information
    current = [] # text written by the user
    shift_on = False # is shift pressed
    cursor = 0 # where is the cursor in the current text
    for step in steps:
        time, key, action = step
        if key == 'LeftShift':
            if action == 'P':
                shift_on = True
            else:
                shift_on = False
            continue
        if key == 'LeftArrow' and action == 'P':
            cursor = max(0, cursor-1)
            continue
        if key == 'RightArrow' and action == 'P':
            cursor = min(len(current), cursor+1)
            continue
        if action == 'P':
            if shift_on is True:
                current.insert(cursor, key.upper())
            else:
                current.insert(cursor, key.lower())
            cursor += 1
            # Now you can join current into a string
            # and compare current with expected
            print(''.join(current)) # printing current (just to see what's happening)
        else:
            # What to do when a key is released?
            # Depends on your needs...
            continue
    
    要比较当前的
    和预期的
    请查看

    注意:通过使用上面的代码和其他一些标志,您可以使它也识别符号。这取决于你的键盘。在我的
    Shift+6=&
    AltGr+E=€
    Ctrl+Shift+AltGr+è={
    。我认为这是一个很好的起点


    更新 比较两个文本并不是一项困难的任务,你可以在网上找到更多的页面。 无论如何,我想向您展示一种面向对象的方法来解决这个问题,所以我添加了
    compare
    部分,我以前在第一个解决方案中忽略了这一部分

    这仍然是一个粗略的代码,没有对输入的主要控制。但是,正如你所问的,这为你指明了方向

    上述
    csv
    文件的输出为:

    Expected:       foobar
    Current:        f
    
    [0 errors at time 17293398.576653]
    
    Expected:       foobar
    Current:        fo
    
    [0 errors at time 17293401.313254]
    
    
    Expected:       foobar
    Current:        foO
                      ^
    [1 errors at time 17293402.073046]
    
    Expected:       foobar
    Current:        foOB
                      ^^
    [2 errors at time 17293403.178612]
    
    
    Expected:       foobar
    Current:        foOBa
                      ^^
    [2 errors at time 17293404.966193]
    
    Expected:       foobar
    Current:        foOBar
                      ^^
    [2 errors at time 17293405.725405]
    
    用Python 给定您输入的csv文件(我称之为
    keyboard\u records.csv

    以下代码执行以下操作:

  • 读取其内容并将其存储在名为
    steps
  • 对于每个
    步骤
    中的
    步骤
    可以识别发生了什么,并且
    • 如果是
      shift
      按下或释放相应设置一个标志(
      shift\u on
    • 如果按下箭头,则移动
      光标
      (插入字符的
      当前
      索引)-如果光标位于字符串的开头或结尾,则不应移动,这就是为什么
      min()
      max()
    • 如果是字母/数字/符号,则将其添加到
      curret
      cursor
      位置,并递增
      cursor
  • 给你

    import csv
    
    steps = [] # list of all actions performed by user
    expected = "Hello"
    
    with open("keyboard.csv") as csvfile:
        for row in csv.reader(csvfile, delimiter=','):
            steps.append((float(row[0]), row[1], row[2]))
    
    # Now we parse the information
    current = [] # text written by the user
    shift_on = False # is shift pressed
    cursor = 0 # where is the cursor in the current text
    for step in steps:
        time, key, action = step
        if key == 'LeftShift':
            if action == 'P':
                shift_on = True
            else:
                shift_on = False
            continue
        if key == 'LeftArrow' and action == 'P':
            cursor = max(0, cursor-1)
            continue
        if key == 'RightArrow' and action == 'P':
            cursor = min(len(current), cursor+1)
            continue
        if action == 'P':
            if shift_on is True:
                current.insert(cursor, key.upper())
            else:
                current.insert(cursor, key.lower())
            cursor += 1
            # Now you can join current into a string
            # and compare current with expected
            print(''.join(current)) # printing current (just to see what's happening)
        else:
            # What to do when a key is released?
            # Depends on your needs...
            continue
    
    要比较当前的
    和预期的
    请查看

    注意:通过玩上面的代码和几个标志,你可以让它也识别符号。这取决于你的键盘。在我的
    Shift+6=&
    AltGr+E=€
    Ctrl+Shift+AltGr+è={
    中,我认为这是一个好的开始


    更新 比较两个文本并不是一项困难的任务,你可以在网上找到更多的页面。 无论如何,我想向您展示一种面向对象的方法来解决这个问题,所以我添加了
    compare
    部分,我以前在第一个解决方案中忽略了这一部分

    这仍然是一个粗略的代码,没有对输入的主要控制。但是,正如你所问的,这为你指明了方向

    上述
    csv
    文件的输出为:

    Expected:       foobar
    Current:        f
    
    [0 errors at time 17293398.576653]
    
    Expected:       foobar
    Current:        fo
    
    [0 errors at time 17293401.313254]
    
    
    Expected:       foobar
    Current:        foO
                      ^
    [1 errors at time 17293402.073046]
    
    Expected:       foobar
    Current:        foOB
                      ^^
    [2 errors at time 17293403.178612]
    
    
    Expected:       foobar
    Current:        foOBa
                      ^^
    [2 errors at time 17293404.966193]
    
    Expected:       foobar
    Current:        foOBar
                      ^^
    [2 errors at time 17293405.725405]
    

    大约一年前,我找到了自己问题的解决方案。现在我有时间与大家分享:

    R.William Soukoreff和I.Scott MacKenzie在其2003年的论文《文本输入研究的指标:MSD和KSPC的评估,以及新的统一错误指标》中提出了三个主要的新指标:“总错误率”、“纠正错误率”和“未纠正错误率”。自本pap发布以来,这些指标已经得到了很好的确立呃,这些就是我想要的指标


    如果您试图做一些与我类似的事情,例如,比较不同输入设备上的书写性能,这就是解决方法。

    我大约在一年前找到了自己问题的解决方案。现在我有时间与您分享:

    R.William Soukoreff和I.Scott MacKenzie在其2003年的论文《文本输入研究的指标:MSD和KSPC的评估,以及新的统一错误指标》中提出了三个主要的新指标:“总错误率”、“纠正错误率”和“未纠正错误率”。自本pap发布以来,这些指标已经得到了很好的确立呃,这些就是我想要的指标


    <>如果你想做一些与我所做的相似的事情,比如比较不同输入设备上的写作性能,这就是方法。

    什么是编程语言?这个项目是C++的,但是我很欣赏任何语言的解决方案。在C++中,没有用户按下<代码>输入< /代码>,这取决于OS和终端使用的……你使用的是什么OS?实际上我将拥有一个具有关键名称和相应时间戳的CSV文件。我可以从该数据中重新创建文本或直接使用CSV。在每次更改之后,我也可以访问全文。“不需要比较”
    Expected:       foobar
    Current:        f
    
    [0 errors at time 17293398.576653]
    
    Expected:       foobar
    Current:        fo
    
    [0 errors at time 17293401.313254]
    
    
    Expected:       foobar
    Current:        foO
                      ^
    [1 errors at time 17293402.073046]
    
    Expected:       foobar
    Current:        foOB
                      ^^
    [2 errors at time 17293403.178612]
    
    
    Expected:       foobar
    Current:        foOBa
                      ^^
    [2 errors at time 17293404.966193]
    
    Expected:       foobar
    Current:        foOBar
                      ^^
    [2 errors at time 17293405.725405]