Find By Content No More

I don’t know if the Sane main issue writer is just really old (well, it is… 2001 or so, which is old, in software terms, I suppose), but this little Cocoa app that drives Sane Magazine each week (umm… except for the last two, since we’ve been on… hiatus/vacation), needed a little upgrade recently. But moving it to Leopard the other day I noticed that it still used Find By Content’s FBCSummarizeCFString() function… which was new as of 10.2 and deprecated as of 10.4 (doh). This was for the handy dandy summary of the latest issue we produce. A little known, little used feature, but there it is. At any rate, to get our summarization up to speed, it just took a little digging and a tiny little bit of work.

So I figured I’d write about the quick and easy fix, since it took me a few minutes of digging to find the replacement function to use: you need to look into Search Kit.

A combo of SKSummaryCreateWithString to get an SKSummaryRef and SKSummaryCopySentenceSummaryString on that with the number of sentences you want to limit it to gets you back to where we were with FBCSummarizeCFString.

CFStringRef myTextString = CFStringCreateCopy(NULL, (CFStringRef)[[self mainText] string]);
CFStringRef mySummaryString;
UInt32 numOfSentences = 2;

SKSummaryRef summaryRef = SKSummaryCreateWithString(myTextString);

mySummaryString = SKSummaryCopySentenceSummaryString(summaryRef, numOfSentences);

Enjoy.

3 thoughts on “Find By Content No More”

  1. Hi,
    congratulation you got the stuff working for which I am looking for. This nights had some unsuccessful attempts.

    From the description and Apple documentation it sounds easy (only a few functions must be used). But it is the 1st run for me to get the stuff working on an Apple.

    I am using Tiger 10.4.11 and my intention is to have an as sample as possible summarizer on the command line usable like grep:

    cat MyText.txt | summarize -s 10 > MySumText.txt

    Can you give me a hint? I have not understood that line of code:
    CFStringRef myTextString = CFStringCreateCopy(NULL, (CFStringRef)[[self mainText] string]);
    ==> Compiler Error

    Thanks in advance and best regards
    Frank

  2. Sure. That line simply gets me a CFStringRef from the NSString in the main NSTextView in the window, which is what SKSummaryCreateWithString() expects.

    I could have written it differently (didn’t need the CFStringCreateCopy), as NSString and CFStringRef are toll-free bridged, but that seems to be beside the point, for your particular case.

    So you’ll want to do something like grab the piped in text, get a CFStringRef for it, feed it into the SK* functions like mentioned in the above post, and you should be good to go.

  3. Hi,

    thanks for your hints!!! I got it basically running (after calling 411 URLs) . I’ve used the Xcode Project Type “Command Line Utility – Foundation Tool” (the key for my success). Up to now I’ve pre-definded the text which has to be summarized constant in a string variable. That simple story does work now!

    My next problem is that I do not now:

    1. How to handover arguments to the program during start up like “head -n 5 file.txt”, “-n 5” is for example an argument. I would like to use that to distinguish between sentense and paragraph plus percentage of summarization. For a C programmed applications I woud have ideas but for Objective-C not yet (fork(), pipe(), execlp()).

    2. How to handle raw file access (read/write). For eample read the content of the file byte per byte until EOF. And the some for writing into a file.

    Can you provide me further information or a link which already descibes the solution of my problem.

    Thanks in advance and best regards
    Frank

    P.S.: Sorry for these maybe stupied questions but the interface is Objective-C and it is my first run. Learning by doing or better by asking. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *