ULAPI  8.0
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ULJSONDictionaryDataSource Class Reference

ULJSONDictionaryDataSource implements the ULDictionaryDataSource protocol (and thus both the ULDictionary and ULDataSource protocols) by using ULAPI 8 .uld files. More...

#include <uljsondictionarydatasource.h>

Public Member Functions

 ULJSONDictionaryDataSource ()
 
 ULJSONDictionaryDataSource (const ULJSONDictionaryDataSource &other)
 
virtual ~ULJSONDictionaryDataSource ()
 
ULJSONDictionaryDataSourceoperator= (const ULJSONDictionaryDataSource &other)
 
virtual bool operator== (const ULDictionaryDataSource &dataSource) const
 
virtual bool operator== (const ULJSONDictionaryDataSource &dataSource) const
 
virtual bool isServiceAvailable (const ULServiceDescriptor &service)
 
virtual void getAvailableServices (ULList< ULServiceDescriptor > &serviceList)
 
virtual ULError attach (const ULString &dataSourceIdentifier)
 
virtual ULError detach ()
 
virtual ULError load ()
 
virtual ULError close ()
 
virtual ULString getDataSourceIdentifier ()
 
virtual ULDataSourceVersion getVersion ()
 
virtual ULError begin (const ULLanguage &searchLanguage, uluint32 indexID, ULDictionaryIterator &iterator)
 
virtual ULError end (const ULLanguage &searchLanguage, uluint32 indexID, ULDictionaryIterator &iterator)
 
virtual ULError find (const ULString &s, const ULLanguage &searchLanguage, uluint32 indexID, ULDictionaryIterator &iterator)
 
virtual ULDictionaryDescriptor getDictionaryDescriptor ()
 
virtual const ULLanguagegetFirstLanguage ()
 
virtual const ULLanguagegetSecondLanguage ()
 
virtual const ULLanguagegetOtherLanguage (const ULLanguage &language)
 
virtual ULForestType getForestType ()
 
virtual ULForester * getForester ()
 
virtual void setForester (ULForester *newForester)
 
virtual ULError getFeatureNameList (ULList< ULString > &featureNameList)
 
virtual ULError getLocalizationRuleList (const ULLanguage &language, ULList< ULLocalizationRule > &localizationRulesList)
 
virtual bool getULDAttribute (const ULString &key, ULString &value)
 

Protected Member Functions

bool isOpen () const
 
void clear ()
 

Protected Attributes

ULString jsonData
 
Json::Value jsonRoot
 
uluint32 nNodes
 
ULLanguage firstLanguage
 
ULLanguage secondLanguage
 
ULForester * forester
 
ULStringfeatureNames
 

Friends

class ULJSONDictionaryIterator
 

Additional Inherited Members

- Public Types inherited from ULDictionaryDataSource
enum  { HeadwordIndex, OntologyIndex, NCommonIndexIDs }
 

Detailed Description

ULJSONDictionaryDataSource implements the ULDictionaryDataSource protocol (and thus both the ULDictionary and ULDataSource protocols) by using ULAPI 8 .uld files.

Constructor & Destructor Documentation

ULJSONDictionaryDataSource::ULJSONDictionaryDataSource ( )

Default constructor.

ULJSONDictionaryDataSource::ULJSONDictionaryDataSource ( const ULJSONDictionaryDataSource other)

Copy constructor.

ULJSONDictionaryDataSource::~ULJSONDictionaryDataSource ( )
virtual

Destructor.

Member Function Documentation

ULError ULJSONDictionaryDataSource::attach ( const ULString dataSourceIdentifier)
virtual

Causes this ULDataSource object to be associated with the specified data source, and reads enough information from that data source to determine its language(s), etc.

The exact behavior of attach will be dependent on the nature of the data source. If the data source is a file, then attach will read header information from the file and then close the file to save memory until the data source is actually needed. On the other hand, if the data source is a remote database, then attach might open a connection, collect header information, and then close the connection.

Returns
ULError::NoError if the attachment is successful, or some other ULError value if not.
Parameters
[in]dataSourceIdentifierA string describing the data source (e.g. a file name, a database connection string, a URL, etc.).

Implements ULDictionaryDataSource.

ULError ULJSONDictionaryDataSource::begin ( const ULLanguage searchLanguage,
uluint32  indexID,
ULDictionaryIterator iterator 
)
virtual

Creates an iterator pointing to the first ULDictionaryNode in the set of nodes associated with the specified index. An "index" in this context refers to a sorted list of strings in the data source associated with this ULDictionary object. The most common index is the "headword" index, which is an alphabetized list of labels for dictionary entries. Other indexes may support searching for dictionary entries whose definitions contain the search string, or whose "domain" labels (e.g. "Cooking", "Botany", "Computers", "Sports") match the search string, etc.

