私は次のような問題を解決しています:文字列解析とマッチングアルゴリズム
は、私はこの(のみ知られているものは、これらの名前がSOMETHING + VERSION
状に形成されていることであるように、ソフトウェアパッケージとその名前のリストが見えるかもしれないがあると、バージョンは常に)名前後に来ることを意味:
Efficient.Exclusive.Zip.Archiver-PROPER.v.122.24-EXTENDED
Efficient.Exclusive.Zip.Archiver.123.01
Efficient-Exclusive.Zip.Archiver(2011)-126.24-X
Zip.Archiver14.06
Zip-Archiver.v15.08-T
Custom.Zip.Archiver1.08
Custom.Zip.Archiver1
は今、私はこのリストを解析し、のみ最新バージョンを選択する必要があります各パッケージの。この例では期待される結果は次のようになります。
Efficient-Exclusive.Zip.Archiver(2011)-126.24-X
Zip-Archiver.v15.08-T
Custom.Zip.Archiver1.08
私が使用して現在のアプローチは、次のように説明することができます:
Split the initial strings into groups by their starting letter,
ignoring spaces, case and special symbols.
(`E`, `Z`, `C` for the example list above)
Foreach element {
Apply the regular expression (or a set of regular expressions),
which tries to deduce the version from the string and perform
the following conversion `STRING -> (VERSION, STRING_BEFORE_VERSION)`
// Example for this step:
// 'Efficient.Exclusive.Zip.Archiver-PROPER.v.122.24-EXTENDED' ->
// (122.24, Efficient.Exclusive.Zip.Archiver-PROPER)
Search through the corresponding group (in this example - the 'E' group)
and find every other strings, which starts from the 'STRING_BEFORE_VERSION' or
from it's significant part. This comparison is performed in ignore-case and
ignore-special-symbols mode.
// The matches for this step:
// Efficient.Exclusive.Zip.Archiver-PROPER, {122.24}
// Efficient.Exclusive.Zip.Archiver, {123.01}
// Efficient-Exclusive.Zip.Archiver, {126.24, 2011}
// The last one will get picked, because year is ignored.
Get the possible version from each match, ***pick the latest, yield that match.***
Remove every possible match (including the initial element) from the list.
}
このアルゴリズムは、(私は仮定として)のようなもののために働く必要がありますO(N * V + N lg N * M)
ここで、M
は平均文字列一致時間を表し、V
はバージョンregexpの作業時間を表します。
はしかし、私はよりよい解決策は多分、特定のデータ構造またはより良いマッチングアプローチは、(常にある!)があると思います。あなたが何かを提案できるかは、現在のアプローチにいくつかのメモを作る場合
は、これを実行することを躊躇しないでください。
おそらく、最も長い共通部分文字列を見つけることは役に立ちますか? http://en.wikipedia.org/wiki/Longest_common_substring_problem SOやその他のWebサイトでは、多くのディスカッションや実装を見つけることができます。 –
@ Jim最も長い共通部分文字列の問題は、2つの文字列の比較に役立ちますが、実行する比較の数を最適化することはできません。 OPはすでに2つのパッケージが等しいかどうかを判断する方法を知っていて、ある種のクラスタリングを使用してこれをより高速に実行したいと思っていることを理解しています。 – aKzenT
実行時の分析が間違っています:範囲(アルファベット)が限られている最初の文字のみに基づいてグループ化しているため、O(N^2)でO(N log N)同じグループ内の他のすべてのエントリへのすべてのエントリ。 – aKzenT