私は2つのテキストファイルを持っています。どちらも同じ内容ですが、それぞれの書式は異なります。 1つのファイルには、単語や文字の間に余分なスペースがあります。異なる改行もあります。たとえば:別のテキストファイルのあるテキストファイルから文字列に一致する文字列を検索するにはどうすればよいですか?
はFile1:
The annotation framework we presented is
embedded in the Knowledge Management and
Acquisition Platform Semantic Turkey (Pazienza, et
al., 2012), and comes out-the-box with a few
annotation families which differ in the underlying
annotation model and, notably, in the tasks they
support. The default handlers take into consideration
the annotation of atomic ontological resources, and
complex activities that are provided as macros, e.g.
the creation of new instances, the definition of new
subclasses in OWL, or of narrower concepts in
SKOS.
File2の:
Theannotationframework we presented is
embedded in th e K n o w l e d ge Management and
Acquisition Platform Semantic Turkey (Pazienza, et
al., 2012), and comes out-the-
box with a few
annotation families which differ in the underlying
annotation model and, notably, in the tasks they
support. The default handlers take into consideration
the a n n o t a t i o n o f a t o m i c ontological resources, and
complex activities that are provided as macros, e.g.
the creation of new instances, the definition of new
subclasses in OWL, or of narrower concepts in
SKOS.
は、私はファイル1から文字列the Knowledge Management
を選択して、私はFile2の中の文字列th e K n o w l e d ge Management
でそれを一致させたいとします。
どうすれば実現できますか? 2番目のファイルには固定された変形はありません。両方のファイルで文字が同じ順序であり、余分なスペースで区切られている可能性があります。間に余白があると保証できません。
私はSellers AlgorithmまたはViterbi Algorithmを適用することを考えましたが、わかりません。おおよその文字列マッチングは高価かもしれません。
任意の鉛が役立ちます。 ありがとう!
パターンマッチングアルゴリズムを本当に探しているなら、ラビンのKnuth-Morris-Pratt(最も難しいアルゴリズムの1つ)やBoyer-Mooresアルゴリズムを見てください。しかし、あなたの両方のファイルがすべて同じ文字を持っているので、ループで簡単に行うことができます –