错误:“ filter”输入“ ..1”存在问题

问题描述

我正在编写要合并到闪亮应用程序中的功能,该功能可以从一组预定义的文件中预测下一个单词。当我创建使用ngram预测下一个单词的函数时,

我遇到了这个错误

metrics.calinski_harabasz_score(X,labels)

这是我的R程序。我已经在另一个R脚本中创建了二元语法的三元语法和四元语法的单词,并将其保存为我在这里使用的rds文件


x object of type 'closure' is not subsettable
i Input ..1 is top_n_rank(1,n).

Run rlang::last_error() to see where the error occurred.

In addition: Warning message:
In is.na(x) : is.na() applied to non-(list or vector) of type 'closure'

This is an snippet of the quad_words.rds

解决方法

也许这里缺少的步骤是在选择最上面的ngram之前先计算每种情况下最常见的ngram。一个简单的解决方案是用add_count代替top_n

filter(quad_words,word1==input_words[num-2],word2==input_words[num-1],word3==input_words[num])  %>%
  add_count(word4,sort = TRUE) %>% 
  filter(row_number() == 1L) %>%
  select(num_range("word",4)) %>%
  as.character() -> out
ifelse(out=="character(0)",trigram(input_words),return(out))

...作为四边形调用的中心部分。过滤掉词1-3后,对word4的调用会计算最频繁的第4个词。 sort = TRUE参数使最高频率的组合图出现在第1行中,然后选择您的下一行。希望这是一个有用的步骤-如果可以解决此特定问题,请跟进任何问题或更正,或标记为完成。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...