Returns
ULError::NoError, ULError::MemoryAllocationFailed, or ULError::DataSourceOpenFailed.
Parameters
[in]searchLanguageFor bilingual dictionaries, this indicates the language of the index in question. (For example, an English-Spanish data source would have both an English headword index and a Spanish headword index, and searchLanguage would tell begin() which of these indexes to use.)
[in]indexIDAn enumerated value specifying which index to search.
[out]iteratorAn iterator pointing to the first ULDictionaryNode associated with the specified index.

Implements ULDictionaryDataSource.

void ULJSONDictionaryDataSource::clear ( )
protected

Private method that sets this data source to its default state and releases all its dynamically allocated memory.

ULError ULJSONDictionaryDataSource::close ( )
virtual

Frees dynamically allocated memory associated with this data source while keeping it attached to the file, db, etc. to which it was previously attached. Also closes any relevant files, db connections, etc.

Returns
ULError::NoError if the memory freeing was successful.

Implements ULDictionaryDataSource.

ULError ULJSONDictionaryDataSource::detach ( )
virtual

Releases the connection between this ULDataSource object and the data source specified in the previous open() or attach() call, closing any relevant files or network connections and freeing memory in the process.

Returns
ULError::NoError if the attachment is successful, or some other ULError value if not.

Implements ULDictionaryDataSource.

ULError ULJSONDictionaryDataSource::end ( const ULLanguage searchLanguage,
uluint32  indexID,
ULDictionaryIterator iterator 
)
virtual

Creates an iterator pointing to the end of the list of ULDictionaryNodes associated with the specified index. An "index" in this context refers to a sorted list of strings in the data source associated with this ULDictionary object. The most common index is the "headword" index, which is an alphabetized list of labels for dictionary entries. Other indexes may support searching for dictionary entries whose definitions contain the search string, or whose "domain" labels (e.g. "Cooking", "Botany", "Computers", "Sports") match the search string, etc.

Returns
ULError::NoError, ULError::MemoryAllocationFailed, or ULError::DataSourceOpenFailed.
Parameters
[in]searchLanguageFor bilingual dictionaries, this indicates the language of the index in question. (For example, an English-Spanish data source would have both an English headword index and a Spanish headword index, and searchLanguage would tell begin() which of these indexes to use.)
[in]indexIDAn enumerated value specifying which index to search.
[out]iteratorAn iterator pointing to the end of the ULDictionaryNode list associated with the specified index.

Implements ULDictionaryDataSource.

ULError ULJSONDictionaryDataSource::find ( const ULString searchString,
const ULLanguage searchLanguage,
uluint32  indexID,
ULDictionaryIterator iterator 
)
virtual

Searches the data source(s) associated with this ULDictionary for the closest match to the specified search string, using the specified language and index. An "index" in this context refers to a sorted list of strings in the data source associated with this ULDictionary object. The most common index is the "headword" index, which is an alphabetized list of labels for dictionary entries. Other indexes may support searching for dictionary entries whose definitions contain the search string, or whose "domain" labels (e.g. "Cooking", "Botany", "Computers", "Sports") match the search string, etc.

The "closest match" found by this method is closest in the sense of a binary search on a sorted list. More specifically, the closest match is the lexicographically smallest item in the specified index that is greater than or equal to the search string. Thus, for example, if you search for "sp" in English, you'll get an iterator pointing to the first English word starting with "sp" or "Sp" (e.g. "spa").

Returns
ULError::NoError, ULError::MemoryAllocationFailed, or ULError::DataSourceOpenFailed.
Parameters
[in]searchStringThe string you're looking for.
[in]searchLanguageFor bilingual dictionaries, this specifies the direction in which to search–i.e. the language in which searchString is to be interpreted.
[in]indexIDAn enumerated value specifying which index to search.
[out]iteratorAn iterator pointing to the closest match in the specified index. This iterator will point to a top-level ULDictionaryNode (i.e. one with no parent node).

Implements ULDictionaryDataSource.

void ULJSONDictionaryDataSource::getAvailableServices ( ULList< ULServiceDescriptor > &  serviceList)
virtual
Parameters
[out]serviceListUsed to return a list of all the services this ULWorker can provide.

Implements ULWorker.

ULString ULJSONDictionaryDataSource::getDataSourceIdentifier ( )
virtual
Returns
the data source identifier for the data source attached to this ULDataSource object, or the empty string if no data source is attached.

Implements ULDictionaryDataSource.

ULDictionaryDescriptor ULJSONDictionaryDataSource::getDictionaryDescriptor ( )
virtual
Returns
a ULDictionaryDescriptor object describing the data source attached to this ULDictionaryDataSource.

