Mathematica - 从字符串搜索中排除字符串
我正在尝试选择表格中最常出现的关键词。 我需要搜索列表中不包含给定第二个、第三个、第四个等单词的单词的出现次数。
例如,我需要搜索单词“lollypop”在不包含单词“candy”的列表中出现的次数。
此代码将返回单词“lollypop”出现的次数:
rt = Parallelize@
Cases[MemoizeTable["Candy_table.txt"],
x_List /;
MemberQ[x,
s_String /;
StringMatchQ[s, ("*lollypop*"), IgnoreCase -> True]], {1}];
我尝试添加 StringFreeQ
来排除“candy”,并尝试添加 Nor
,其中需要添加 > 或者在字符串搜索中,但我不确定如何做到这一点/将其放在哪里/它们..?
基本上,我需要一个“this”而不是“that”代码。
I'm trying to select the most frequently occurring key words on a table.
I need to search for the number of occurrences of a word in a list that DOES NOT include a given second, third, fourth, etc. word.
For example, I need to search for the number of times the word "lollypop" appears in a list that does not include the word "candy".
This code will return the number of times the word "lollypop" appears:
rt = Parallelize@
Cases[MemoizeTable["Candy_table.txt"],
x_List /;
MemberQ[x,
s_String /;
StringMatchQ[s, ("*lollypop*"), IgnoreCase -> True]], {1}];
I tried adding StringFreeQ
to exclude "candy", and I tried adding Nor
where one would add Or
in the string search, but I wasn't sure how to do that/where to put it/them..?
I need a "this" BUT NOT "that"
code, basically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用法:
Usage:
要获取单词,请尝试例如
,您可以通过在末尾添加
//Count
来对它们进行计数(例如)。编辑:看来我误解了你的问题。如果您要问的是:计算“canapes”在列表中出现的次数,该列表不包括“可修改”,则:
while
排除“plate”,因此该列表为 1。
但我对你的评论感到困惑(“此代码正在返回我正在运行其他搜索的列表的初步选择,因此我需要保持列表完整”哪个列表?上面的代码都保持完整)所以我一定还缺少一些东西。
To obtain the words, try eg
and you can count them by adding
//Count
at the end (say).EDIT: It seems I misunderstood your question. If what you're asking is: count the number of times "canapes" appears in a list, which list does not include "modifiable", then:
while
excludes "plate", thus giving 1 for this list.
But I am confused by your comments ("This code is returning a preliminary selection of lists that I'm running other searches on, so I need to keep the list intact" which list? they're all kept intact by the code above) so I must still be missing something.