gpt4 book ai didi

code-golf - Code Golf : Quickly Build List of Keywords from Text, 包括实例数

转载 作者:行者123 更新时间:2023-12-02 22:12:57 24 4
gpt4 key购买 nike

我已经用 PHP 为自己制定了这个解决方案,但我很好奇如何以不同的方式完成它 - 甚至更好。我主要感兴趣的两种语言是 PHP 和 Javascript,但我有兴趣了解当今任何其他主要语言(主要是 C#、Java 等)可以多快地完成此操作。

  1. 仅返回出现次数大于 X 的单词
  2. 仅返回长度大于 Y 的单词
  3. 忽略“and、is、the 等”等常见术语
  4. 在处理之前可以随意删除标点符号(即“John's”变为“John”)
  5. 以集合/数组的形式返回结果

额外积分

  1. 将引用的陈述放在一起,(即“它们显然‘好得令人难以置信’”)
    其中“好得令人难以置信”是实际的陈述

额外额外积分

  1. 您的脚本能否根据单词出现在一起的频率来确定应该放在一起的单词?这是在事先不知道单词的情况下完成的。例子:
    *"The fruit fly is a great thing when it comes to medical research. Much study has been done on the fruit fly in the past, and has lead to many breakthroughs. In the future, the fruit fly will continue to be studied, but our methods may change."*
    显然这里的词是“果蝇”,我们很容易找到。您的 search'n'scrape 脚本也能确定这一点吗?

源文本:http://sampsonresume.com/labs/c.txt

答案格式

  1. 如果能够看到代码的结果、输出以及操作持续的时间,那就太好了。

最佳答案

GNU 脚本

sed -e 's/ /\n/g' | grep -v '^ *$' | sort | uniq -c | sort -nr

结果:

  7 be
6 to
[...]
1 2.
1 -

出现次数大于 X:

sed -e 's/ /\n/g' | grep -v '^ *$' | sort | uniq -c | awk '$1>X'

仅返回长度大于 Y 的单词(在第二个 grep 中放入 Y+1 个点):

sed -e 's/ /\n/g' | grep -v '^ *$' | grep .... | sort | uniq -c

忽略常见术语,如“and、is、the 等”(假设常见术语在文件“ignored”中)

sed -e 's/ /\n/g' | grep -v '^ *$' | grep -vf ignored | sort | uniq -c

在处理之前随意删除标点符号(即“John's”变成“John”):

sed -e 's/[,.:"\']//g;s/ /\n/g' | grep -v '^ *$' | sort | uniq -c

以集合/数组形式返回结果:它已经像 shell 的数组一样:第一列是计数,第二列是单词。

关于code-golf - Code Golf : Quickly Build List of Keywords from Text, 包括实例数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1038252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com