API-Application Programming Interface Presented By: Konkani NLP Team Goa University Brief Outline • API’s IndoWordNet API Layers of API Sample API codes API’s • An Application Programming Interface (API) is a set of commands, functions and protocols which programmers can use when building a software. • It allows the programmers to use predefined functions to interact with systems, instead of writing them from scratch. • Characteristics of good API – Easy to learn and use, Hard to misuse. – Easy to read and maintain code that uses it. – Is programming language neutral. – Sufficiently powerful to support all computational requirements. IndoWordNet Database Design 3 IndoWordNet API • It allows a user to access wordnet database and to create wordnet tools without the knowledge of the underlying database design. • The API is object-oriented design. • The API is designed in such a way that it supports single/ multiple languages. • The API is designed in two layers: – Application layer – Database layer IndoWordNet Database Design 4 Implementation of API’s is done in: JAVA Php Database layer • The Database layer deals with encapsulation of the database design. • It provides a standard interface to the application layer. • The Database layer supports all the operations needed to be performed on the database. IndoWordNet Database Design 6 Database Layer consists of the following classes: – IWDb • A class that connects to the Database. – IWCon • A class that sets up a connection to a database – IWStatement • A class which contains all the queries pertaining to the application layer • Also the basic functions such as updating, deletion, insertion, selection, etc. – IWResult • A class which returns results to the application layer, the results of executed queries IndoWordNet Database Design 7 Application layer • The Application layer incorporates the logical part of the IndoWordNet requirements, so as to provide classes and objects to perform all the operations to be performed on the synset, relations, ontology, other master data, etc. • The Application Layer allows us to perform operations such as: – get all the synsets – get all words – get all synsets from a given start id to a given end id – get various relations for a given synset/ word – get words for a given synset – add a new source or domain, a new relation – to create sysnet, to create words, – update the records in the table – delete a synset/ source/ domain – modify ontology information – Etc… IndoWordNet Database Design 8 Application Layer consists of the following classes: – IWAPIClass • A class that allows to initialise API library for use. • Maintain master tables. • Manage connectivity to language specific databases. – IWSynset • A class that represents a Synset – IWWord • A class that represents a Word – IWSynsetCollection • Collection of Synsets – IWWordCollection • Collection of words for a synset – IWOntology • A class that represents Ontology • Each synset is mapped into some place in the ontology tree IndoWordNet Database Design 9 – IWOntologyCollection • Collection of child nodes for a given onto node – IWExampleCollection • Collection of examples – IWFile • A class that represents a File – IWDataFile • A class that represents a data file – IWPictureFile • A class that represents a picture files – IWFileCollection • Collection of files IndoWordNet Database Design 10 Where to copy the API sample codes – For java: Open the sampleCodesInJava folder in Netbeans and import the libraries from the lib folder. – For Php: Copy the sampleCodesInPhp Folder in htdocs and open it in Netbeans IndoWordNet Database Design 11 • IWAPIClass – – – – – – – – – – – – – – A class that allows initialising API library for use, Maintains master tables, Manage connectivity to language specific databases, A class that allows to get all synsets from the database, It consists of all the language database names, the various antonymy property values, meronymy_holonymy property values, etc... To create new synsets, To get synsets belonging to a domain, To get synset belonging to a grammatical category, To get synsets belonging to a given source, To get synsets for a given range of Id’s, To get all files, To create a new word, new source, new domain, new category, etc… To destroy a synset, word, relation, Etc… • The object of the IWAPIClass is declared as follows: In Java: IWAPIClass apiObject = new IWAPIClass("root", ""); IWDb dbObj = apiObject.connectLanguageDb(IWAPIClass.KONKANI); In Php: $apiObject = new IWAPIClass("root", ""); $dbObj = $apiObject->connectLanguageDb(IWAPIClass::$KONKANI); Where “root” is the username of the database, password is “”. It will connect to the master database. • IWSynset – A class that represents a Synset. – To get the concept, translated concept, transliterated concept of a given synset which is present in the database. – To get words and relations of a given synset. – To get examples belonging to a synset. – To get the category, domain, source, concept of a given synset present in the database. – To add examples, files and various semantic relations to a synset. – To remove semantic relations. – To set a new concept, a new category, a new domain for a synset. – Etc… • The object of the IWSynset is declared as follows: In Java: IWSynset synsetObject = new IWSynset (dbObject, synset_id); In Php: $synsetObject = new IWSynset ($dbObject, $synset_id); • IWSynsetCollection – A class that represent a Collection of Synset. – To get the length of the collection i.e the number of synsets present in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous(); last(); respectively. – To get the current element, use getElement(); • IWWord – A class that represents a Word. – To get various lexical relation such as antonymy relation, compounding relation, gradation relation, etc. – To get all the synsets for a given word. – To get the lex id. – To remove lexical relations for specified synset and word. – Etc… • IWWordCollection – A class that represent a Collection of words for a synset. – To get the length of the collection i.e the number of words present in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous();and last(); respectively. – To get the current element, use getElement(); • IWExampleCollection – Collection of examples for a synset. – To get the length of the collection i.e the number of examples present in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous();and last(); respectively. – To get the current element, use getElement(); • IWOntology – A class that represents Ontology node. – Each synset is mapped into some place in the ontology tree. – To get ontology Id, use getOntologyID(); – To get ontology data, ontology translated data, ontology transliterated data, use getOntologyData(); getOntologyTranslatedData(); and getOntologyTransliteratedData(); – To get ontology description, ontology translated description, ontology transliterated description, use getOntologyDescription(); getOntologyTranslatedDescription(); and getOntologyTransliteratedDescription(); – To set ontology data, ontology translated data, ontology transliterated data, use setOntologyData(); setOntologyTranslatedData(); and setOntologyTransliteratedData(); – To set ontology description, ontology translated description, ontology transliterated description, use setOntologyDescription(); setOntologyTranslatedDescription(); and setOntologyTransliteratedDescription(); – Etc… • IWOntologyCollection – Collection of child nodes for a given onto node. – To get the length of the collection i.e the number of ontology nodes present in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous();and last(); respectively. – To get the current element, use getElement(); • IWFile – A class that represents Files. – To get the file content, to get the file Id, to get file size, to get file type. – To set a new file type, to set a new file name. – Etc... • IWFileCollection – Collection of files. – To get the length of the collection i.e the number of files in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous();and last(); respectively. – To get the current element, use getElement(); • IWAntonymyCollection – Collection of words belonging to a synset having antonymy relation for a given synset and lex words. – To get the length of the collection i.e the number of antonymy relation for a given synset and lex word present in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous(); and last(); respectively. – To get the current element, use getElement(); – To get anto word and anto synset use getAntoWord(); and getAntoSynset(); respectively. – To get the antonymy property value, use getAntonymyValue(); • IWGradationCollection – A collection of gradation relation obtained for a given synset and lex words. – To get the gradation property for a given synset and lex words, use getGradationValue(); – To get the length of the collection i.e the number of gradation relation for a given synset and lex word present in the collection, use length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous(); and last(); respectively. – To get the current element, use getElement(); – To get the mid lex word and to get the last lex word use getMidLexWord(); and getLastLexWord(); respectively. – To get the mid synset and to get the last synset use getMidSynset(); and getLastSynset(); respectively. • IWLexicalRelationCollection – Collection of Lexical relation for a given word. – The different types of lexical relations are: antonymy (opposites), gradation, compounding, conjunction, etc. – To get the length of the collection using length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous(); and last(); respectively. – To get the current element, use getElement(); – To get the lex word and synset id, use getLexWord(); and getSynsetID() respectively. • IWMeroHoloCollection – Collection of Meronymy Holonymy relation for a given synset. – To get the Meronymy_holonymy property value, use getMeroHoloValue(); – To get the length of the collection using length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous(); and last(); respectively. – To get the current element, use getElement(); • IWNounVerbLinkCollection – Collection of NounVerbLink relation for a given synset. – To get the link property value getLinkValue(); – To get the length of the collection using length(); – To get the first element from the collection, the next element from the collection, the previous element from the collection and the last element from the collection, use first(); next(); previous(); and last(); respectively. – To get the current element, use getElement(); – To get NounVerbSynsetId, use getNounVerbSynsetID(); Questions? IndoWordNet Database Design 29 THANK YOU IndoWordNet Database Design 30