JADT entry, Part 1

xiaoxiao2021-03-06  90

Use Java Dictionary and Dictionary API in the Java application

Level: Intermediate

Rakesh Midha (Mrakesh@in.ibm.com) Software Engineer, IBM Software Laboratory, Bangalore 2004 October

Java Dictionary and Dictionary API (Dictionary and THESAURURUS API for Java, JADT) is a class library that accesses language features in the Java application. This article is part of the series of articles composed of two parts, in this article, JADT developers rakesh Midha discussed JADT from the user's perspective and showing how to use JADT in the Java application. He discussed the various types and design involved in JADT, as well as some of the features that can be used in JADT.

Part 2, in depth, the details of the architecture and the API are discussed, providing guidance for users who wish to implement JADT drivers.

Java Dictionary and Dictionary API (JADT) is an API of the dictionary features published on AlphaWorks, which is a standard class library for accessing language features in the Java application. It provides a transparent method-centric approach to Java programmers to access dictionary and non-structured words, as well as information about them. This article is part of the series of articles consisting of two parts, and the content involved is to develop JAVA applications that enhance dictionaries and dictionaries with JADT. Part 2 provides a detailed investigation of architecture and API.

JADT Overview JADT is an API for accessing dictionary data from Java programming languages. It provides a universal interface that can be used in the Java application, an implementation of a dictionary / data provider. Using JADT, use the application written in Java language to access the definition, pronunciation, synonym, antonym of a particular word, etc.

JADT features include:

Access Dictionary, Dictionary, and Other Services Interface Multilingual Conversion Interface Based on Drivers Access Protocols for Dictionary Providers and Driver Developers Accessing backend dictionaries or dictionaries, such as databases, file systems, or XML-based files (as long as Implement their drivers)

JADT is a very useful API for dictionary access applications because it provides simple, standard technologies for performing such tasks. It rescued application developers from maintenance data and data access points.

This API implementation is very useful for many applications that use multilingual features, localization and similar features. For example, when editing, editing can be spell check with this technology, or get more suitable words. Another example application may be, let applications that need to be translated can use multilingual dictionaries and dictionaries.

In addition, JADT also provides a language-neutral interface that allows it to be used in various languages ​​and dialects. Moreover, since ADT is written in Java language, its sample driver is also implemented in Java language, so it is a platform-independent.

JADT data structures JADT include a variety of different components and services, depending on the characteristics or specific subsets of the JADT used. The first stop of your JADT journey is a group and interface that provides a general method of data organization. Because all services use these data structures, JADT users understand their understanding is very important.

The word list WordList class is a word container. It does not take data from backend resources. WordList is generally used to pass, acquire or contain words that groups. In addition, there is an option to find all words that meet specific rules. For example, it is currently supporting words with similar prefixes or suffixes, supporting the word lookup of some substrings. It is different from the WordLister service because it does not get words from the background resource, so it is just a packaging class. It can also be used for word collection, as shown in Listing: Listing 1. WordList as a collection

WordList WordList = WordLister.FindWithPrefix ("un");

// Getting Collection of Words One by one

WordList.start ();

While (WordList.haASMorewords ())

{

Word word = wordList.getnext ();

}

// using wordlist further to narrow down the search

WordList WordList2 = WordList.FindWithsuffix ("ing");

The word Word interface represents a language unit or a character that can be identified. Word Pack the word information. The information saved in Word includes a word spelling, type, source, pronunciation, and record. Once a Word object is obtained from a service, you can easily use its method to extract information, as shown in Listing 2:

Listing 2. Extract data with Word

Word word = wordList.getnext ();

String strname = word.getWord ();

Dictionary record DictionaryRecord object saves the additional information of words. DictionaryRecord is usually used to represent a word result set for a service that the JADT driver implemented. The message is saved in the record, such as its description, type, usage, area, pronunciation, and more. Because DictionaryRecord is implemented as a chainedObject, it is possible to obtain multi-group word information in the form of a series of objects. This technique can be used for a set of services, such as Listing 3:

