Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dictionary Manager: Manipulate with records?



I want to create a custom dictionary which can be used by Dictionary.app with Dictionary Manager.

Sorry, currently there is no public information to create dictionaries usable by Dictionary.app. It is considered being published in the future system release.


4) DCMGetDictionaryFieldInfo(), AEGetDescDataSize() and AEGetDescData() returns a "field info record", whose 'descriptorType' field is 'list' and the 'dataHandle field' points to a 420 bytes lengthed memory block. So, what is "field info record"?

"Field info record" consists of various information of each "field" data category corresponding to name and address in an address book. Each field is represented by four characters "tag" and has various information such as data type and maximum length. Dictionaries must have at least one "key field" which is indexed and can be used for searching.


DCMGetNextRecord(dictRef, '****', 0, NULL, 0, maxKeySize, &nextKeySize, dataBuf, &nextUniqueID); should return the 1st record in this dictionary. But I always get a -7113 error, which means "no such field exists".

Unfortunately, you cannot iterate all records in Oxford dictionaries by this function since those dictionaries have kDCMProhibitListing (=1) value in pDCMListing (='list') property as you found. Please see: <http://developer.apple.com/documentation/Carbon/Reference/ Dictionary_Manager/dm_refchap/chapter_38.4_section_11.html#// apple_ref/doc/uid/TP30000141-DontLinkChapterID_4-C008792>


Of course, you can search Oxford dictionaries with a particular keyword using Dictionary Manager API. The key field of Oxford dictionaries is 'dsky' and body text is stored in 'dsbd' field as xml. Followings are sample code of searching Oxford dictionary for your information.


{ OSStatus err; DCMDictionaryRef dictionaryRef;

    err = OpenOxfordDictionary( &dictionaryRef);
    if ( err == noErr )
    {
        LookupOxfordDictionary( dictionaryRef, CFSTR("test"));
        DCMCloseDictionary( dictionaryRef);
    }
}

// -----------------------------------

static OSStatus OpenOxfordDictionary( DCMDictionaryRef *dictionaryRef )
{
    OSStatus        err;
    FSRef           dictFileRef;
    FSSpec          dictFileSpec;
    DCMDictionaryID dictionaryID;

err = FSPathMakeRef( "/Library/Dictionaries/New Oxford American Dictionary.dict",
&dictFileRef, NULL);
if ( err == noErr )
err = FSGetCatalogInfo( &dictFileRef, kFSCatInfoNone, NULL, NULL, &dictFileSpec, NULL);


if ( err == noErr )
err = DCMGetDictionaryIDFromFile( &dictFileSpec, &dictionaryID);


    if ( err == noErr )
        err = DCMOpenDictionary( dictionaryID, 0, NULL, dictionaryRef);

    return err;
}

static void LookupOxfordDictionary( DCMDictionaryRef dictionaryRef, CFStringRef searchString )
{
OSStatus err;
CFIndex length = CFStringGetLength( searchString);
UniChar *dataBuffer, keyBuffer[256];
DCMFieldTag keyFieldTag = 'dsky', dataFieldTag = 'dsbd';
UInt32 keySize;
DCMUniqueID uniqueID;
DCMFoundRecordIterator recordIterator;
AEDesc dataDescList;
DescType dataType;
Size dataSize;
CFStringRef dataString;


// Look up dictionary
CFStringGetCharacters( searchString, CFRangeMake(0, length), keyBuffer);
keySize = length * sizeof(UniChar);
err = DCMFindRecords( dictionaryRef, keyFieldTag, keySize, keyBuffer,
kDCMFindMethodExactMatch, 0, NULL, 0, 0, &recordIterator);
if ( err != noErr ) return;


// Iterate found records
while ( true )
{
// Iterate a key from found key list
err = DCMIterateFoundRecord( recordIterator, sizeof (keyBuffer), &keySize,
keyBuffer, &uniqueID, NULL);
if ( err != noErr ) break;


// Retrieve data record which belongs to iterated key
err = DCMGetFieldData( dictionaryRef, keyFieldTag, keySize, keyBuffer,
uniqueID, 1, &dataFieldTag, &dataDescList);
if ( err != noErr ) break;


// Retrieve XML body text which belongs to retrieved data record
AESizeOfKeyDesc( &dataDescList, dataFieldTag, &dataType, &dataSize);
dataBuffer = (UniChar*)malloc( dataSize);
err = AEGetKeyPtr( &dataDescList, dataFieldTag, typeUnicodeText,
&dataType, dataBuffer, dataSize, &dataSize);
dataString = CFStringCreateWithCharacters( NULL, dataBuffer, dataSize / sizeof(UniChar));
CFShow( dataString);


        free( dataBuffer);
        CFRelease( dataString);
        AEDisposeDesc( &dataDescList);
    }

    DCMDisposeRecordIterator( recordIterator);
}

----
Keisuke Hara
Senior Software Engineer
Apple Japan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.