c# - 在 mysql/python 或 mysql/.net 中按子字符串对字符串进行分组

标签 c# python mysql

数据将像这样存储在mysql数据库中:

5911    CD  $4.99   Eben, Landscapes of Patmos {w.Martin Lenniger, percussion}; 2 Choral Phantasies; Laudes. (All w.Sieglinde Ahrens, organ)
5913    CD  $5.99   Turina, Sevilliana; Rafaga; Hommage a Tarrega; Sonata. Rodrigo, 3 Piezas Espanolas; En Los Trigales; Sarabande Lointaine. (Eric Hill, guitar^)
145460  CD  $13.98  Wagner, The Flying Dutchman. (Hans Hotter, Astrid Varnay, Set Svanholm et al. Cond. Reiner. Rec.1950. PLEASE NOTE: Limited-pressing CDRs)
145461  CD  $13.98  Montemezzi, L'Amore dei Tre Re. (Virgilio Lazzari, Dorothy Kirsten, Charles Kullman, Robert Weede, Leslie Chabay et al. Cond. Giuseppe Antonicelli. Rec. 1949. PLEASE NOTE: Limited-pressing CDRs)
145462  CD  $13.98  Ponchielli, La Gioconda. (Zinka Milanov, Giacomo Vaghi, Leonard Warren, Rise Stevens, Richard Tucker, Margaret Harshaw et al. Cond. Emil Cooper. Rec. 1946. PLEASE NOTE: Limited-pressing CDRs)
145465  CD  $5.99   ' Yankele: Yiddish Songs'. (16 titles incl. Az der Rebe, Rozhinkes mit Mandlekh, Shabes, Yankele, Belz, Di Grine Kuzine. Moshe Leiser, voice and guitar. Ami Flammer, violin. Gerard Barreaux, accordion. Rec. 'live', Lyon Opera. Total time: 78')
145467  CD  $4.99   Brahms, Piano Trios 2 & 3. (Trio Bamberg: Evgeny Schuk, violin; Stephan Gerlinghaus, cello. Robert Benz, piano. Rec. Nuremberg, 4/7/2000. Total time: 51'45')
145468  CD  $4.99   Gaubert, Piece Romantique; Trois Aquarelles. Debussy, Premier Trio in G. Francaix, Trio. (Trio Cantabile: Hans-Jorg Wegner, flute. Guido Larisch, cello. Christiane Kroeker, piano. Rec. Hannover, 3/2001. Total time: 62'35')
145469  CD  $4.99   Gattermeyer, Heinrich [b.1923]: Ophelias Schattentheater [text by Michael Ende]. Matthias Drude [b.1960], Jorinde und Joringel. Christoph J. Keller [b.1959], Die Kristallkugel [both texts by Brother Grimm]. (Helmut Thiele, narrator w.Bernd-Christian Schulze, piano. Total time: 68'08')
145470  CD  $2.99   Morrill, Dexter [b.1938]: Dance Bagatelles for Viola & Piano; Three Lyric Pieces for Violin and Piano [Laura Klugherz, viola & violin. Jill Timmons, piano]; Fantasy for Solo Cello [James Kirkwood, cello]; String Quartet #2 [Tremont String Quartet]. (Total time: 51'03')
145471  CD  $2.99   Werntz, Julia: String Trio with Homage to Chopin [Curtis Macomber, violin. Lois Martin, viola. Ted Mook, cello]; 'To You Strangers'- Five Poems of Dylan Thomas for Mezzo-Soprano Solo [Christina Ascher]; Piano Piece [John McDonald]. John Mallia, Lock [Stephanie Kay, clarinet]; Poor Denizens of Hell [chamber ensemble/ Daniel Hosken]; Plexus 2. (Aura Group for New Music)
145472  CD  $2.99   Morrill, Dexter [b.1938]- 'Music for Trumpets': 'Ponzo' for Two Trumpets; 'Nine Pieces' for Solo Trumpet; 'TARR' for Four Trumpets & Computer; 'Studies' for Trumpet & Computer; 'Trumpet Concerto' for Trumpet & Piano. (Mark Ponzo, trumpet with Barbara Butler [trumpet] & William Koehler, piano. Total time: 52'02')
145473  CD  $2.99   Kallstrom, Michael [b.1956]: 'Stories'. (A chamber opera for solo performer with puppets and electronic tape based on Old Testament stories)
145474  CD  $2.99   Carosio, Vailati, Lechi, Ponchielli, D'Alessandro, Sterzati, Riva, Pucci, Casazza, Denti, Gnaga, Anelli, Feroldi: 'The Mandolins of Stradivari'. (16 pieces for mandolin ensemble et al. Ugo Orlandi, mandolin. Alessandro Bono, guitar. Maura Mazzonetto, piano. Giampaolo Baldin, baritone. Quartetto romantico a plettro 'Umbert Sterzati'. Orchestra di Mandolini e Chitarre 'Citta di Brescia'/ Mandonico. Total time: 77'19')
145475  CD  $3.99   Rachmaninov, Symphony #3; Symphonic Dances. (St. Petersburg Philharmonic/ Jansons. Total time: 72'16')

我需要将每个标题与其他 4 个具有共同单词的标题分组。例如,如果我想将字符串中同时包含单词 BEETHOVEN 和 MOZART 的 4 张 CD 分组。

但是,我不想指定它应该按哪些词分组。我希望这能以某种人工智能的方式完成

我认为算法应该是这样的:

  1. 对所有词进行频率分布
  2. 扔掉英语中经常使用的任何单词(比如 if、or、the、of 我在哪里可以得到这些单词的列表)??
  3. 开始按出现次数最少的词分组

有谁知道对它进行分组的任何智能方法吗?

最佳答案

关于 (2),你想要的被称为“停用词”——例如,在 NLTK 中(这是 Python,但我想会有 C# 等价物),根据 chapter 2在其出色的在线书籍中,

>>> from nltk.corpus import stopwords
>>> stopwords.words('english')
['a', "a's", 'able', 'about', 'above', 'according', 'accordingly', 'across',
'actually', 'after', 'afterwards', 'again', 'against', "ain't", 'all', 'allow',
'allows', 'almost', 'alone', 'along', 'already', 'also', 'although', 'always',
 ...]

我引用的书也可以帮助您解决第 1 点,但第 3 点实际上是一个不同的领域——聚类。您想要一种非常特殊的聚类(指定且相同的聚类大小),因此现有算法可能不适合您,但根据您提到的内容设计一些算法并不难。

基本上,您希望每个单词都值得一个“分数”,对于英语中较少出现的单词来说,该分数更高(NLTK,或 C# 中任何同等强大的自然语言处理工具包,当然可以帮助您)——负例如,单词频率的对数可能是一个开始。

根据您提到的规范,您只需要对出现在至少五个文档中的不间断词进行评分,因此有意义的词的数量应该很少,并且穷举搜索甚至是可行的。

事实上,最大的问题可能是另一个问题——如果有一组少于 5 个文档,而这些文档加起来没有与其他文档有任何共同的不间断词怎么办?发生这种情况的可能性表明您必须在某些方面放宽规范(因为我对您的应用程序一无所知,所以我当然无法给出具体建议,但它可能是从允许文档数量不同于 5 的组,到放宽分组标准等)。

或者,您是否宁愿诊断出某些情况实际上不可能满足您的严格限制,并在发生时提供错误消息而不是任何结果?

关于c# - 在 mysql/python 或 mysql/.net 中按子字符串对字符串进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3518375/

相关文章:

c# - 线程调试窗口中没有显示任何线程

c# - 为什么我的 get/set 实现会出现堆栈错误?

c# - ASP.Net 中的客户端应用程序

mysql - 带有隐式默认值的警告 TIMESTAMP 已弃用

php - 使用nodeMCU在mysql中写入dht11传感器失败

Mysql触发器选择和删除

c# - 在设置文件中保存一些东西或..?在 C# 中

python - 无法理解 python 生成器

python - 优化分散

python - AWS Lambda + Python - 没有名为 pkg_resources 的模块