Listing 3. Usage of DictionaryRecord

DictionaryRecord DR = Dict.getMeaning ("Dictionary");

Dr.start ();

While (DR! = null)

{

String strname = Dr.GetWordName ();

String pronunciation = Dr.getPronunciation ();

String Type = Dr.gettype ();

String meaning = Dr.getdescription ();

DR = Dr.getNextRecord ();

}

JADT drivers are as long as I have said earlier, JADT provides a driver-based access mechanism, so Java applications can work independently of the implementation provider. In order to do this, the JADT driver needs to be able to communicate with the specific data sources being accessed. You can send the user to the data source through a driver service, you can also send the result of these statements to the user.

Realizing the provider is responsible for jadtdriver, the JADT driver is responsible for extracting and providing the data you need.

JADT has two default drivers for two different data sources that are bound to JADT APIs. These two drivers are JadtTextDriver, which is implemented for language data saved in text format, and JADTXMLDRIVER is implemented for language data saved in XML format. Control Process JADT API defines programming models for accessing Jadtdriver services. Java application developers must use Jadtdriver in accordance with protocol. So the simplest process of JADT service access code must be:

Load JadtdriverFactory: When calling class.Forname ("com.ibm.jadtdrivers.textdriver.jadttextdriverfactory); JADTDriverFactory will automatically register on the driver when loading jaddriverfactory. JADTDRIVERFAACTORY: JADTDRIVERFAACTORY: JadtdriverFactory is a production plant of various drivers and has been controlled by JadtdriverFactoryManager. So you can call JadtdriverFactory FAC = JaddriverFactoryManager.getjadtdriverFactory ("JadtTextDriverFactory); JADTDRIVERFAACTORY. Generating JADT drivers: JADT drivers provide access to various services, such as dictionaries, dictionaries, spelling, words, translators, grammar inspections, and phrasers. You can call the factory's CREATEJADTDRIVER () method to create it:

Driver dri = fac.createjadtdriver ();

Set the properties of the driver: Driver Properties are announced by the driver provider. For example, it is important for text and XML drivers that users need to set the path to the data directory, which can be used with Driver.SetProperty, "C: // DataDir"); complete. If this path is not set, the default value is used, the default value is the path to the driver class.

Now you can start using driver services for all languages ​​supported by the driver.

Access the Dictionary Dictionary is one of the most important services provided by the JADT driver, both text and XML drivers support this service. You can use the following statement to get a dictionary of a specific language from the driver:

Dictionary Dict = Driver.getDictionary ("English", "English");

The getMeaning () method extracts DictionaryRecord for each word you specified, which contains multiple meanings of words. Listing 4 shows the usage of the dictionary:

Listing 4. Usage of dictionary

DictionaryRecord DR = Dict.getMeaning ("Dictionary");

Dr.start ();

While (DR! = null)

{

String strname = Dr.GetWordName ();

String pronunciation = Dr.getPronunciation ();

String Type = Dr.gettype ();

String meaning = Dr.getdescription ();

DR = Dr.getNextRecord ();

}

Dictionary Wordbook is a service component that provides a list of related words classification, which provides information about all related words. These words can be associated with indicators such as usage, source, pronunciation. You can access this service from the driver with the following code:

Wordbook Wordbook = Driver.GetWordbook ("English");

Both text and XML drivers support this service.

The current version of JADT provides an interface that implements the following services:

Synonym synonyms refer to two words that can be used interchangeably in a given context. There are two ways to provide this service:

GetSynyms () is used to get synonyms. Issynynyms () is used to determine whether two words are synonymous.

Listing 5 shows how to use:

Listing 5. Dictionary of checking synonyms

DictionaryRecord Dr = this.wordbook.getsynynyms ("Dictionary");

While (DR! = null)

{

String strname = Dr.GetWordName ();

DR = Dr.getNextRecord ();

}

IF (Wordbook.issynonyms ("Dictionary", "Lexicon"))

