Apple Dictionary

Here is where the magnanimous folks that create externals post them (.zip archives only please).

Apple Dictionary

Postby mrBean » Wed Jan 26, 2011 4:56 pm

This is an example for my external, Definition; that allows you to access apple built-in dictionary.
Last edited by mrBean on Sat Jan 29, 2011 10:13 am, edited 1 time in total.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: Apple Dictionary

Postby Scott » Thu Jan 27, 2011 5:05 am

I moved this to XCmds, XFcns, and XRtns.

BTW... this appears to be Intel only. Did you intend it that way?
User avatar
Scott
Site Admin
 
Posts: 1217
Joined: Sat Jul 05, 2008 1:37 pm
Location: Northern Sierra Nevada

Re: Apple Dictionary

Postby Dan_Kelleher » Thu Jan 27, 2011 9:55 am

Yup.
error is "never heard of that function" on PPC OSX 10.5.8
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Apple Dictionary

Postby mrBean » Thu Jan 27, 2011 3:36 pm

Scott wrote:BTW... this appears to be Intel only. Did you intend it that way?


No, i never intended for the external to be intel only, sorry for the mistake.
Last edited by mrBean on Sat Jan 29, 2011 5:41 pm, edited 1 time in total.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: Apple Dictionary

Postby Dan_Kelleher » Thu Jan 27, 2011 7:32 pm

Still testing on PPC OSX 10.58,
If the search value field is empty the return is "Search Value is empty."
but
if the search value is not empty, and contains "play" the return is "play" but no definition

I'm wondering if I have the right dictionary (?.app) as shown in the get Info below; ?

(Also, if the search value is either "?" or "!" it hangs then crashes)

-Dan


Picture 1.jpg
Picture 1.jpg (14.54 KiB) Viewed 8110 times
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Apple Dictionary

Postby mrBean » Thu Jan 27, 2011 10:00 pm

Dan_Kelleher wrote:If the search value field is empty the return is "Search Value is empty."


That's my own error message per-say, not from apple's dictionary API.

Dan_Kelleher wrote:if the search value is not empty, and contains "play" the return is "play" but no definition


I don't know why that happens, but believe it or not, thats not an error with the external. try words like "history" or "ghost".

Dan_Kelleher wrote:(Also, if the search value is either "?" or "!" it hangs then crashes)


I found the error, and I'll see about fixing it tomorrow. Thanks for the help.

Dan_Kelleher wrote:I'm wondering if I have the right dictionary (?.app) as shown in the get Info below; ?


Yes.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: Apple Dictionary

Postby Dan_Kelleher » Fri Jan 28, 2011 7:47 am

