编程语言
首页 > 编程语言> > CYK算法伪代码混淆

CYK算法伪代码混淆

作者:互联网

因此我一直在Wikipedia和许多Powerpoint / pdf中阅读有关CYK algorithm的信息.

在Wikipedia中,有一部分我不是100%想要说的话.你们能帮我分解一下吗?

let the input be a string S consisting of n characters: a1 ... an.
let the grammar contain r nonterminal symbols R1 ... Rr.
This grammar contains the subset Rs which is the set of start symbols.
let P[n,n,r] be an array of booleans. Initialize all elements of P to false.
for each i = 1 to n
  for each unit production Rj -> ai
     set P[i,1,j] = true

for each i = 2 to n -- Length of span
 for each j = 1 to n-i+1 -- Start of span
  for each k = 1 to i-1 -- Partition of span
   for each production RA -> RB RC
    if P[j,k,B] and P[j+k,i-k,C] then set P[j,i,A] = true

if any of P[1,n,x] is true (x is iterated over the set s, where s are all the indices for Rs) then S is member of language
  else
S is not member of language

真正令我困惑的部分是“如果P [1,n,x]中的任何一个为真(x在集合s上迭代,其中s是Rs的所有索引),那么S是语言的成员
  其他
S不是语言成员”

是说存在的n和x是否为真,则它是成员?
还是说字符串长度为n和x,如果为真,则为成员?还是完全不同的东西?

X到底是什么?

编辑:

谢谢大家,我肯定已经学会了如何做.
希望我能同时得到您的答案作为选定答案.

解决方法:

在执行CYK算法时,基本上是从底部到最上层元素填充底部三角形矩阵.每当其中j是列索引,i是行索引且x是非终结符的某些元素(j,i,x)为true时,这意味着您可以生成j的子序列j i-1您从符号Rx中得到的单词.

您的目标是从一个起始符号中生成整个单词.与生成整个单词的可能性相对应的元素是(1,n,x)-矩阵的最左边和最上面的元素,其中x是非终结符的索引.由于必须从一个起始符号开始,因此您正在寻找的只是所有非终端的子集-的子集.如果您设法从一个起始符号中生成整个单词,则只需声明该单词是语言的一部分即可.如果不存在这样的开始符号,则您将无法生成该单词,并且该单词不是语法描述的语言的一部分.

标签:context-free-grammar,java,algorithm,cyk
来源: https://codeday.me/bug/20191031/1974672.html