Re: What is Best Method To Determine Duplicate Items in a Large List?
Re: What is Best Method To Determine Duplicate Items in a Large List?
- Subject: Re: What is Best Method To Determine Duplicate Items in a Large List?
- From: Jim Underwood <email@hidden>
- Date: Tue, 15 Aug 2017 02:43:00 +0000
- Thread-topic: What is Best Method To Determine Duplicate Items in a Large List?
Shane, thanks again. Your help is greatly appreciated.
Please see below for my replies/questions to your last post.
Best Regards,
Jim Underwood
aka JMichaelTX
From: Shane Stanley
<email@hidden<mailto:email@hidden>>
Date: Monday, August 14, 2017 at 7:36 PM
To: "ASUL (AppleScript)"
<email@hidden<mailto:email@hidden>>
Subject: Re: What is Best Method To Determine Duplicate Items in a Large List?
So, how do we sort IndexInfo on item 2?
The simplest way would be to change the order so it's first or last -- then
your sort key would firstItem or lastItem.
OK, I like that idea, but I don't see how to implement it. The current sort is
just on the dup items without the indexes:
set duplicatedValues to countedDupes's allObjects()'s
sortedArrayUsingSelector:"compare:"
What do I need to change for this option?
There's no direct way to sort based on index (other than BridgePlus's
subarraysIn:sortedByIndexes:ascending:sortTypes:error:).
I like this also, since I'm already using BP. This seems to work. Can you
please confirm:
REVERT to this:
set duplicatedValues to countedDupes's allObjects()
ADD this at end of script:
set dupItemList to BPLib's sublistsIn:dupItemList sortedByIndexes:{2}
ascending:{true} sortTypes:{}
where dupItemList is your indexInfo
Here's my complete revised test script using BPLib:
________________________________
use AppleScript version "2.5" -- El Capitan 10.11.6+
use scripting additions
use framework "Foundation"
use BPLib : script "BridgePlus"
### code to get titleList from Evernote
set {dupNoteList, dupNoteCount} to my getDupItemList(titleList)
on getDupItemList(pSourceList)
(* VER: 1.2 2017-08-14
---------------------------------------------------------------------------------
PURPOSE: Get a List of Dup Items, with indexes, found in Source List
PARAMETERS:
• pSourceList ║ text ║ Source List to search for duplicate items (exact
match)
RETURNS: List of Lists ║ Each Item in main list is list with these items:
• text ║ Source items which had dups
• integer ║ Index of first item in Source List
• integer ║ Index of second item in Source List
• [integer ║ additional items for each dup found, one item per
dup]
AUTHOR: JMichaelTX refactored script by Shane Stanley
REQUIRES:
• macOS 10.11.6+
• use framework "Foundation"
REF:
1. Shane Stanley, 2017-08-13
http://lists.apple.com/archives/applescript-users/2017/Aug/msg00053.html
—————————————————————————————————————————————————————————————————————————————————
*)
¬
local time1, theCount, countedDupes, duplicatedValues, dupItemList,
thisValue, thisIndex, thisInfo, time2, elapTime, dupItemCount, msgStr,
msgTitleStr
set startTime to current application's NSDate's |date|()
set pSourceList to current application's NSArray's arrayWithArray:pSourceList
set theCount to pSourceList's |count|()
-- get a counted set of the duplicate instances of any duplicated values
set countedDupes to current application's NSCountedSet's
setWithArray:pSourceList
countedDupes's minusSet:(current application's NSSet's
setWithSet:countedDupes)
-- get the indices of the duplicated values' first and dupe instances
-- REVERT TO THIS:
set duplicatedValues to countedDupes's allObjects()
--- OPTION to Sort by Item Name/Title ---
-- Now replaced by BPLib sort at bottom
-- set duplicatedValues to countedDupes's allObjects()'s
sortedArrayUsingSelector:"compare:"
set dupItemList to {}
repeat with thisValue in duplicatedValues
-- Value and first index.
set thisIndex to (pSourceList's indexOfObject:(thisValue)) + 1
set thisInfo to {thisValue as text, thisIndex}
-- Indices of dupes.
repeat (countedDupes's countForObject:(thisValue)) times
set thisIndex to (pSourceList's indexOfObject:(thisValue)
inRange:({thisIndex, theCount - thisIndex})) + 1
set end of thisInfo to thisIndex
end repeat
set end of dupItemList to thisInfo
end repeat
### ADD BPLib SORT of RESULTS ###
set dupItemList to BPLib's sublistsIn:dupItemList sortedByIndexes:{2}
ascending:{true} sortTypes:{}
set elapTime to (-(round ((startTime's timeIntervalSinceNow()) * 100)) /
100.0)
set dupItemCount to count of dupItemList
set msgStr to ((dupItemCount as text) & " Dup Items found in " & elapTime as
text) & " sec"
set msgTitleStr to "getDupItems() Handler"
display notification msgStr with title msgTitleStr sound name "Tink.aiff"
return {dupItemList, dupItemCount}
end getDupItemList
--~~~~~~~~~~~~~~~ END OF handler getDupItemList ~~~~~~~~~~~~~~~~~~~~~~~~~
________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden