Compare multiple lists of records to find matching sequenced items

Hi i’m looking for suggestions on how to compare multiple lists
and find recurring sequences in the lists.

This for my DJ history playlists, wanting to find song sequencing
combos that I use over and over.

each list item would contain records of the following:

  • list index
  • track name
  • artist name
  • genre

{playlistINDEX:1, track:“Miss You”, artist:“Rolling Stones”, genre:“Classic Rock”}

I would like to be able to assign ranking values based on:

  1. the number of times a match is found
  2. the depth of the match index wise
    for the depth I’ll probably just start with a index depth -1,1 to start
    (before and after)… but eventually would probably like to extend it
    up to even -5,5 (does the match come within 5 items before or after)
  3. a combo ranking based on the match count x the depth
    (the more times it is closer, the higher the ranking)

From here I would like to possibly be able to do the following:

  1. create a new master list based on all the lists, grouping duplicate
    items based on their rankings from above, also having the duplicates
    only appear once. Trying to maintain somewhat of the same order as the original lists
  2. create sublists, with each sublist only containing matched genre values,
    and then creating as above
  3. enter the name of a track (or select from a list) and then provide suggestions
    of songs to play that would match based on the rankings.

suggestions?

thanks

I don’t have time to code this… and I would’t get my hopes up for someone else here to volunteer coding it, as I believe the time commitment is non-trivial.

To find arbitrary repetitions in strings, you build a suffix tree:

https://en.wikipedia.org/wiki/Suffix_tree

Here’s a more intelligible explanation of that:

https://stackoverflow.com/questions/9452701/ukkonens-suffix-tree-algorithm-in-plain-english/9513423#9513423

Then once you have a suffix tree, finding the repetitions is not difficult:

https://en.wikipedia.org/wiki/Longest_repeated_substring_problem

I don’t think you’re likely to find an existing Applescript handler for generating the Suffix Tree, and coding it would take a bit.

On the other hand, you certainly can find an existing library for generating the suffix tree in another language you can call from Applescript. If you convert your data to a string before sending it in, then you could us a “do shell script” and run an existing PERL or Python library to generate the suffix tree, write additional PERL/Python code to spit out the results you want, and return that to Applescript.

https://github.com/kvh/Python-Suffix-Tree

Or you might be able to use an Objective C Suffix Tree implementation and ASObjC:

https://github.com/jasonhotsauce/suffixtree

Best of luck with it.

I’ve been doing a bit of reading about asOBJc indexing.
If anyone could provide some example or insight into using these would appreciate it.

here’s some things I think will help me from :

https://developer.apple.com/documentation/foundation/indexpath
var lazy: LazySequence
A sequence containing the same elements as this sequence, but on which some operations, such as map and filter, are implemented lazily.

func appending(Array<IndexPath.Element>) → IndexPath
Returns a new index path containing the elements of this one plus an array of additional elements.

func elementsEqual(OtherSequence) → Bool
Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.

func starts(with: PossiblePrefix) → Bool
Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

var lazy: LazySequence
A sequence containing the same elements as this sequence, but on which some operations, such as map and filter, are implemented lazily.

func elementsEqual(OtherSequence, by: (Int, OtherSequence.Element) → Bool) → Bool
Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements in the same order, using the given predicate as the equivalence test.

func map((Int) → T) → [T]
Returns an array containing the results of mapping the given closure over the sequence’s elements.

func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Int) → Bool) → [IndexPath]
Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.

func split(separator: Int, maxSplits: Int, omittingEmptySubsequences: Bool) → [IndexPath]
Returns the longest possible subsequences of the collection, in order, around elements equal to the given element.

any tutorials on using these?

thanks

Kerry

AppleScriptObjC, as its name implies, is a bridge to using Objective-C classes and methods. What you’re looking at there is the documentation for a Swift structure that is an overlay of the NSIndexPath class. Basically, you can’t use any of it.

And if you could, I don’t think it’s what you’re looking for.

thanks for the info on Suffix_Tree. I think I came come up with a way to implement this

So far I’ve taken my lists and have assigned each list item contains:

  • playlistINDEX number (which playlist it is in)
  • sequenceINDEX number (the position in the playlist)
  • entryNAME
  • entryARTIST

I’ve then go thru every entry from each playlist and create possible combos
grouping by 2, with a max depth of 5 and placed these into these groups lists

  • group10 (current entry alone - not a combo but just every entry)
  • group11 (current entry and the next entry)
  • group12 (currrent entry and the +2 next entry)
    etc
  • group15 (current entry and the +5 next entry)

Then using functions i’ve found in the forums for counted sets and ordering.
I’m able to built lists of the possible combos that appear more than 1 time.
From here I this info i believe it can help me create the Tree as I’ll know when there
are duplicates (ability to connect branches between playlists).
Unfortunately I’m realizing now that in the end the final playlist in iTunes or Traktor will only
be able to show a list that has a flat structure with no branches. But maybe this is a good
opportunity to have an external Applescript that would allow me to take the current song
and show me the next most “popular” 5 songs from my history.

more soon