首页 \ 问答 \ 字符串的模式匹配独立于符号(Pattern matching for strings independent from symbols)

字符串的模式匹配独立于符号(Pattern matching for strings independent from symbols)

我需要一种算法,它可以在数据中找到预定义的模式(以字符串的形式出现),与数据和模式的实际符号/字符无关。 我只关心符号之间的关系,而不是符号本身。 在数据中为同一符号设置不同的模式符号也是合法的。 模式匹配算法必须强制执行的唯一事情是保留模式中相同符号的多个出现。 举个例子:

模式是abca ,因此第一个和最后一个字母是相同的。 对于我的应用程序,写这个的等效方法是1 2 3 1 ,其中数字只是变量。 我拥有的数据是最好的 。 结果算法应该给我两个正确的匹配, 文本测试 。 因为只有在这两种情况下,第一个和第四个字母是相同的,就像在模式中一样。

作为第二个例子,模式abcd应该返回12个匹配(在thistextisat中每个位置一个)。 由于模式中没有变量重复,因此它无处不在。 即使在文本测试的情况下,因为模式的变量ad映射到相同的符号是合法的。

该算法的目标应该是检测书面语言的相似之处。 想象一下,有一本英语词典,并用看不见或等效的模式解析它1 2 3 4 4 2 。 然后你会看到,例如, belittle这个词包含相同的字母模式。

所以,既然我希望明确我需要什么,我有一些问题:

  • 这个算法叫什么? 这是一个已经解决的众所周知的问题吗?

  • 有关于此事的出版物吗? 当你不知道正确的搜索术语来将这个问题与常规模式匹配分开时,很难找到任何有用的东西。

  • 有没有现成的实现?

我没有使用Regex来处理任何太复杂的事情,所以我不知道在Regex中是否有这样的东西甚至是可能的,当你基本上不关心这些符号时,只考虑它们出现的模式。

我真的很感谢你的帮助!


I have need for an algorithm which can find pre-defined patterns in data (which is present in the form of strings) independent from the actual symbols/characters of the data and the pattern. I only care about the relations between the symbols, not the symbols themselves. It is also legal to have different pattern symbols for the same symbol in the data. The only thing the pattern matching algorithm has to enforce is that multiple occurences of the same symbol in the pattern are preserved. To give you an example:

The pattern is abca, so the first and the last letter are the same. For my application, an equivalent way to write this would be 1 2 3 1, where the digits are just variables. The data I have is thistextisatest. The resulting algorithm should give me two correct matches here, text and test. Because only in these two cases, the first and the fourth letter are the same, as in the pattern.

As a second example, the pattern abcd should return 12 matches (one for each position in thistextisat). Since no variable in the pattern is repeated, it is trivially matched everywhere. Even in the case of text and test, because it is legal that the variables a and d of the pattern map to the same symbol.

The goal of this algorithm should be to detect similarities in written language. Imagine having a dictionary of the English language and parsing it with the pattern unseen or equivalently 1 2 3 4 4 2. You would then see that, for example, the word belittle contains the same pattern of letters.

So, now that I hopefully made clear what I need, I have some questions:

  • What is this algorithm called? Is it a well-known problem that has been solved?

  • Are there publications on the matter? It is really hard to find anything useful when you don't know the correct search terms to separate this problem from regular pattern matching.

  • Is there a ready implementation of this?

I have not used Regex for anything too complicated, so I don't know if anything like this would even be possible in Regex, when you basically do not care about the symbols as such, but only consider the pattern of their occurences.

I'd really appreciate your help!


原文:https://stackoverflow.com/questions/29393638
更新时间:2021-04-11 12:04

最满意答案

更换

ss << "lynx -dump '" << siteurl << "'" > filename;

ss << "lynx -dump '" << siteurl << "'" << filename;

或者,与您的原始代码保持一致:

ss << "lynx -dump '" << siteurl << "' > " << filename;

Replace

ss << "lynx -dump '" << siteurl << "'" > filename;

with

ss << "lynx -dump '" << siteurl << "'" << filename;

or, to be consistent with your original code:

ss << "lynx -dump '" << siteurl << "' > " << filename;

