从句子中提取艺术家和歌曲标题的技巧?(Techniques to extract artist and song title from a sentence?)

编程入门 行业动态 更新时间:2024-10-25 16:27:04
句子中提取艺术家和歌曲标题的技巧?(Techniques to extract artist and song title from a sentence?)

对于上下文,我要做的是创建一个小的webapp,您可以在其中粘贴Reddit讨论线程,并将线程中引用的歌曲名称转换为Spotify播放列表。

我试图找出一种从某种自然语言中提取艺术家/歌曲名称的方法,格式为“ artist - song name ”或“ songname by artist ”。

所以,例如,假设我有以下字符串:

The Funeral by the Band of Horses is my favorite song. you should check out the Acoustic version of Foo Fighters - Everlong. Eminem- Stan. Not a fan of rap but I like this song.

结果输出将是:

["The Funeral", "the Band of Horses"], ["Foo Fighters", "Everlong"], ["Eminem", "Stan"]

由于没有办法知道什么是艺术家,什么是没有API调用的歌曲,因此不需要以任何特定的方式存储,我只需要将艺术家和歌曲名称分成不同的数组部分。

这可能没有任何分隔符来表示歌曲名称的结尾吗?

这是我到目前为止的...(半伪代码):

delimiters = [" - ", "-", " by ",]; strings = [ "The Funeral by the Band of Horses is my favorite song.", "you should check out the Acoustic version of Foo Fighters - Everlong.", "Eminem- Stan. Not a fan of rap but I like this song." ]; // loop over each string for (var i=0; i<strings.length; i++ ) { // loop through each delimiter possibility for (var d=0; d<delimiters.length; d++) { if ( strings[i].indexOf(delimiters[d]) > -1 ) { // we have a delimiter match // now figure out how to get the stuff on either side... } } }

For context, what I'm trying to do is make a small webapp in which you can paste a Reddit discussion thread, and have song names referenced in the thread converted into a Spotify playlist.

I'm trying to figure out a way to extract artists/song names from some natural language, in the format of of "artist - song name" or "songname by artist" .

So, for example, say I had the following strings:

The Funeral by the Band of Horses is my favorite song. you should check out the Acoustic version of Foo Fighters - Everlong. Eminem- Stan. Not a fan of rap but I like this song.

the resulting output would be:

["The Funeral", "the Band of Horses"], ["Foo Fighters", "Everlong"], ["Eminem", "Stan"]

Since there's no way to know what is an artist vs. what is a song without an API call, they don't need to be stored in any particular manner, I just need the artist and song name broken into different array parts.

Is this possible to do without any sort of delimiter to indicate the end of a song name?

Here's what I have so far... (semi-pseudo-code):

delimiters = [" - ", "-", " by ",]; strings = [ "The Funeral by the Band of Horses is my favorite song.", "you should check out the Acoustic version of Foo Fighters - Everlong.", "Eminem- Stan. Not a fan of rap but I like this song." ]; // loop over each string for (var i=0; i<strings.length; i++ ) { // loop through each delimiter possibility for (var d=0; d<delimiters.length; d++) { if ( strings[i].indexOf(delimiters[d]) > -1 ) { // we have a delimiter match // now figure out how to get the stuff on either side... } } }

最满意答案

有一个有趣的文本解析库: Knwl.js 。 Knwl.js似乎没有用于解析艺术家或歌曲的插件,但它似乎应该很容易实现。 请参阅: 插件开发

There is an interesting library for text parsing: Knwl.js. Knwl.js doesn't seem to have a plugin for parsing artists or songs, but it seems it should be easy to implement. See: plugin development

更多推荐

本文发布于:2023-07-28 23:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:句子   艺术家   标题   技巧   歌曲

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!