如何使用progress4gl中的ENTRY函数从两个不同的句子中获取常用词



如何利用progress4gl中的ENTRY函数从两个不同的句子中获取常用词?

 define variable a1 as character  no-undo  initial  "hi dude do". 
 define variable a2 as character  no-undo  initial  "hi man it". 
 define variable cnta as character.
 define variable cntb as character.
 define variable cntc as character.
 define variable i as integer.
 define variable j as integer.
 do i = 1 to 3:
 entry (i,a1,"").
   do  j = 1 to 3:
    entry (j,a2,"").
  end.
 end.
/*   assign cntc = cnta matches cntb . */
define variable a1 as character  no-undo  initial  "hi dude do". 
define variable a2 as character  no-undo  initial  "hi man it". 
define variable common as character no-undo.
define variable cc as integer no-undo.
define variable ii as integer no-undo.
define variable jj as integer no-undo.
define variable n1 as integer no-undo.
define variable n2 as integer no-undo.
n1 = num-entries( a1 ).
n2 = num-entries( a2 ).
do ii = 1 to n1:
    do  jj = 1 to n2:
      if entry ( ii, a1, " ") = entry( jj, a2, " " ) then
        do:
          cc = cc + 1.
          common = common + " " + entry( ii, a1, " " ).
        end.
    end.
end.
display trim( cc ) common.

指出:

TRIM()函数只是清理"公共"字符串,使其没有额外的空间。

出于性能原因,最好养成在循环外部获取NUM-ENTRIES()的习惯,而不是在每次循环迭代时获取NUM-ENTRIES()。这对小弦没有太大影响,但对大弦却有很大影响。

1。/*如果我需要在运行时从用户那里获得两个句子中的n个单词,如何比较并获得常见单词。

下面的代码比较并只显示两个句子的第一个字母。*/

define variable a1 as character  no-undo.
define variable a2 as character  no-undo.
define variable common as character no-undo.
define variable a1 as character FORMAT "x(64)" no-undo  /* initial  "hi d do" */. 
define variable a2 as character FORMAT "x(64)" no-undo  /* initial  "hi d it" */. 
define variable common as character FORMAT "x(64)" no-undo.
define variable c1 as character FORMAT "x(64)" no-undo.
 define variable x as character FORMAT "x(64)" no-undo.
 define variable y as character FORMAT "x(64)" no-undo.
define variable cc as integer no-undo initial 0.
define variable ii as integer no-undo.
define variable jj as integer no-undo.
define variable n1 as integer no-undo.
define variable n2 as integer no-undo.

set a1. 
n1 = num-entries( a1,"" ).

set a2. 
n2 = num-entries( a2,"" ).
do ii = 1 to n1:

   do  jj = 1 to n2:
   if entry ( ii,a1, " ") matches entry( jj,a2, " " ) then
   do:
     common = entry( ii, a1, " " ).
     display  common .     
   end.
   end.
end.

最新更新