相关问答

更多
  • newStr = (string_t*)malloc(sizeof(string_t)*2); 您为newStr分配内存,但不为newStr->line分配内存。 尝试以下方法: newStr = malloc(sizeof *newStr); newStr->line = malloc(s1->length + s2->length + 1); 旁注: *((newStr->line)+i)可以写成newStr->line[i] 。 newStr = (string_t*)malloc(sizeof( ...
  • 您不需要使用类名称为实例变量添加前缀,而是使用row或this->row 编辑: 最终,您将要将类声明移动到头文件,即。 position.h并将实现保存在position.cpp文件中,顶部是#include "position.h" 。 这将使您的Position类可用于其他文件。 You don't need to prefix instance variables using the class name, instead use row or this->row EDIT: Eventually ...
  • 更换 ss << "lynx -dump '" << siteurl << "'" > filename; 同 ss << "lynx -dump '" << siteurl << "'" << filename; 或者,与您的原始代码保持一致: ss << "lynx -dump '" << siteurl << "' > " << filename; Replace ss << "lynx -dump '" << siteurl << "'" > filename; with ss << "ly ...
  • 我能发现的主要内容:realloc可能无法将缓冲区保持在同一地址。 你应该用 l = realloc(...) 实际上,请参阅下面Matteo的评论。 Realloc可以做以下三件事之一: 扩展你已经拥有的缓冲区的大小(在这种情况下,你会得到相同的指针); 在其他地方分配一个新缓冲区,复制缓冲区的内容并释放原始内容(在这种情况下,你会得到一个不同的指针); 发现自己无法在任何地方找到所需大小的缓冲区并失败,使当前内容保持不变(返回NULL)。 在最后一种情况下,不检查返回值的赋值将导致内存泄漏。 The ...
  • 最常见的原因是: 脏构建(即接口已更改,但使用这些接口的对象未重建) 堆栈损坏(你在堆栈上覆盖了导致调用错误函数的东西和/或带有无效参数的正确函数) 尝试使用干净的重建进行修复,如果仍然发生,请尝试使用内存调试工具(如Valgrind)来查看覆盖堆栈的位置。 Most common causes for this are: Dirty build (i.e. interface changed, but objects that used those interfaces weren't rebuilt) ...
  • 这取决于您询问的问题类型。 我在这看到两个问题: 递归。 没有理由。 只需使用迭代。 范围溢出。 int type cant保持范围[0,100]内的所有Fibonacci数 这是在Python中使用迭代的fib实现的一个例子(仅仅因为它可以将fib(100)保持在盒子外面): In [16]: def fib(n): ....: curr, next = 0, 1 ....: for x in range(n): ....: curr, next = ne ...
  • void foo(Person &y) { y = new Person(); } y是引用,而不是指针。 要重新分配给你,你会使用 y = Person(); 但如果你真的想分配一个新人,你就可以使用 void foo(Person* &y) // reference to pointer to Person 通过引用,您基本上可以说您修改了调用站点的值。 请注意您当前的代码泄漏。 如果你有一个想要自己管理的裸指针,你必须先删除它: void foo (Person*& y) { d ...
  • typedef的一个问题是class Student是一个抽象类,因此它不能是默认构造的,这对于可以组成向量的类型是必需的。 另一个问题(比如说你删除了class Student是抽象的这个事实)可能是该类没有完全定义。 实际上,您可以为带有不完整类的vector<>声明一个typedef,但在完全定义类之前,您将无法实际使用typedef - 除非声明指针或对该类型的引用。 在这两种情况下,您可能需要考虑类的整体设计 - 您可能希望使用vector因此向量可以容纳任何类型的学生(使用指 ...
  • 如此处所述, std::priority_queue模板的签名是: template< class T, class Container = std::vector, class Compare = std::less > class priority_queue; 因此,您需要将基础容器指定为模板参数。 您不能依赖默认模板参数,因为您正在尝试指定比较器(第三个模板参数)。 此外,我不确定您指定比较器的方式是否正确...您可 ...
  • 以下测试程序演示了使用float和Float类之间的至少一个区别: void test(float x) { cout<<"Called with float argument"<

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)