%%% ========================================================================= %%% FLORID Example: INFORMATION INTEGRATION: %%% %%% Author: Wolfgang May %%% %%% mondial-codes.flp: %%% country names and car-codes in different languages %%% ========================================================================= % ?- sys.theOMAccess.debugOn. % trace Web access ?- sys.theOM.eqTraceOn. % trace derived equalities ?- sys.prn.style@("bound"). % set output mode % /* Define several entry points for the data source: */ % ext[country_codes_mirror -> "file:/home/dbis/.public_html/.mir/terraplus/"; country_codes ->"flags+carcodes.html"]. % /* An auxiliary formatting method is defined, using \Florid's perl interface. */ % format[country_name->"$out[0]=$in[0]; $out[0]=~s|\Athe \s*||g; $out[0]=~s|\AThe \s*||g; $out[0]=~s|\A\s*||g; $out[0]=~s/\s*\Z//g; $out[0]=~s/([^,]*) \(South\)/South $1/g; $out[0]=~s/([^,]*) \(North\)/North $1/g; $out[0]=~s/([^,]*) \(Süd\)/Sued-$1/g; $out[0]=~s/([^,]*) \(Nord\)/Nord $1/g; $out[0]=~s/'//g; $out[0]=~s/Cte/Cote/g; $out[0]=~s/Dnemark/Dänemark/g; $out[0]=~s/Sdafrika/Südafrika/g; $out[0]=~s/\Aquatorial- guinea/Aequatorialguinea/g; $out[0]=~s/\Agypten/Ägypten/g; $out[0]=~s/So Tom/Sao Tome/g; $out[0]=~s/Prncipe/Principe/g; $out[0]=~s/sterreich/Österreich/g; $out[0]=~s/Rumnien/Rumänien/g; $out[0]=~s/Ruland/Russland/g; $out[0]=~s/Grobritannien/Großbritannien/g; $out[0]=~s/Trkei/Türkei/g; $out[0]=~s/Great Britain and Northern Ireland/United Kingdom/g; $out[0]=~s/Luxemburg/Luxembourg/g; $out[0]=~s/Vatican/Holy See/g; $out[0]=~s/United States of America/United States/g; $out[0]=~s/Cape Verte/Cape Verde/g; $out[0]=~s/Yugoslavia/Serbia and Montenegro/g; $out[0]=~s/Comores/Comoros/g; $out[0]=~s/ I\Z//g;"]. % ?- sys.strat.doIt. % /* The page with country names in english, german, and the local name, and the car code is structured as a list of tables for every letter. The page is parsed by the built-in HTML parser, obtaining a parse-tree of the page using a special tagfile (specifying which HTML tags are ignored or pruned). */ % ?- sys.theOMAccess.setTagFile@("mondial-codes.tags"). % U:url.parse :- strcat(ext.country_codes_mirror,ext.country_codes,U). % ?- sys.strat.doIt. ?- sys.echo@("*** Country Codes ***"). % /* The individual tables are extracted */ % tab(N):country_codes_table[thetable->T;nr->N] :- T:(U.parse.table), T = X.html@(N), strcat(ext.country_codes_mirror,ext.country_codes,U). % /* the 0.th column contains the car code, the first column gives the englich name, the third one gives the german name, and the forth one gives the name in the local language. */ % language(1,"english"). language(3,"german"). language(4,"local"). % ctry(N,Row):country[name@(Language)->Name2;car_code_str->Code] :- T:country_codes_table[nr->N].thetable.table@(Row) [tr@(Column)->_[td@(0)->Name];tr@(0)->_[td@(0)->Code]], language(Column,Language), string(Name), perl(format.country_name,Name,Name2). % /* The car code of Finland is not FIN but SF. All other codes are correct. */ % C[car_code->Code] :- C:country[car_code_str->Code], not Code = "FIN". C[car_code->"SF"] :- C:country[car_code_str->Code], Code = "FIN". % ?- sys.strat.doIt. % %?- C:country[name@(S)->N]. /* \paragraph{Output.} Using the \flrule{instance} output format, the resulting atoms are selected for output to \flrule{mondial-codes-facts.flp}.*/ % ?- sys.echo@("*** Generating Output ***"). % save[init->"`rm ../Mondial-facts/mondial-codes-facts.flp`; @out=@in;"]. % ?- sys.strat.doIt. % ?- perl(save.init,[""],[""]). % ?- sys.prn.style@("instance"). % set output mode ?- sys[output->sys.open@("../Mondial-facts/mondial-codes-facts.flp")]. ?- sys.answerChannel.setStream@(output)[]. % /* The following output query also defines the schema of the country names and country code part of the database */ % ?- C:country[car_code->Code; name@("english")->NE; name@("german")->NG; name@("local")->NL]. % ?- sys.answerChannel.resetStream[]. ?- sys.remove@("output").