Hi Mr Beam,
I hope the following helps. (Note I'm still testing only on PPC OS 10.5.8 and SC 4.7)

As you suggested, both "ghost" and "history" DO return definitions, more evidence of success.

I've found 3 issues.
1. The "Dictionary app" returns a different, longer defn compared to the "Definition XFcn".
compare the first 2 attached screenshots for "ghost" (same sort of thing for "history")

(As you can see from the THIRD screenshot, I used the "Dictionary" option of the "Dictionary app". The "Apple" option returns no defn while the "Thesaurus" option returns a shorter defn but it's different than the short one returned by the "Definition XFcn".)

2. If a word is mistyped to generate nonsense (I'm good at that) the "Dictionary app" returns a suggestion(s) while the "Definition XFcn" crashes.
see the third attached screenshot using the nonsense search value, "ghoost".

3.While the "Dictionary app" returns definitions for both "play" and "dog" the Definition XFcn" returns
"play" (without a definition) and returns empty in the case of input "dog". ??

(I looked very briefly in the bundle "Contents" of the "Dictionary app" for the database(s?) to check out 'it's' structure but did not find 'it' quickly and I've 'gotta run' - financial aid forms -ugh)
-Dan
ghost_Dictionary app.jpg
ghost_Dictionary app.jpg (41.97 KiB) Viewed 8094 times

ghost_Definition XFcn.jpg
ghost_Definition XFcn.jpg (16.23 KiB) Viewed 8094 times

ghoost_Dictionary app.jpg
ghoost_Dictionary app.jpg (10.59 KiB) Viewed 8094 times
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Apple Dictionary

Postby mrBean » Sat Jan 29, 2011 5:41 pm

Dan_Kelleher wrote:1. The "Dictionary app" returns a different, longer defn compared to the "Definition XFcn".
compare the first 2 attached screenshots for "ghost" (same sort of thing for "history")

I don't know why the length of the definitions differ from one another, but I can tell you, it's by design of the dictionary's API that's provided by apple.

Dan_Kelleher wrote:2. If a word is mistyped to generate nonsense (I'm good at that) the "Dictionary app" returns a suggestion(s) while the "Definition XFcn" crashes.
Dan_Kelleher wrote:3.While the "Dictionary app" returns definitions for both "play" and "dog" the Definition XFcn" returns
"play" (without a definition) and returns empty in the case of input "dog". ??


Both of these things happen for basically the same reason. When i access the dictionary API, the definition that I get I put into a variable type called CFStringRef. When the definition is handed over to superCard, the variable type is converted from CFStringRef to char. It is at this point when all the trouble starts.
If you pass a anything that the dictionary does not have a definition for, it comes back empty. when the external tries to convert that empty variable, it crashes. So now I have put a condition in, to check if the API comes back with a definition. if it does come back empty, the following string will be returned ""[searchValue]" could not be found."
There are two reason why definition didn't come back with one. in the case of "dog" the function that converts CFStringRef to char failed. I have add in a condition in to check if it fails, if so then i use my own custom converter. in the case of "play" the definition is larger then the space that was allocated for the char variable, so the converter didn't bother to do it's job. i have now made the externals memory management more dynamic, to prevent this from happening.
Attachments
definition.sc45.zip
OSX 10.5 or latter || SC 4.7
Universal Binary
(17.54 KiB) Downloaded 311 times
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: Apple Dictionary

Postby sctell » Sun Jan 30, 2011 3:11 am

Hi,

Out of interest Uli Kusterer produced a class for working with Cocoa called SCParamBlock.

I think it was included with the source code I gave you the other week.

It has many useful functions for working with SC. Here is the header.

If you are not working with Cocoa it still may be useful to see how the conversions to access SC work.

If anyone needs it, please speak up and I will post it here in a small bare bones Xcode project showing how it works with Cocoa. Hopefully Uli won't mind.


Code: Select all
@interface SCParamBlock : NSObject
{
   XCmdPtr   paramPtr;
}

-(id)initWithXCmdBlock: (XCmdPtr)pblock;

// Parameters:
-(int)parameterCount;

-(NSString*)parameterAtIndex: (int)ind;
-(void)setParameterAtIndex: (int)ind to: (NSString*)str;   // For pass-by-reference parameters.

-(NSData*)parameterDataAtIndex: (int)ind;
-(void)setParameterDataAtIndex: (int)ind to: (NSData*)theData;   // For pass-by-reference parameters.

// Return value:
-(void)setReturnValue: (NSString*)str;


// Callbacks:
-(void)sendCardMessage: (NSString*)superTalkStatement;
-(void)sendSCMessage: (NSString*)superTalkStatement;
-(NSString*)evaluateExpression: (NSString*)superTalkExpression;

-(NSString*)valueForGlobal: (NSString*)globalName;
-(void)setValue: (NSString*)var forGlobal: (NSString*)globalName;

-(NSString*)valueOfFieldNamed: (NSString*)fieldName onCardLayer: (BOOL)yorn;
-(NSString*)valueOfFieldNumber: (int)num onCardLayer: (BOOL)yorn;
-(NSString*)valueOfFieldID: (int)num onCardLayer: (BOOL)yorn;

-(void)setValue: (NSString*)val forFieldNamed: (NSString*)fieldName onCardLayer: (BOOL)yorn;
-(void)setValue: (NSString*)val forFieldNumber: (int)num onCardLayer: (BOOL)yorn;
-(void)setValue: (NSString*)val forFieldID: (int)num onCardLayer: (BOOL)yorn;

// Low-level utility stuff:
+(Handle)stringHandleFromString: (NSString*)str;
+(Handle)stringHandleFromData: (NSData*)theData;

+(NSString*)stringFromStringHandle: (Handle)theHd;
+(NSData*)dataFromStringHandle: (Handle)theHd;

+(void)setStringPtr: (StringPtr)theString toString: (NSString*)str;   // theString must be a variable of type Str255.

@end
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Apple Dictionary

Postby Dan_Kelleher » Sun Jan 30, 2011 5:41 am

No crashes here now and reasonable returns for "play", "dog", "ghost" and nonsense "ghoost".
Nice!
-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Apple Dictionary

Postby mrBean » Sun Jan 30, 2011 5:00 pm

-- Dan Kelleher
Thanks for your help, your beta testing really help me to clean up my external.

--terry heaford
I have the SCParamBlock file but haven't taken much of a look at it yet, I've been sticking with what I'm familiar with.
But I did used the source code you gave me as an outlines for building this Cocoa external.
User avatar
mrBean
 
Posts: 89
Joined: Sat Jan 30, 2010 8:03 am
Location: New York

Re: Apple Dictionary

Postby LorenzT » Sun Jan 30, 2011 11:42 pm

BTW, did you know that you can use an AppleScript to open the Dictionary with a search term?
Try: open location dict://ghost
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: Apple Dictionary

Postby 1nperson0z » Tue Feb 01, 2011 5:07 pm

If anyone needs it, please speak up and I will post it here in a small bare bones Xcode project showing how it works with Cocoa. Hopefully Uli won't mind


Hi Terry, if OK I would like a look at how Uli has done that.

Thanks
Ian B
MacBook Pro 2.4Ghz i7 8Gb 10.11.3
1nperson0z
 
Posts: 78
Joined: Wed Jul 09, 2008 3:31 pm
Location: Blue Mountains Australia

Re: Apple Dictionary

Postby sctell » Wed Feb 02, 2011 10:30 am

Ian,

I have uploaded a sample file here:

http://forums.supercard.us/viewtopic.php?f=16&t=1284
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am


Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest

cron