0

毎回 2 つの文を取り、それらが類似しているかどうかを計算することになっています。同様に、構文的にも意味的にも意味があります。

INPUT1: オバマは法律に署名します。新しい法律がオバマによって署名されました。

INPUT2: バスはここで停止します。ここに車が停車します。

INPUT3: NYで火事。NY全焼。

INPUT4: NYで火事。NY火災で50人死亡。

オントロジーツリーを魂として使いたくありません。文間のレーベンシュタイン距離(LD) を計算し、2 番目の文かどうかを判断するコードを作成しました。

  • 無視できます (INPUT1 および 2)。
  • 最初の文を置き換える必要があります (入力 3)、または
  • 最初の文 (INPUT4) と共に保存します。

LD は構文レベルのみを計算するため、コードに満足していません (他にどのような方法がありますか?)。セマンティックをどのように組み込むことができますか (バスは一種の乗り物ですか?) .

コードは次のとおりです。

%# As the difference is computed, a decision is made on the new event
%# (string 2) to be ignored, to replace existing event (string 1) or to be
%# stored separately. The higher the LD metric, the higher the difference
%# between two strings. Of course, lower difference indices either identical
%# or similar events. However, the higher difference indicates the new event
%# as a fresh event.

%#.........................................................................
%# Calculating the LD between two strings of events.
%#.........................................................................
L1=length(str1)+1;
L2=length(str2)+1;
L=zeros(L1,L2);   %# Initializing the new length.

g=+1;             %# just constant
m=+0;             %# match is cheaper, we seek to minimize
d=+1;             %# not-a-match is more costly.

% do BC's
L(:,1)=([0:L1-1]*g)';
L(1,:)=[0:L2-1]*g;

m4=0;             %# loop invariant
%# Calculating required edits.
for idx=2:L1;
    for idy=2:L2
        if(str1(idx-1)==str2(idy-1))
            score=m;
        else
            score=d;
        end
        m1=L(idx-1,idy-1) + score;
        m2=L(idx-1,idy) + g;
        m3=L(idx,idy-1) + g;
        L(idx,idy)=min(m1,min(m2,m3)); % only minimum edits allowed.
    end
end
%# The LD between two strings.
D=L(L1,L2);

%#....................................................................
%# Making decision on what to do with the new event (string 2).
%#...................................................................
if (D<=4)     %# Distance is so less that string 2 seems identical to string 1.
    store=str1;        %# Hence string 2 is ignored. String 1 remains stored.
elseif (D>=5 && D<=15) %# Distance is larger to be identical but not enough to
    %# make string 2 an individual event.
    store= str2;       %# String 2 is somewhat similar to string 1.
                       %# So, string 1 is replaced with string 2 and stored.
else
    %# For all other distances, string 2 is stored along with string 1.
    store={str1; str2};
end

どんな助けでも大歓迎です。

4

1 に答える 1

2

「意味的に」。そのための単純な教科書のアルゴリズムはありません。自然言語 (特に英語) は非常に複雑で気まぐれです。提供されているケース (ほんの一部) を見てみましょう。

INPUT1: Obama signs the law. A new law is signed by Obama.

法律に署名すると、それは「新しい」法律になります。

INPUT2: A Bus is stopped here. A vehicle stops here.

バスは、車両の種類であり、ある種の時間関係であることを知る必要があります。また、停車したバス正常に停車しない、停車しなくなった場合は?それはいくつかの方法で取ることができます。

INPUT3: Fire in NY. NY is burnt down.

火事は物を焼き尽くす可能性があることを知っておく必要があります。

INPUT4: Fire in NY. 50 died in NY fire.

火災は物を殺す可能性があることを知っておく必要があります (次を参照)。「ニュースの見出し」(50 WHAT?) を人々に関連付ける必要があります。脳はこれをやや簡単に行うことができます。コンピュータプログラムは頭脳ではありません。

そして、私は英語専攻ではありません:-)

于 2010-09-07T22:21:26.307 に答える