{

/*..

}

Other services in this section can also use the same technique, so I don't demonstrate each service.

Antonyms Antonyms refers to two words that are opposite. Using Wordbook, you can check if the meaning of words is the opposite, or you can find all the antonyms of the word. Similarly, there are two ways to provide this service:

Getantonyms () is used to get antonym. Isantonyms () is used to determine whether two words are meaningless.

The upper word is the word "Hypernyms" refers to the word large or general concept. "Computer" or "fruit" is the upper word relative to more specific terms (such as "Dell" or "Banana"). You can use Wordbook to get all the last words, or whether the word is the last word. There are two ways to provide this service:

gethypernym () is used to get the last word ishypernym () used to determine if the two words are host

The next word is the word, "Hyponyms) refers to a more specific word or concept. A proprietary noun is a good example of the next word. "North America" ​​or "Mercedes" is the next word "Continent" or "Automobile".

You can use Wordbook to check the word is the next word, you can also find all the following words of the specified word. There are two ways to provide this service:

GethyPonym () is used to get the next word ISHYPONYM () to determine if the two words are under the following words

The overall noun is the overall noun, and the specified word is an integral part. For example "HAT" is the overall noun "Brim" and "Crown". There are two ways to provide this service:

getholonym () used to get the overall noun Isholonym () used to determine if the two words are overall

Some of the noun sections (Meronyms) represent part of the specified word. For example, "brim" and "crown" are some nouns "HAT". There are two ways to provide this service:

getmeronym () used to get some nouns ismeronym () used to determine if the two words are part of the noun

Using the spell checker You can use SpellChecker to capture the words that are missing. For editor, IDE, and other word processing applications, it is a very useful tool.

You can get a service instance from the driver to access SpellChecker as shown below. Text and XML drivers support this service: SpellChecker SpellChecker = Driver.getspellChecker ("English");

JADT's SpellChecher provides the following features:

Find the word correct: call the SpellChecker's check () method, the method uses words as parameters, return to Boolean:

System.out.println ("Word Dictionar is right spelling" SpellChecker.check

(New TextWord ("Dictionar")))

Find the correct form of words: Call the CorRect () method of SpellChecker, the method uses words as a parameter, returns DictionaryRecord:

DictionaryRecord Dr = SPELLCHECKER.CORRECT (New Textword ("Dictionar");

IF (DR! = null)

System.out.Println ("Correct Spelling Of Dictionar IS" DR);

Find similar words: Calling SpellChecker's suggestsimilar () method, this method uses words as a parameter, returns DictionaryRecord:

DictionaryRecord Dr = SpellChecker. Suggestsimilar (New Textword ("Dictionar");

System.out.println ("Words Similar to Dictionar Are:");

Dr.start ();

While (Dr.haASMoreWords ())

System.out.println (Dr.getNext ());

Use the word table WordLister to allow you to get words from the backend resource. JADT's WordLister also provides an option that looks for all words that meet a certain rule.

You can use the following statement to access this service from the driver:

WordLister WordLister = Driver.getWordLister ("English");

Currently, it supports searching words:

Similar prefix: Returns the word starting with the same prefix:

WordList DR = WordLister.FindWithPrefix ("Perf");

System.out.println ("Words with prefix /" perf / "all:");

IF (DR == null) return;

Dr.start ();

While (Dr.haASMoreWords ())

{

System.out.println (Dr.getNext ());

}

Similar suffix: Returns the word ended with the same word suffix:

WordList Dr = WordLister.FindWithsuffix ("CES");

System.out.println ("Words with Suffix /" CES / "Are:");

IF (DR == null) return;

Dr.start ();

While (Dr.haASMoreWords ())

{

System.out.println (Dr.getNext ());}

Share some subtrings: Returns the word containing the same word:

WordList Dr = WordLister.FindWithsubstring ("Tiona");

System.out.println ("Words with substring /" ces / "are:");

IF (DR == null) return;

Dr.start ();

While (Dr.haASMoreWords ())

{

System.out.println (Dr.getNext ());

}

The use of the word displacement displaced word is a word or phrase obtained by rearrangement words or phrases. Anagrammizer is used to obtain a word consisting of the same character, which is very useful for text game applications. Using Anagrammizer, you can judge that each word is not a variation word, or all displaced words that specify the word.

You can use the following statement to access this service from the driver:

Anagrammizer Anagram = Driver.Getanagrammizer ("English");

There are two ways to provide this service:

Anagrammise () used to get displaced ISANAGRAM () is used to determine if two words are variable

These methods can be used as shown in Listing 6:

Listing 6. Anagrammizer Usage

DictionaryRecord Dr = this.wordbook.anagrammise (New Textword ("Clear");

While (DR! = null)

{

String strname = Dr.GetWordName ();

DR = Dr.getNextRecord ();

}

IF (Wordbook. Isanagram ("Clear", "CLARE"))

{

/*..

}

Use the Syntax Checker GrammarChecker Check that the arrangement of words in the sentence is allowed, check whether the use of words in a particular context is correct. Similarly, this service can be used in publishing and word processing applications.

You can use the following statement to access this service from the driver:

Grammarchecker grammarchecker = YourDriver.getgrammarchecker ("english");

With JADT's grammarchecker, you can:

Use the check () method to determine if the correct syntax is used with a Correct () method correction syntax with the suggestsimilar () method to correct the syntax in a specific context environment.

Use translator Translator to convert words or sentences from a language into another language. This feature can be used in localization and international implementation. With this characteristics, the resource binding file written in a language can be converted into another language.

You can access this service from the driver with the following code:

Translator translator = youdriver.gettranslator ("English", "French");

With JADT's Translator, you can:

Use the translate () method to translate words into a second language. Use the translationsencept () method to translate the sentence into a second language.

JADT Application Example JADT also has a sample application that demonstrates the characteristics of JadTTextDriver and Jadxmldriver drivers.

To perform an example application, call Java Com.ibm.jadtsample.jadtsampleApplication to open the application, the effect of running is shown in Figure 1: Figure 1. Sample application screen

Make sure you are executing the Java com.ibm.jadtsample.jadtsampleApplication command in the directory deployed by the resource file.

After reading this article, you should have a good understanding from the user's angle for Java Dictionary and Dictionary API. Specifically, you learned the basic JADT structure, learn how to use different JADT services and components, create Java applications with words related to words.

In Part 2 of this series, I will visit JADT from the perspective of the dictionary provider, showing how they can implement JADT for the dictionary and word data.

Reference

You can see this article in our website on our world. Download The Dictionary and the the Dictionary and thisaurus API for Java from AlphaWorks.don't Miss Part 2 of this Series Download IBM XML4J from AlphaWorks from AlphaWorks. More Java technology resources can be found on the developerWorks Java technology zone. Please visit developer bookstore to get a complete list of technical books, including hundreds of Java-related topics. Is it interested in IBM test products that don't require usually high cost entrance (Entry Point) or short-term evaluation licenses? DeveloperWorks Kit provides a low-cost 12-month single-user license for WebSphere, DB2, Lotus, Rational, and Tivoli products, including Eclipse-based WebSphere Studio IDE for development, testing, evaluation, and showing your application.

About the author Rakesh Midha is a software engineer of the IBM software laboratory of Bangalore. He is currently engaged in IBM WebSphere Business Components Development. He has 5 years of experience in programming Java and C server-side programming on multi-platform and various relational database systems (like DB2 UDB, Oracle, MySQL, and Microsoft SQL Server). His expertise is included in banks, finance, cataloging industries, and orders and warehousing management systems. Independent and N-layer distributed systems. He received a bachelor's degree from the Electronic Engineering from Chandigarh's Punjab University, which is a technical expert in Java dictionary and dictionary. This technology is started by IBM AlphaWorks.

转载请注明原文地址:https://www.9cbs.com/read-105859.html

New Post(0)