package aminePlatform.samples.buildOntology; /******************************************************************* Amine - Artificial Intelligence platform for the development of Intelligent Systems. Copyright (C) 2004 AmineGroup. GNU Lesser General Public License This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *********************************************************************/ import java.util.*; import java.awt.event.*; import java.io.File; import aminePlatform.kernel.lexicons.*; import aminePlatform.kernel.ontology.*; import aminePlatform.util.AmineObjects; import aminePlatform.util.cg.*; import aminePlatform.util.parserGenerator.*; import aminePlatform.guis.util.*; /** *
Title : BuildFinanceOntology Sample class
*Description : This class builds an ontology that is an adaptation of a subset of a Knowledge Base * in Finace developed by Pavlin Dobrev and al. (www.ksl.stanford.edu/iccs2001/CGTools).
* @author Karim Bouzoubaa * @version 2 */ public class BuildFinanceOntology { public BuildFinanceOntology() { ArrayList languages = new ArrayList(); Identifier english = new Identifier("English"); Identifier rootIdentifier = new Identifier("Universal"); Identifier rootRelIdentifier = new Identifier("Relation"); try { // The first steps for the creation of a LexiconsOntology // Create ontology with an English lexicon Ontology ontology = new Ontology(rootIdentifier, rootRelIdentifier, english); Lexicon englishLexicon = ontology.getLexicon(english); // Enter SubTypes of a Type. If you have several subtypes, use nn array // like shown below // Build the ontology Type Hierarchy Identifier entity = new Identifier("entity"); Identifier others = new Identifier("others"); Object[] objs = {entity, others}; englishLexicon.linkSubTypesToType(objs, rootIdentifier); // Addition of relations types, as subtypes of the type "relation" Identifier trade = new Identifier("trade"); objs = new Object[] { new Identifier("agnt"), new Identifier("attr"), new Identifier("operate_with"), new Identifier("provide"), new Identifier("loc"), new Identifier("thm"), trade, new Identifier("raise"), new Identifier("of"), new Identifier("goal"), new Identifier("rcpt"), new Identifier("poss"), new Identifier("convert_into"), new Identifier("dim"), new Identifier("manr"), new Identifier("method"), new Identifier("obj"), new Identifier("char"), new Identifier("buy"), new Identifier("sell"), new Identifier("support"), new Identifier("agnt_seller"), new Identifier("agnt_buyer"), new Identifier("operate_with_security"), new Identifier("operate_with_loan"), }; englishLexicon.linkSubTypesToType(objs, rootRelIdentifier); // add subtypes to the type "others" Identifier investment = new Identifier("investment"); Identifier money_value = new Identifier("money_value"); Identifier range = new Identifier("range"); Identifier direct = new Identifier("direct"); objs = new Object[] { new Identifier("buyer"), new Identifier("seller"), new Identifier("new"), new Identifier("newly_issued"), new Identifier("already_issued"), new Identifier("trade"), new Identifier("loan"), new Identifier("cash"), new Identifier("access"), new Identifier("free"), new Identifier("capital"), money_value, new Identifier("short_term"), new Identifier("long_term"), new Identifier("size"), new Identifier("broad"), new Identifier("bargain"), new Identifier("situation"), new Identifier("investor"), new Identifier("lender"), new Identifier("maturity"), new Identifier("borrower"), investment, new Identifier("money_market_investment"), range, direct }; englishLexicon.linkSubTypesToType(objs, others); // idem Identifier financial_instrument = new Identifier("financial_instrument"); Identifier organization = new Identifier("organization"); objs = new Object[] {financial_instrument, organization}; englishLexicon.linkSubTypesToType(objs, entity); Identifier certificate = new Identifier("certificate"); Identifier commercial_paper = new Identifier("commercial_paper"); Identifier bankers_acceptance = new Identifier("banker's_acceptance"); Identifier contract = new Identifier("contract"); Identifier debt_instrument = new Identifier("debt_instrument"); Identifier security = new Identifier("security"); objs = new Object[] {certificate, commercial_paper, bankers_acceptance, contract, debt_instrument, security}; englishLexicon.linkSubTypesToType(objs, financial_instrument); Identifier certificate_of_deposit = new Identifier("certificate_of_deposit"); objs = new Object[] {certificate_of_deposit}; englishLexicon.linkSubTypesToType(objs, certificate); Identifier negotiable_certificate_of_deposit = new Identifier("negotiable_certificate_of_deposit"); objs = new Object[] {negotiable_certificate_of_deposit}; englishLexicon.linkSubTypesToType(objs, certificate_of_deposit); Identifier option_contract = new Identifier("option_contract"); Identifier futures_contract = new Identifier("futures_contract"); Identifier foward_contract = new Identifier("foward_contract"); objs = new Object[] {option_contract, futures_contract, foward_contract}; englishLexicon.linkSubTypesToType(objs, contract); Identifier stock_option = new Identifier("stock_option"); Identifier european_stock_option = new Identifier("european_stock_option"); Identifier index_option = new Identifier("index_option"); Identifier american_standard_option = new Identifier("american_standard_option"); Identifier call_option = new Identifier("call_option"); Identifier put_option = new Identifier("put_option"); objs = new Object[] {stock_option, european_stock_option, index_option, american_standard_option, call_option, put_option}; englishLexicon.linkSubTypesToType(objs, option_contract); Identifier agricultural_futures_contract = new Identifier("agricultural_futures_contract"); Identifier metallurgical_futures_contract = new Identifier("metallurgical_futures_contract"); objs = new Object[] {agricultural_futures_contract, metallurgical_futures_contract}; englishLexicon.linkSubTypesToType(objs, futures_contract); Identifier loan = new Identifier("loan"); Identifier bond = new Identifier("bond"); objs = new Object[] {loan, bond}; englishLexicon.linkSubTypesToType(objs, debt_instrument); Identifier multiplier_bond = new Identifier("multiplier_bond"); Identifier compound_interest_bond = new Identifier("compound_interest_bond"); Identifier zero_coupon_bond = new Identifier("zero_coupon_bond"); Identifier convertible_bond = new Identifier("convertible_bond"); Identifier municipal_bond = new Identifier("municipal_bond"); Identifier non_tax_exempt_bond = new Identifier("non_tax_exempt_bond"); Identifier tax_exempt_bond = new Identifier("tax_exempt_bond"); Identifier non_callable_bond = new Identifier("non_callable_bond"); Identifier callable_bond = new Identifier("callable_bond"); Identifier put_bond = new Identifier("put_bond"); Identifier coupon_bond = new Identifier("coupon_bond"); Identifier income_bond = new Identifier("income_bond"); Identifier registered_bond = new Identifier("registered_bond"); Identifier subordinated_bond = new Identifier("subordinated_bond"); Identifier corporate_bond = new Identifier("corporate_bond"); Identifier serial_bond = new Identifier("serial_bond"); Identifier senior_bond = new Identifier("senior_bond"); Identifier agency_bond = new Identifier("agency_bond"); Identifier government_bond = new Identifier("government_bond"); objs = new Object[] {multiplier_bond, compound_interest_bond, zero_coupon_bond, convertible_bond, municipal_bond, non_tax_exempt_bond, tax_exempt_bond, non_callable_bond, callable_bond, put_bond, coupon_bond, income_bond, registered_bond, subordinated_bond, corporate_bond, serial_bond, senior_bond, agency_bond, government_bond}; englishLexicon.linkSubTypesToType(objs, bond); Identifier housing_bond = new Identifier("housing_bond"); Identifier municipal_note = new Identifier("municipal_note"); Identifier moral_obligation_bond = new Identifier("moral_obligation_bond"); Identifier limited_and_special_tax_bond = new Identifier("limited_and_special_tax_bond"); Identifier insured_municipal_bond = new Identifier("insured_municipal_bond"); Identifier revenue_bond = new Identifier("revenue_bond"); Identifier general_obligation_bond = new Identifier("general_obligation_bond"); Identifier double_barreled_bond = new Identifier("double_barreled_bond"); objs = new Object[] {housing_bond, municipal_note, moral_obligation_bond, limited_and_special_tax_bond, insured_municipal_bond, revenue_bond, general_obligation_bond, double_barreled_bond}; englishLexicon.linkSubTypesToType(objs, municipal_bond); Identifier tax_anticipation_note = new Identifier("tax_anticipation_note"); Identifier bond_anticipation_note = new Identifier("bond_anticipation_note"); Identifier revenue_anticipation_note = new Identifier("revenue_anticipation_note"); objs = new Object[] {tax_anticipation_note, bond_anticipation_note, revenue_anticipation_note}; englishLexicon.linkSubTypesToType(objs, municipal_note); Identifier industrial_revenue_bond = new Identifier("industrial_revenue_bond"); objs = new Object[] {industrial_revenue_bond}; englishLexicon.linkSubTypesToType(objs, revenue_bond); Identifier bearer_bond = new Identifier("bearer_bond"); Identifier partiallay_registered_bond = new Identifier("partiallay_registered_bond"); objs = new Object[] {bearer_bond, partiallay_registered_bond}; englishLexicon.linkSubTypesToType(objs, coupon_bond); objs = new Object[] {partiallay_registered_bond}; englishLexicon.linkSubTypesToType(objs, registered_bond); Identifier secure_bond = new Identifier("secure_bond"); Identifier unsecured_bond = new Identifier("unsecured_bond"); Identifier samuraibond = new Identifier("samuraibond"); Identifier junk_bond = new Identifier("junk_bond"); Identifier gilt_edged_bond = new Identifier("gilt_edged_bond"); Identifier bulldog_bond = new Identifier("bulldog_bond"); objs = new Object[] {secure_bond, unsecured_bond, samuraibond, junk_bond, gilt_edged_bond, bulldog_bond}; englishLexicon.linkSubTypesToType(objs, corporate_bond); Identifier equipment_trust_certificate = new Identifier("equipment_trust_certificate"); objs = new Object[] {equipment_trust_certificate}; englishLexicon.linkSubTypesToType(objs, serial_bond); Identifier mortgage_bond = new Identifier("mortgage_bond"); objs = new Object[] {equipment_trust_certificate, mortgage_bond}; englishLexicon.linkSubTypesToType(objs, senior_bond); Identifier open_end_mortgage_bond = new Identifier("open_end_mortgage_bond"); Identifier close_end_mortgage_bond = new Identifier("close_end_mortgage_bond"); objs = new Object[] {open_end_mortgage_bond, close_end_mortgage_bond}; englishLexicon.linkSubTypesToType(objs, mortgage_bond); Identifier federal_agency_bond = new Identifier("federal_agency_bond"); objs = new Object[] {federal_agency_bond}; englishLexicon.linkSubTypesToType(objs, agency_bond); Identifier gilt = new Identifier("gilt"); Identifier ustreasuries = new Identifier("u.s.treasuries"); Identifier savings_bond = new Identifier("savings_bond"); Identifier eurobond = new Identifier("eurobond"); objs = new Object[] {federal_agency_bond, gilt, ustreasuries, savings_bond, eurobond}; englishLexicon.linkSubTypesToType(objs, government_bond); Identifier ustreasury_bill = new Identifier("u.s.treasury_bill"); Identifier ustreasury_note = new Identifier("u.s.treasury_note"); Identifier ustreasury_bond = new Identifier("u.s.treasury_bond"); objs = new Object[] {ustreasury_bill, ustreasury_note, ustreasury_bond}; englishLexicon.linkSubTypesToType(objs, ustreasuries); Identifier fixed_interest_security = new Identifier("fixed_interest_security"); Identifier floating_rate_security = new Identifier("floating_rate_security"); Identifier hybrid_security = new Identifier("hybrid_security"); Identifier asset_backed_security = new Identifier("asset_backed_security"); Identifier mortgage_backed_security = new Identifier("mortgage_backed_security"); Identifier stock = new Identifier("stock"); objs = new Object[] {fixed_interest_security, floating_rate_security, hybrid_security, asset_backed_security, mortgage_backed_security, stock}; englishLexicon.linkSubTypesToType(objs, security); Identifier growth_stock = new Identifier("growth_stock"); Identifier speculative_stock = new Identifier("speculative_stock"); Identifier defnsive_stock = new Identifier("defnsive_stock"); Identifier cyclical_stock = new Identifier("cyclical_stock"); Identifier common_stock = new Identifier("common_stock"); Identifier prefered_stock = new Identifier("prefered_stock"); Identifier unlisted_stock = new Identifier("unlisted_stock"); Identifier listed_stock = new Identifier("listed_stock"); Identifier blue_chip_stock = new Identifier("blue_chip_stock"); objs = new Object[] {growth_stock, speculative_stock, defnsive_stock, cyclical_stock, common_stock, prefered_stock, unlisted_stock, listed_stock, blue_chip_stock}; englishLexicon.linkSubTypesToType(objs, stock); Identifier cummulative_prefered_stock = new Identifier("cummulative_prefered_stock"); Identifier non_cumulative_prefered_stock = new Identifier("non_cumulative_prefered_stock"); objs = new Object[] {cummulative_prefered_stock, non_cumulative_prefered_stock}; englishLexicon.linkSubTypesToType(objs, prefered_stock); Identifier option_clearing_corporation = new Identifier("option_clearing_corporation"); Identifier company = new Identifier("company"); Identifier corporation = new Identifier("corporation"); Identifier self_regulatory_organization = new Identifier("self_regulatory_organization"); Identifier security_and_exchange_commission = new Identifier("security_and_exchange_commission"); Identifier market = new Identifier("market"); Identifier usa_federal_reserve = new Identifier("usa_federal_reserve"); Identifier commodity_futures_trading_commission = new Identifier("commodity_futures_trading_commission"); Identifier government = new Identifier("government"); Identifier brokerage_firm = new Identifier("brokerage_firm"); Identifier government_agency = new Identifier("government_agency"); Identifier bank = new Identifier("bank"); objs = new Object[] {option_clearing_corporation, company, corporation, self_regulatory_organization, security_and_exchange_commission, market, usa_federal_reserve, commodity_futures_trading_commission, government, brokerage_firm, government_agency, bank}; englishLexicon.linkSubTypesToType(objs, organization); Identifier forward_market = new Identifier("forward_market"); Identifier stock_market = new Identifier("stock_market"); objs = new Object[] {forward_market, stock_market}; englishLexicon.linkSubTypesToType(objs, self_regulatory_organization); Identifier stock_exchange = new Identifier("stock_exchange"); objs = new Object[] {stock_exchange}; englishLexicon.linkSubTypesToType(objs, stock_market); Identifier nyse = new Identifier("nyse"); Identifier nasd = new Identifier("nasd"); Identifier amex = new Identifier("amex"); objs = new Object[] {nyse, nasd, amex}; englishLexicon.linkSubTypesToType(objs, stock_exchange); Identifier financial_market = new Identifier("financial_market"); objs = new Object[] {financial_market}; englishLexicon.linkSubTypesToType(objs, market); Identifier secondary_market = new Identifier("secondary_market"); Identifier primary_market = new Identifier("primary_market"); Identifier negotiated_market = new Identifier("negotiated_market"); Identifier capital_market = new Identifier("capital_market"); Identifier money_market = new Identifier("money_market"); Identifier open_market = new Identifier("open_market"); Identifier spot_market = new Identifier("spot_market"); Identifier bond_market = new Identifier("bond_market"); objs = new Object[] {stock_market, secondary_market, primary_market, negotiated_market, capital_market, money_market, open_market, spot_market, bond_market}; englishLexicon.linkSubTypesToType(objs, financial_market); Identifier municipal_government = new Identifier("municipal_government"); Identifier national_government = new Identifier("national_government"); objs = new Object[] {municipal_government, national_government}; englishLexicon.linkSubTypesToType(objs, government); Identifier state_government = new Identifier("state_government"); Identifier local_government = new Identifier("local_government"); objs = new Object[] {state_government, local_government}; englishLexicon.linkSubTypesToType(objs, municipal_government); Identifier investment_bank = new Identifier("investment_bank"); objs = new Object[] {investment_bank}; englishLexicon.linkSubTypesToType(objs, bank); // Associate Conceptual Structures to Types // First we should get the Conceptual Structure node associated to the type identifier. // this is done by the method lexicons#getTypeCS(Identifier) as illustrated below Type primary_marketType = englishLexicon.getTypeCS(primary_market); Type tradeType = englishLexicon.getTypeCS(trade); Type securityType = englishLexicon.getTypeCS(security); Type loanType = englishLexicon.getTypeCS(loan); Type investmentType = englishLexicon.getTypeCS(investment); Type corporate_bondType = englishLexicon.getTypeCS(corporate_bond); Type money_valueType = englishLexicon.getTypeCS(money_value); Type financial_marketType = englishLexicon.getTypeCS(financial_market); Type secondary_marketType = englishLexicon.getTypeCS(secondary_market); Type money_marketType = englishLexicon.getTypeCS(money_market); Type financial_intrumentType = englishLexicon.getTypeCS(financial_instrument); Type capital_marketType = englishLexicon.getTypeCS(capital_market); Type negotiated_marketType = englishLexicon.getTypeCS(negotiated_market); Type open_marketType = englishLexicon.getTypeCS(open_market); // then we add definitions, canons and situations to the various types as shown below. // To set a definition for a type, we specify first the definition body, which is a CG, // as a String and we ask the method parseLF(String, Lexicon) to parse the string and // to return the CG object. This is illustrated below : CG cg = CG.parseLF( "[market:super]<-loc-[trade]-\n" + "-agnt_buyer->[buyer],\n" + "-agnt_seller->[seller],\n" + "-thm->[financial_instrument]" , englishLexicon); // Next, we set the cg that results from the above parsing as a definition for our type (in the // example below financial_marketType) with the method setDefinition() as illustrated below. financial_marketType.setDefinition(cg); // The two instructions above could be reformulated in one instruction, as illustrated below primary_marketType.setDefinition(CG.parseLF( "[financial_market:super]-trade->[financial_instrument]-attr->[newly_issued]" , englishLexicon)); // idem for all your definitions secondary_marketType.setDefinition(CG.parseLF( "[financial_market:super]-operate_with->[security]-attr->[already_issued]" , englishLexicon)); open_marketType.setDefinition(CG.parseLF( "[financial_market:super]-" + "-trade->[security],\n" + "-agnt->[seller]-poss->[access]-attr->[free],\n" + "-rcpt->[buyer]-poss->[access]-attr->[free]" , englishLexicon)); open_marketType.setCanon(CG.parseLF( "[financial_market:super]-" + "-trade->[loan],\n" + "-agnt->[seller]-poss->[access]-attr->[free],\n" + "-rcpt->[buyer]-poss->[access]-attr->[free]" , englishLexicon)); money_marketType.setDefinition(CG.parseLF( "[financial_market:super]-" + "-operate_with_security->[security]-attr->[short_term],\n" + "-operate_with_loan->[loan]-attr->[short_term]" , englishLexicon)); capital_marketType.setDefinition(CG.parseLF( "[investment]-" + "<-trade-[financial_market:super],\n" + "<-agnt-[range]-" + "-manr->[broad],\n" + "-dim->[size];\n" + "-attr->[long_term]" , englishLexicon)); //*** To add situations, we proceed the same way : either with the two instructions // as illustrated below CG s = CG.parseLF( "[newly_issued]<-attr-[stock]<-operate_with-[primary_market]-provide->[investment]-attr->[new]" , englishLexicon); primary_marketType.addSituation(new Situation(s)); // ... or in one instruction like the next example: primary_marketType.addSituation(new Situation(CG.parseLF( "[primary_market]-trade->[security]-attr->[newly_issued]" , englishLexicon))); // idem for all your situations: note that a type can have several // situations, this is illustrated below by the type primary_marketType primary_marketType.addSituation(new Situation(CG.parseLF( "[primary_market]-trade->[loan]-attr->[newly_issued]" , englishLexicon))); primary_marketType.addSituation(new Situation(CG.parseLF( "[primary_market]-provide->[investment]-attr->[new]" , englishLexicon))); primary_marketType.addSituation(new Situation(CG.parseLF( "[primary_market]-trade->[corporate_bond]-attr->[newly_issued]" , englishLexicon))); primary_marketType.addSituation(new Situation(CG.parseLF( "[new]<-attr-[investment]<-provide-[primary_market]-trade->[security]-attr->[newly_issued]" , englishLexicon))); primary_marketType.addSituation(new Situation(CG.parseLF( "[primary_market]-goal->[situation = [primary_market]-raise->[money_value]-of->[capital] ]" , englishLexicon))); primary_marketType.addSituation(new Situation(CG.parseLF( "[primary_market]-provide->[capital]-rcpt->[investment]-attr->[new]" , englishLexicon))); // idem secondary_marketType.addSituation(new Situation(CG.parseLF( "[secondary_market]-trade->[security]-attr->[already_issued]" , englishLexicon))); secondary_marketType.addSituation(new Situation(CG.parseLF( "[secondary_market]-trade->[loan]-attr->[already_issued]" , englishLexicon))); secondary_marketType.addSituation(new Situation(CG.parseLF( "[secondary_market]-provide->[situation = [security]-convert_into->[cash] ]-rcpt->[investor]" , englishLexicon))); secondary_marketType.addSituation(new Situation(CG.parseLF( "[secondary_market]-support->[investment]-attr->[new]" , englishLexicon))); money_marketType.addSituation(new Situation(CG.parseLF( "[money_market]-trade->[security]-attr->[short_term]" , englishLexicon))); money_marketType.addSituation(new Situation(CG.parseLF( "[money_market]-trade->[loan]-attr->[short_term]" , englishLexicon))); money_marketType.addSituation(new Situation(CG.parseLF( "[money_market]-provide->[situation = [money_market_investment]-convert_into->[cash] ]" , englishLexicon))); money_marketType.addSituation(new Situation( CG.parseLF( "[money_market]-" + "-rcpt->[buyer],\n" + "-agnt->[seller],\n" + "-obj->[security]-attr->[short_term]" , englishLexicon))); negotiated_marketType.addSituation(new Situation(CG.parseLF( "[money_market]-" + "-trade->[security],\n" + "-method->[bargain]-" + "-attr->[direct],\n" + "-agnt->[seller],\n" + "-rcpt->[buyer]" , englishLexicon))); negotiated_marketType.addSituation(new Situation(CG.parseLF( "[money_market]-" + "-trade->[loan],\n" + "-method->[bargain]-" + "-attr->[direct],\n" + "-agnt->[seller],\n" + "-rcpt->[buyer]" , englishLexicon))); // Save the new created Lexicons/Ontology in the .ont and in .xml forms // in aminePlatform.samples.ontology. try { // Save the Lexicon/Ontology, by serialisation of Java object(s), in the specified file. ontology.store(AmineFrame.ontologyDirPath + "FinanceOntology.ont"); // Save the Lexicon/Ontology in the specified XML file. ontology.storeInXML(AmineFrame.ontologyDirPath + "FinanceOntology.xml"); } catch (Exception ex){ ex.printStackTrace(); } /************ // Visualize the Ontology (this part is Optional) TextualDisplayOntology txtDsplyOntFrm = new TextualDisplayOntology(ontology); txtDsplyOntFrm.displayOntology(); txtDsplyOntFrm.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); *****************/ } catch (Exception ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); } } }