- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
考虑一下我有一个
string1 = "hello hi goodmorning evening [...]"
还有一些次要的关键词
compare1 = "hello evening"
compare2 = "hello hi"
我需要一个函数来返回文本和关键字之间的关联。示例:
function(string1,compare1); // returns: 4
function(string1,compare2); // returns: 5 (more relevant)
请注意,5 和 4 只是示例。
你可以说 - 写一个计算出现次数的函数 - 但对于这个例子,这是行不通的,因为两者都出现了 2 次,但 compare1 不太相关,因为在 string1 中没有准确找到“hello evening”(这两个词 hello和晚上比你好更遥远 hi)
有没有已知的算法可以做到这一点?
添加1:
在这种情况下,像“编辑距离”这样的算法将不起作用。因为 string1 是一个完整的文本(比如 300-400 个单词),比较字符串最多 4-5 个单词。
最佳答案
您要查找的内容似乎与 Smith–Waterman algorithm 非常相似做。
来自维基百科:
The algorithm was first proposed by Temple F. Smith and Michael S. Waterman in 1981. Like the Needleman-Wunsch algorithm, of which it is a variation, Smith-Waterman is a dynamic programming algorithm. As such, it has the desirable property that it is guaranteed to find the optimal local alignment with respect to the scoring system being used (which includes the substitution matrix and the gap-scoring scheme).
让我们看一个实际的例子,这样你就可以评估它的用处。
假设我们有一段文字:
text = "We the people of the United States, in order to form a more
perfect union, establish justice, insure domestic tranquility,
provide for the common defense,
promote the general welfare,
and secure the blessings of liberty to ourselves and our posterity,
do ordain and establish this Constitution for the United States of
America.";
为了方便阅读,我将要匹配的部分隔离出来。
我们将比较相似性(或相似性)与字符串列表:
list = {
"the general welfare",
"my personal welfare",
"general utopian welfare",
"the general",
"promote welfare",
"stackoverflow rulez"
};
我已经实现了算法,所以我将计算相似度并对结果进行归一化:
sw = SmithWatermanSimilarity[ text, #] & /@ list;
swN = (sw - Min[sw])/(Max[sw] - Min[sw])
然后我们绘制结果:
我认为这与您的预期结果非常相似。
喂!
一些实现(带源代码)
关于algorithm - 返回文本之间亲和性的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4788344/
我只能在线找到有关将 pods 附加到基于标签的节点的文档。 有没有一种方法可以根据标签和计数将 pods 附加到节点上-那么只有带有标签y的x pods 吗? 我们的方案是,我们只想在每个节点上运行
假设一台机器上有两个处理器。线程 A 在 P1 上运行,线程 B 在 P2 上运行。 线程 A 调用 Sleep(10000); 是否有可能当线程 A 再次开始执行时,它在 P2 上运行? 如果是,谁
我想创建一个 C++11 线程,我希望它在我的第一个核心上运行。我发现 pthread_setaffinity_np 和 sched_setaffinity 可以改变线程的 CPU affinity
我正在从事计算密集型 C# 项目,该项目实现了多种算法。问题是,当我想分析我的应用程序时,特定算法所需的时间会有所不同。例如,有时运行该算法 100 次大约需要 1100 毫秒,而另一次运行 100
我想将父进程关联到一个特定的核心。在下面的代码中,变量 core 是用户提供的参数。之后,我想创建 NUM_CHILDREN 个进程,并且每个进程都以循环方式关联到其中一个核心。子进程跳出循环并执行更
我很少有与线程和进程调度相关的问题。 当我的进程进入休眠状态并唤醒时,它是否总是会被调度到之前调度的同一个 CPU 上? 当我从进程中创建一个线程时,它是否也总是在同一个 CPU 上执行?即使其他 C
我有一个服务器进程,它派生出许多子进程。服务器进程与 CPU 核心具有亲和性,但我不希望子进程继承这种亲和性(操作系统应该处理运行这些进程的位置)。有没有一种方法可以根据 cpu 亲和性解除父子进程的
尝试在 Amazon EC2 等虚拟化环境中的多核处理器上高效使用 L2 缓存时,CPU 关联性任务集是否适用? 最佳答案 不,尤其是对于较小的实例,CPU 共享量很大,您依赖于其他实例对 CPU 的
sched_setaffinity 或 pthread_attr_setaffinity_np 是否可以在 OpenMP 下设置线程关联? 相关:CPU Affinity 最佳答案 是的,命名调用将用
所以我有 4 个节点。 1是System,1是Dev,1是Qa,1是UAT。 我的亲和性如下: apiVersion: apps/v1 kind: Deployment metadata: nam
我找不到指定当附属部署使用多个副本扩展时 Kubernetes 服务行为方式的文档。 我假设有某种负载平衡。是否与服务类型有关? 此外,我希望在服务转发的请求中具有某种关联性(即,如果可能,所有具有特
我想获取有关启用了 ARR Affinity 和自动缩放的应用程序行为的详细信息? 假设我在 Azure Web App 上部署有状态 ASP.NET Web 应用。因此我启用了 ARR Affini
R 2.14.0 或更高版本包括 R package parallel它提供了对并行计算的支持。 在 类 Unix 下,此软件包提供 facility for setting CPU affinity
我想获取有关启用了 ARR Affinity 和自动缩放的应用程序行为的详细信息? 假设我在 Azure Web App 上部署有状态 ASP.NET Web 应用。因此我启用了 ARR Affini
在 Qt5 中使用线程,如何设置单个线程的 CPU affinity ? 我想指定线程可以在其下运行的可用 CPU 内核的掩码。 换句话说,Qt5相当于Posix线程的pthread_setaffin
我想通过以下方式将进程绑定(bind)到特定的核心#0(cpu 亲和性) taskset -c 0 ./run_prog 当它自己的程序在核心 #0 上运行时,操作系统可能会决定将其他后台和事件进程运
我刚刚发现了 Node.js 的worker_threads 模块,它看起来很有前途! 问题:将worker_threads与集群结合起来是否有趣/高效,或者创建的线程是否自动分布在机器的不同CPU上
我想测试在基于 64 位、2 CPU、16 核 Intel Xeon 5500 CPU 的服务器的不同物理 CPU 和不同嵌入式内存 Controller 分配和访问内存时可能发生的性能变化。 (戴尔
非常简单的问题 - 有没有办法通过 PHP 设置 CPU 亲和性?以下任何一项都可以: 通过 PHP 调用设置当前进程的亲和性。 通过 PHP 调用设置特定 PID 的亲和性。 作为最后的手段,通过命
我需要创建一个内核模块,在计算机的每个内核上启用 ARM PMU 计数器。我在设置 cpu 亲和性时遇到问题。我试过 sched_get_affinity,但显然,它只适用于用户空间进程。我的代码如下
我是一名优秀的程序员,十分优秀!