RE: return string that is the difference between two other strings

2014-09-21 Thread Lee Ann Rucker
On 21 Sep 2014, at 13:03, Kyle Sluder  wrote:

>
>> No, it is nowhere near a common operation to perform on strings.


>I stand corrected on that front, then (apparently...). Doesn't change the fact 
>that I need to know how to do it, unless someone is willing to  point me in 
>the direction of a better way, for which I'd be most grateful.

>> It’s common for *programmers* to perform on their source code.
>

>I've no idea what this means. Is it a cryptic answer to the problem, or a dig 
>at my level of experience?

No, it's saying that while the people on this list - you included - may need 
the results of the operation frequently enough that it's a standard developer 
tool, it's not something that most of us ever need to add to the programs we 
write for non-programmers to use. It's a very specialised operation; the more 
you look into it, the more complicated it gets. Try getting a source-code diff 
tool to understand that you've moved an entire function, for instance.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-21 Thread Jens Alfke

> On Sep 20, 2014, at 11:45 PM, Allan Odgaard  
> wrote:
> 
> If you need a C API then have a look at 
> https://code.google.com/p/google-diff-match-patch/ 
> 
This^^ looks like exactly what you want, 2551. The online demo is quite 
impressive:

https://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html
It compares on a character-by-character basis, not just by line, and the output 
shows the individual insertions/deletions/changes inline.

(I'm actually going to bookmark this myself; I have a side project that could 
make use of it!)

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Diederik Meijer | Ten Horses
Note that there are two differences, I would want to know: where string A says 
"this", string B says "that." So you have both "this" and 'that" for a 
difference. A lot of times, pre-optimizing your strings helps, meaning you 
first take out punctuation (mostly comma's) and remember where to put them back 
in. Also splitting may sometimes need NSRegularExpression instead of 
ComponentsSeparatedByString to be better. In general pre-optimizing is a 
necessity. In my experience, customizing a workplan between pre-optimizing and 
comparison/search based on the actual content gives the best results. It's more 
time-consuming though...

Verstuurd vanaf mijn iPhone

> Op 21 sep. 2014 om 08:42 heeft 2551 <2551p...@gmail.com> het volgende 
> geschreven:
> 
> 
>> On 21 Sep 2014, at 13:38, Diederik Meijer | Ten Horses 
>>  wrote:
>> 
>> Meaning I would compare words and their index in an array of words created 
>> from the two strings.
> 
> Thanks, Diederik. That's exactly the approach I took by using 
> NSMutableArray's -removeObject. 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/diederik%40tenhorses.com
> 
> This email sent to diede...@tenhorses.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551
On 21 Sep 2014, at 13:45, Allan Odgaard  wrote:
> One solution is the UNIX diff command  which, as Jens 
> previously mentioned, works on lines and is commonly used by version control 
> systems and programmers. You can call out to this command from Cocoa (e.g. 
> via NSTask).
> 


Thanks, Allan, for putting the 2 and 2 together for me. I didn't occur to me 
call diff from NSTask.

An excellent idea I'll play with later today. Thanks again.





signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Allan Odgaard

On 21 Sep 2014, at 6:08, 2551 wrote:

As I've been saying all along, this is such a common operation, I'd 
have thought there must be a common cocoa method or API for doing it. 
So the question is, can anyone tell me what that is?


The general problem you’re dealing with is that of finding the longest 
common subsequence. This is a difficult problem so it is often solved 
with heuristics. Wikipedia: 
http://en.wikipedia.org/wiki/Longest_common_subsequence_problem


One solution is the UNIX diff command  which, as 
Jens previously mentioned, works on lines and is commonly used by 
version control systems and programmers. You can call out to this 
command from Cocoa (e.g. via NSTask).


You can read about the implementation here 
http://www.xmailserver.org/diff2.pdf


An attempt of improving the quality of this command (for source code 
diff’ing) exists: http://alfedenzo.livejournal.com/170301.html


If you need a C API then have a look at 
https://code.google.com/p/google-diff-match-patch/

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551
On 21 Sep 2014, at 13:03, Kyle Sluder  wrote:

> 
> No, it is nowhere near a common operation to perform on strings.


I stand corrected on that front, then (apparently...). Doesn't change the fact 
that I need to know how to do it, unless someone is willing to  point me in the 
direction of a better way, for which I'd be most grateful.

> It’s common for *programmers* to perform on their source code.
> 

I've no idea what this means. Is it a cryptic answer to the problem, or a dig 
at my level of experience? 


signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551

On 21 Sep 2014, at 13:38, Diederik Meijer | Ten Horses  
wrote:

> Meaning I would compare words and their index in an array of words created 
> from the two strings. 

Thanks, Diederik. That's exactly the approach I took by using NSMutableArray's 
-removeObject. 


signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Diederik Meijer | Ten Horses
Meaning I would compare words and their index in an array of words created from 
the two strings. The first mismatch is easily found, but the tricky part is 
finding the last one. Here a context driven comparison may help. Instead of 
comparing word N in both strings, you compare words N and N-1, taking into 
consideration the number of extra words found in previous iterations. I have 
not tested this specific case, but can tell you context driven may help. All 
depends on whether you need the actual difference returned. If not, life is 
easy :-)