Implements ULDictionaryDataSource.

ULError ULJSONDictionaryDataSource::getFeatureNameList ( ULList< ULString > &  featureNameList)
virtual

Obtains the list of feature names stored in this data source. The feature names in this list are associated, in the data source itself, with integer IDs starting at 0 for the first string in featureNameList, and going up to featureNameList.length() - 1.

Returns
ULError::NoError if the list can be retrieved.
Parameters
[out]featureNameListthe list of feature names stored in this data source.

Implements ULDictionaryDataSource.

const ULLanguage & ULJSONDictionaryDataSource::getFirstLanguage ( )
virtual
Returns
this data source's first language.

Implements ULDictionaryDataSource.

ULForester * ULJSONDictionaryDataSource::getForester ( )
virtual
Returns
a pointer to the forester used by this data source.

Implements ULDictionaryDataSource.

ULForestType ULJSONDictionaryDataSource::getForestType ( )
virtual
Returns
the forest type for this data source, which can be used (among other things) to decide which subclass of ULForester to assign to this data source.

Implements ULDictionaryDataSource.

ULError ULJSONDictionaryDataSource::getLocalizationRuleList ( const ULLanguage language,
ULList< ULLocalizationRule > &  localizationRulesList 
)
virtual

Obtains the list of localization rules stored in this data source for the given language.

Returns
ULError::NoError if the list can be retrieved.
Parameters
[in]languageThe language for which to retrieve the rules.
[out]localizationRuleListThe list of localization rule stored in this data source for the given language

Implements ULDictionaryDataSource.

const ULLanguage & ULJSONDictionaryDataSource::getOtherLanguage ( const ULLanguage language)
virtual
Returns
this data source's language that is not the parameter.

Implements ULDictionaryDataSource.

const ULLanguage & ULJSONDictionaryDataSource::getSecondLanguage ( )
virtual
Returns
this data source's second language.

Implements ULDictionaryDataSource.

bool ULJSONDictionaryDataSource::getULDAttribute ( const ULString key,
ULString value 
)
virtual

Retrieves the ULD attribute value associated with the given key if it exists for this ULD.

Returns
true if the uld has this attribute and false otherwise.
Parameters
[in]keyThe string that is the key for the attribute you want to retrieve.
[out]valueThe value of the attribute if it exists.

Implements ULDictionaryDataSource.

ULDataSourceVersion ULJSONDictionaryDataSource::getVersion ( )
virtual
Returns
the ULDataSourceVersion associated with this data source.

Implements ULDictionaryDataSource.

bool ULJSONDictionaryDataSource::isOpen ( ) const
protected
bool ULJSONDictionaryDataSource::isServiceAvailable ( const ULServiceDescriptor service)
virtual
Returns
true if the specified service can be performed by this ULWorker, and false otherwise.
Parameters
serviceThe desired service.

Implements ULWorker.

ULError ULJSONDictionaryDataSource::load ( )
virtual

Perform one-time opening and loading operations. Normally, such operations are performed lazily, when the data source is first queried. If you would prefer to control the time at which loading is performed, call this method.

Returns
ULError::NoError if the loading was successful.

Implements ULDictionaryDataSource.

ULJSONDictionaryDataSource & ULJSONDictionaryDataSource::operator= ( const ULJSONDictionaryDataSource other)

Assignment operator. This operator does not actually copy anything, so the lvalue of an assignment between ULJSONDictionaryDataSources will remain unchanged.

bool ULJSONDictionaryDataSource::operator== ( const ULDictionaryDataSource dataSource) const
virtual
bool ULJSONDictionaryDataSource::operator== ( const ULJSONDictionaryDataSource dataSource) const
virtual

Equality operator. Just checks to see if the underlying data is equal.

void ULJSONDictionaryDataSource::setForester ( ULForester *  newForester)
virtual

Assigns the forester to be used by this ULDictionaryDataSource. The data source takes responsibility for deleting the forester.

Parameters
[in]newForesterA pointer to the desired forester.

Implements ULDictionaryDataSource.

Friends And Related Function Documentation

friend class ULJSONDictionaryIterator
friend

Member Data Documentation

ULString* ULJSONDictionaryDataSource::featureNames
protected
ULLanguage ULJSONDictionaryDataSource::firstLanguage
protected
ULForester* ULJSONDictionaryDataSource::forester
protected
ULString ULJSONDictionaryDataSource::jsonData
protected
Json::Value ULJSONDictionaryDataSource::jsonRoot
protected
uluint32 ULJSONDictionaryDataSource::nNodes
protected
ULLanguage ULJSONDictionaryDataSource::secondLanguage
protected

The documentation for this class was generated from the following files: