对于上下文,我要做的是创建一个小的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
更多推荐
发布评论