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

时间:2016-11-14 09:27:21

标签: progress-4gl openedge

如何在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 . */

2 个答案:

答案 0 :(得分:1)

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()的习惯是好的,而不是循环的每次迭代。它对于小字符串没有太大的区别,但对于大字符串,它可能会产生很大的影响。

答案 1 :(得分:-2)

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.