LISP:查找句子中每个单词的出现情况. [英] LISP: Find occurrences of each word in a sentence.

查看:97
本文介绍了LISP:查找句子中每个单词的出现情况.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释我如何搜索句子中每个单词的出现,例如Common lisp中的猫坐在垫子上"吗?

Can someone please explain to me how I search for the occurrences of each word in a sentence, such as "the cat sat on the mat" in Common lisp ?

用户必须事先输入此行文本,然后必须从该行开始计数.甚至从哪里开始的任何帮助都会有所帮助.

The user has to have inputted this line of text before hand and then the occurrences must be counted from that. Any help on even where to start would help.

推荐答案

现在,您可以只使用带有equal的哈希表作为测试,并可以在列表中使用mapc来获取密钥和频率哈希.然后,您可以在哈希表中找到所需的内容.

Now you could just use a hash table with equal as test and perhaps use mapc on the list to get a key and frequency hash. Then you have what you wanted in the hash table.

或者(更慢)是用(count (car lst) lst :test #'equal)计算第一个元素,然后用(remove (car lst) lst :test #'equal)处理列表的其余部分.当过滤后的列表为空时,您就完成了.

Alternatively (and slower) would be to count the first element with (count (car lst) lst :test #'equal) and process the rest of the list with (remove (car lst) lst :test #'equal). When the filtered list is empty you're done.

这篇关于LISP:查找句子中每个单词的出现情况.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