Verstuurd vanaf mijn iPhone

> Op 21 sep. 2014 om 08:24 heeft Diederik Meijer | Ten Horses 
>  het volgende geschreven:
> 
> I do a lot of text data mining and need similar functions a lot. I would 
> start on a word by word level, to have whatever it returns be more meaningfull
> 
> Verstuurd vanaf mijn iPhone
> 
>>> Op 20 sep. 2014 om 19:43 heeft Scott Ribe  het 
>>> volgende geschreven:
>>> 
>>> On Sep 20, 2014, at 11:13 AM, 2551 <2551p...@gmail.com> wrote:
>>> 
>>> For example:
>>> 
>>> NSString *mary = @"mary had a little lamb, a little lamb she had";
>>>  NSString *scary = @"mary had a little lamb, a little naughty fella of a 
>>> lamb she had for sure";
>>>  NSString *isDifferent = [self getDifference:mary and: scary];
>>>  NSLog(@"%@", isDifferent);
>>> 
>>> The method I posted below produces the difference that I want ("naughty 
>>> fella of a for sure"). But I want to know if there's a more orthodox and 
>>> robust solution.
>> 
>> That's not even remotely close to a definition of what you mean. What about:
>> 
>> @"mary had a little lamb, a little naughty lamb she had"
>> 
>> vs
>> 
>> @"mary had a little lamb, a little fella of a lamb she had for sure"
>> 
>> ?
>> 
>> Or:
>> 
>> @"mary had a little lamb, a naughty little lamb she had"
>> 
>> vs
>> 
>> @"mary had a big lamb, a little fella of a lamb she had for sure"
>> 
>> There is no simple definition of "the difference between two strings", and I 
>> don't think it's a basic need at all.
>> 
>> -- 
>> Scott Ribe
>> scott_r...@elevated-dev.com
>> http://www.elevated-dev.com/
>> (303) 722-0567 voice
>> 
>> 
>> 
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/diederik%40tenhorses.com
>> 
>> This email sent to diede...@tenhorses.com
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/diederik%40tenhorses.com
> 
> This email sent to diede...@tenhorses.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Diederik Meijer | Ten Horses
I do a lot of text data mining and need similar functions a lot. I would start 
on a word by word level, to have whatever it returns be more meaningfull

Verstuurd vanaf mijn iPhone

> Op 20 sep. 2014 om 19:43 heeft Scott Ribe  het 
> volgende geschreven:
> 
>> On Sep 20, 2014, at 11:13 AM, 2551 <2551p...@gmail.com> wrote:
>> 
>> For example:
>> 
>>  NSString *mary = @"mary had a little lamb, a little lamb she had";
>>   NSString *scary = @"mary had a little lamb, a little naughty fella of a 
>> lamb she had for sure";
>>   NSString *isDifferent = [self getDifference:mary and: scary];
>>   NSLog(@"%@", isDifferent);
>> 
>> The method I posted below produces the difference that I want ("naughty 
>> fella of a for sure"). But I want to know if there's a more orthodox and 
>> robust solution.
> 
> That's not even remotely close to a definition of what you mean. What about:
> 
> @"mary had a little lamb, a little naughty lamb she had"
> 
> vs
> 
> @"mary had a little lamb, a little fella of a lamb she had for sure"
> 
> ?
> 
> Or:
> 
> @"mary had a little lamb, a naughty little lamb she had"
> 
> vs
> 
> @"mary had a big lamb, a little fella of a lamb she had for sure"
> 
> There is no simple definition of "the difference between two strings", and I 
> don't think it's a basic need at all.
> 
> -- 
> Scott Ribe
> scott_r...@elevated-dev.com
> http://www.elevated-dev.com/
> (303) 722-0567 voice
> 
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/diederik%40tenhorses.com
> 
> This email sent to diede...@tenhorses.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Kyle Sluder
On Sep 20, 2014, at 9:08 PM, 2551 <2551p...@gmail.com> wrote:
> 
> As I've been saying all along, this is such a common operation, I'd have 
> thought there must be a common cocoa method or API for doing it. So the 
> question is, can anyone tell me what that is?

No, it is nowhere near a common operation to perform on strings. It’s common 
for *programmers* to perform on their source code.

--Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551
On 21 Sep 2014, at 10:58, Jens Alfke  wrote:

> What I'd want is something that shows the combined text with the deleted 
> words crossed out and the new words highlighted.

Thanks, Jens. You've hit the nail on the head. That's exactly what I want to 
achieve. I said order didn't matter because I figured that was a problem to 
sort out once I'd got the differences. 

As I've been saying all along, this is such a common operation, I'd have 
thought there must be a common cocoa method or API for doing it. So the 
question is, can anyone tell me what that is?




signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Jens Alfke

> On Sep 20, 2014, at 7:54 PM, 2551 <2551p...@gmail.com> wrote:
> 
> OK, I should have presented the problem, rather than a solution that needed 
> improving. If you have two text files written out at different times, how do 
> you guys determine the difference between their contents to produce a third 
> file stating the changes?

See what I wrote earlier about diff algorithms. (To see them in action, use the 
'diff' command in your favorite version control tool, like git or svn.) 
However, these tend to be either line- or byte-oriented; I'm not sure what 
there is that operates on word boundaries.

The thing you're looking for doesn't seem very useful, to be honest. If I want 
to know the difference between two versions of something, I don't think I'd 
find a randomly-ordered pile of words useful. What I'd want is something that 
shows the combined text with the deleted words crossed out and the new words 
highlighted. That's basically a diff. The implementation is completely 
different from what you're doing, because order matters; it has to scan both 
arrays of words in parallel and notice the changes (and beyond that, I don't 
know any further details. I'm sure it's covered in textbooks.)

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551
On 21 Sep 2014, at 02:56, Ludovic Nicolle  wrote:

> Once we (and maybe yourself? :p ) know what you truly want

OK, I should have presented the problem, rather than a solution that needed 
improving. If you have two text files written out at different times, how do 
you guys determine the difference between their contents to produce a third 
file stating the changes? (You can assume they are plain text and contain 
nothing other than the traditional ASCII 128 character set). That's all I'm 
trying to achieve. 

For my use case, order can be ingored, but case sensitive differences and 
repeats must be counted as unique instances. 

Thus, if 

String A =  @"Happy Birthday to You Happy Birthday to You Happy Birthday Dear 
Mary";
//Happy = 3, Birthday = 3, to = 2, You  = 2, Dear = 1, Mary = 1
 
String B = @"Happy Birthday Dear Mary and you too Scary";
//Happy = 1, Birthday = 1, Dear = 1; Mary = 1, and = 1, you = 1, too = 1, Scary 
= 1

The result should be the subtraction of the word counts, returning:

result = @"Happy Birthday to You Happy Birthday to You and you too Scary; 
//Happy = 2, Birthday = 2, to =2, You = 2, and = 1, you =1, too =1, Scary = 1
 
Just to sum up, the suggestions I've had so far are to look at

CFStringTokenizer (Thanks, Kyle)
NSLinguisticTagger (Thanks, Gerd)

and

NSMutableSet -minusSet: or -intersectSet (Gerd, again). 

I did look at -minusSet before setting out to reinvent the wheel (rather 
squarely) using a convoluted implementation of NSArray's removeObject. but I 
overlooked -intersectSet. I'll look again.


Thanks for the help so far.

Best



signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Gerd Knops
NSLinguisticTagger might be worth a look.

And if you don't care about word counts, NSMutableSet -minusSet: or 
-intersectSet: could be of help as well.

Gerd

> On Sep 20, 2014, at 1:54 PM, 2551 <2551p...@gmail.com> wrote:
> 
> Definition:
> 
> On 21 Sep 2014, at 00:53, Jens Alfke  wrote:
> 
>> a set of the words that are in the second string but not in the first
> 
> That's close. Any words that are in one string but not in the other. Yup, 
> that is what I'm after. 
> 
> I'll pass if people start asking me what I mean by a 'word', though I'm well 
> aware that that is a genuine question at certain levels and across different 
> localisations. Take it that for the purpose of the inquiry I mean any 
> combination of letters in the standard English alphabet that is space 
> delimited. Punctuation and diacriticals can be ignored for my current 
> purposes.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/gerti-cocoadev%40bitart.com
> 
> This email sent to gerti-cocoa...@bitart.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Kyle Sluder
On Sep 20, 2014, at 11:54 AM, 2551 <2551p...@gmail.com> wrote:
> 
> I'll pass if people start asking me what I mean by a 'word', though I'm well 
> aware that that is a genuine question at certain levels and across different 
> localisations. Take it that for the purpose of the inquiry I mean any 
> combination of letters in the standard English alphabet that is space 
> delimited. Punctuation and diacriticals can be ignored for my current 
> purposes.

Well luckily for you, there is a general-purpose word splitter in Core 
Foundation that works for many non-Latin languages as well: CFStringTokenizer.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551
Definition:

On 21 Sep 2014, at 00:53, Jens Alfke  wrote:

> a set of the words that are in the second string but not in the first

That's close. Any words that are in one string but not in the other. Yup, that 
is what I'm after. 

I'll pass if people start asking me what I mean by a 'word', though I'm well 
aware that that is a genuine question at certain levels and across different 
localisations. Take it that for the purpose of the inquiry I mean any 
combination of letters in the standard English alphabet that is space 
delimited. Punctuation and diacriticals can be ignored for my current purposes.


signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread SevenBits
On Sep 20, 2014, at 1:43 PM, Scott Ribe  wrote:

> On Sep 20, 2014, at 11:13 AM, 2551 <2551p...@gmail.com> wrote:
> 
>> For example:
>> 
>>  NSString *mary = @"mary had a little lamb, a little lamb she had";
>>   NSString *scary = @"mary had a little lamb, a little naughty fella of a 
>> lamb she had for sure";
>>   NSString *isDifferent = [self getDifference:mary and: scary];
>>   NSLog(@"%@", isDifferent);
>> 
>> The method I posted below produces the difference that I want ("naughty 
>> fella of a for sure"). But I want to know if there's a more orthodox and 
>> robust solution. 
> 
> That's not even remotely close to a definition of what you mean. What about:
> 
> @"mary had a little lamb, a little naughty lamb she had"
> 
> vs
> 
> @"mary had a little lamb, a little fella of a lamb she had for sure"
> 
> ?
> 
> Or:
> 
> @"mary had a little lamb, a naughty little lamb she had"
> 
> vs
> 
> @"mary had a big lamb, a little fella of a lamb she had for sure"
> 
> There is no simple definition of "the difference between two strings", and I 
> don't think it's a basic need at all.

Exactly. While it may seem that it’s a simple question, we actually have no 
idea what you mean unless you tell us. 

> 
> -- 
> Scott Ribe
> scott_r...@elevated-dev.com
> http://www.elevated-dev.com/
> (303) 722-0567 voice
> 
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/sevenbitstech%40gmail.com
> 
> This email sent to sevenbitst...@gmail.com



signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Jens Alfke

> On Sep 20, 2014, at 10:43 AM, Scott Ribe  wrote:
> 
> There is no simple definition of "the difference between two strings", and I 
> don't think it's a basic need at all.

Usually when programmers talk about "differences" they're referring to 
something like what a 'diff' tool produces, which is basically a description 
showing the insertions/deletions that have to be made to the first string to 
produce the second. This is a very useful type of algorithm that's used a lot 
in version-control systems, especially because you can later apply the diff 
output to the first string and reconstruct the second.

Diff algorithms are fairly complex, though, and the details depend a lot on 
what the granularity of the insertions/deletions is — the usual diff tools 
consider lines of text as units, but there are "binary delta" algorithms whose 
units are individual bytes and that will operate on arbitrary data.

I'm still not clear what exactly the OP is asking for. It looks like maybe just 
a set of the words that are in the second string but not in the first? Keary's 
solution works well for that.

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Scott Ribe
On Sep 20, 2014, at 11:13 AM, 2551 <2551p...@gmail.com> wrote:

> For example:
> 
>   NSString *mary = @"mary had a little lamb, a little lamb she had";
>NSString *scary = @"mary had a little lamb, a little naughty fella of a 
> lamb she had for sure";
>NSString *isDifferent = [self getDifference:mary and: scary];
>NSLog(@"%@", isDifferent);
> 
> The method I posted below produces the difference that I want ("naughty fella 
> of a for sure"). But I want to know if there's a more orthodox and robust 
> solution. 

That's not even remotely close to a definition of what you mean. What about:

@"mary had a little lamb, a little naughty lamb she had"

vs

@"mary had a little lamb, a little fella of a lamb she had for sure"

?

Or:

@"mary had a little lamb, a naughty little lamb she had"

vs

@"mary had a big lamb, a little fella of a lamb she had for sure"

There is no simple definition of "the difference between two strings", and I 
don't think it's a basic need at all.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread Keary Suska
On Sep 20, 2014, at 11:13 AM, 2551 <2551p...@gmail.com> wrote:

> For example:
> 
>   NSString *mary = @"mary had a little lamb, a little lamb she had";
>NSString *scary = @"mary had a little lamb, a little naughty fella of a 
> lamb she had for sure";
>NSString *isDifferent = [self getDifference:mary and: scary];
>NSLog(@"%@", isDifferent);
> 
> The method I posted below produces the difference that I want ("naughty fella 
> of a for sure"). But I want to know if there's a more orthodox and robust 
> solution. 
>>> 

I would use an NSOrderedSet and NSCharacterSet for robustness, e.g.:

NSMutableCharacterSet *separatorSet = [NSMutableCharacterSet 
punctuationCharacterSet];
[separatorSet formUnionWithCharacterSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet]];
NSMutableOrderedSet *maryWords = [NSMutableOrderedSet orderedSetWithArray:[mary 
componentsSeparatedByCharactersInSet:separatorSet]];
NSMutableOrderedSet *scaryWords = [NSMutableOrderedSet 
orderedSetWithArray:[scary componentsSeparatedByCharactersInSet:separatorSet]];
BOOL maryLonger = [maryWords count] > [scaryWords count];
[(maryLonger ? maryWords : scaryWords) minusOrderedSet:(maryLonger ? scaryWords 
: maryWords)];
NSLog(@"%@", (maryLonger ? maryWords : scaryWords));

Though this wouldn't account for order or duplicates, but neither would your 
implementation.

>> 
>>> -(NSString *)getDifference: (NSString *)aString and:(NSString 
>>> *)anotherString {
>>>  int i = aString.length;
>>>  int j = anotherString.length;
>>>  NSString *result, *longest, *shortest;
>>> 
>>>  if (i == j) {
>>>  result = @"";
>>>  return result;
>>>  }
>>> 
>>>  if (i > j) {
>>>  longest = aString;
>>>  shortest = anotherString;
>>>  } else {
>>>  longest = anotherString;
>>>  shortest = aString;
>>>  }
>>> 
>>>  NSArray *fa = [longest componentsSeparatedByString: @" " ];
>>>  NSArray *sa = [shortest componentsSeparatedByString: @" "];
>>>  NSMutableArray *remainder = [NSMutableArray arrayWithArray:fa];
>>>  [remainder removeObjectsInArray:sa];
>>>  result = [remainder componentsJoinedByString:@" "];
>>>  return result;
>>> 
>>> }


Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread 2551
Really? OK.
On 21 Sep 2014, at 00:05, SevenBits  wrote:

> On Sep 20, 2014, at 1:01 PM, 2551 <2551p...@gmail.com> wrote:
> 
>> I've searched high and low (or roundabouts in circles) for a built in method 
>> that will return the difference between two strings as a string. 
>> 
>> I hacked up this solution below, but it feels cludgy and isn't very robust 
>> (punctuation will mess it up a little); worse, I can't help feeling I must 
>> be reinventing the wheel. Finding the string that is the difference between 
>> two other strings must be a basic need. How do you guys do this? 
> 
> Define what you mean the “difference between two strings”.

 
For example:

   NSString *mary = @"mary had a little lamb, a little lamb she had";
NSString *scary = @"mary had a little lamb, a little naughty fella of a 
lamb she had for sure";
NSString *isDifferent = [self getDifference:mary and: scary];
NSLog(@"%@", isDifferent);

The method I posted below produces the difference that I want ("naughty fella 
of a for sure"). But I want to know if there's a more orthodox and robust 
solution. 




> 
>> 
>> 
>> 
>> -(NSString *)getDifference: (NSString *)aString and:(NSString 
>> *)anotherString {
>>   int i = aString.length;
>>   int j = anotherString.length;
>>   NSString *result, *longest, *shortest;
>> 
>>   if (i == j) {
>>   result = @"";
>>   return result;
>>   }
>> 
>>   if (i > j) {
>>   longest = aString;
>>   shortest = anotherString;
>>   } else {
>>   longest = anotherString;
>>   shortest = aString;
>>   }
>> 
>>   NSArray *fa = [longest componentsSeparatedByString: @" " ];
>>   NSArray *sa = [shortest componentsSeparatedByString: @" "];
>>   NSMutableArray *remainder = [NSMutableArray arrayWithArray:fa];
>>   [remainder removeObjectsInArray:sa];
>>   result = [remainder componentsJoinedByString:@" "];
>>   return result;
>> 
>> }
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/sevenbitstech%40gmail.com
>> 
>> This email sent to sevenbitst...@gmail.com
> 



signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: return string that is the difference between two other strings

2014-09-20 Thread SevenBits
On Sep 20, 2014, at 1:01 PM, 2551 <2551p...@gmail.com> wrote:

> I've searched high and low (or roundabouts in circles) for a built in method 
> that will return the difference between two strings as a string. 
> 
> I hacked up this solution below, but it feels cludgy and isn't very robust 
> (punctuation will mess it up a little); worse, I can't help feeling I must be 
> reinventing the wheel. Finding the string that is the difference between two 
> other strings must be a basic need. How do you guys do this? 

Define what you mean the “difference between two strings”.

> 
> 
> 
> -(NSString *)getDifference: (NSString *)aString and:(NSString *)anotherString 
> {
>int i = aString.length;
>int j = anotherString.length;
>NSString *result, *longest, *shortest;
> 
>if (i == j) {
>result = @"";
>return result;
>}
> 
>if (i > j) {
>longest = aString;
>shortest = anotherString;
>} else {
>longest = anotherString;
>shortest = aString;
>}
> 
>NSArray *fa = [longest componentsSeparatedByString: @" " ];
>NSArray *sa = [shortest componentsSeparatedByString: @" "];
>NSMutableArray *remainder = [NSMutableArray arrayWithArray:fa];
>[remainder removeObjectsInArray:sa];
>result = [remainder componentsJoinedByString:@" "];
>return result;
> 
> }
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/sevenbitstech%40gmail.com
> 
> This email sent to sevenbitst...@gmail.com



signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

return string that is the difference between two other strings

2014-09-20 Thread 2551
I've searched high and low (or roundabouts in circles) for a built in method 
that will return the difference between two strings as a string. 

I hacked up this solution below, but it feels cludgy and isn't very robust 
(punctuation will mess it up a little); worse, I can't help feeling I must be 
reinventing the wheel. Finding the string that is the difference between two 
other strings must be a basic need. How do you guys do this? 



-(NSString *)getDifference: (NSString *)aString and:(NSString *)anotherString {
int i = aString.length;
int j = anotherString.length;
NSString *result, *longest, *shortest;

if (i == j) {
result = @"";
return result;
}

if (i > j) {
longest = aString;
shortest = anotherString;
} else {
longest = anotherString;
shortest = aString;
}

NSArray *fa = [longest componentsSeparatedByString: @" " ];
NSArray *sa = [shortest componentsSeparatedByString: @" "];
NSMutableArray *remainder = [NSMutableArray arrayWithArray:fa];
[remainder removeObjectsInArray:sa];
result = [remainder componentsJoinedByString:@" "];
return result;

}



signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com