Ontology Aware Applications

2,729 views

Published on

Published in: Education, Spiritual
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,729
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ontology Aware Applications

  1. 1. Ontology Aware Applications Portuguese Perl Workshop 2011 Nuno Carvalho <smash@cpan.org>Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 1
  2. 2. Introduction ontologies can he used to store data create, query, manipulate, maintain, reason, ... build applications using ontologies to store information approaches for representing ontologies mechanisms to implement common operations want to use all this with our favourite programming language to develop applicationsPerl × ontology −→ modern rich ontology aware applications Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 2
  3. 3. IntroductionMotivations ontology use is growing solutions based in this technology are growing Semantic Web, etc. ontologies are a good approach to store knowledge ontologies are easy to share, store, replicate, ... Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 3
  4. 4. BackgroundOntologyA domain ontology is an engineered artifact that informally definesconcepts from a specific domain, representing and organizing themas conceptualizations which a set of systems working cooperativelywith each other agree to share. city -7.84 .. Vila Real DST LAT ISA LNG ISA 39.63 .. IN Chaves LAT Lisbon Portugal -7.47 .. LNG IN ISA 41.74 .. country terms relations Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 4
  5. 5. Ontology RepresentationBiblio::Thesaurus + ISO 2778 simple and uses a simple representation not only thesaurus easy to push features is written in PerlBragaCITY-OF PortugalIS-A cityVigoCITY-OF SpainIS-A city Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 5
  6. 6. Ontology ManipulationOML Programs describe operations on ontologies list of rules each rule has a: a pattern to look for an action list to execute produce side effects expressive, powerful, yet simple embedded programsRules pattern => actions. Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 6
  7. 7. OML Syntax OverviewOML Program program → rule + rule → Pattern => Action .Pattern a pattern of information, terms and relations, that can be found once or more than once in the ontologyAction manipulate information in the ontology add, remove, terms or relations, ... produce any arbitrary user defined side effects produce graphs, images, HTML pages, update databases, ... Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 7
  8. 8. Ontology Example city -7.84 .. Vila Real DST LAT ISA LNG ISA 39.63 .. IN Chaves LAT Lisbon Portugal -7.47 .. LNG IN ISA 41.74 .. countryterms relations Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 8
  9. 9. OML Patterns Examples # Pattern 1 term(Chaves) term Chaves exists 2 rel(ISA) relation ISA exists 3 term($t) for all terms 4 rel($r) for all relations 5 Chaves ISA city 6 $name ISA city 7 $name ISA $place 8 Chaves $rel $term for all related to Chaves 9 Chaves ISA city ∧ Portugal ISA country 10 Chaves ISA city ∨ Portugal ISA country 11 Chaves LAT $lat ∧ Chaves LNG $lng Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 9
  10. 10. OML Actions ExamplesManipulate Information add(Portugal ISA country) del($place ISA city)Arbitrary Effectsub { $db->execute( ’INSERT INTO cities (name) VALUES ($city)’ );} Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 10
  11. 11. OML Rules Examples$city IN Portugal ⇒ add($city IN Europe).$c ISA city ∧ $c IN Portugal ⇒ add($c LANG Portuguese).$city ISA city ∧ $city ISA country ⇒ sub { print ”Warning: review $city ISA relation!” }. ;$name ISA city ∧ $name IN $country ⇒ sub {$db->execute( ’INSERT INTO cities (name,country) VALUES ($name,$country)’)}.$a $r $b ∧ $b $r $c ⇒ add($a $r $c).$a $r $b ∧ $b $r $c ∧ $a $r $c ⇒ rem($a $r $c). Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 11
  12. 12. OML CompilerNuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 12
  13. 13. Architecture Overview ontology program compiler result Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 13
  14. 14. Compiler Architecture Overview program parser ontology pTree expander diTree reactor result Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 14
  15. 15. Embedded OMLNuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 15
  16. 16. Embedded OMLChallenge can applications and tools be written only in OML? actually yes, but do we want to? NO!Why? efficient for ontology processing real world applications require more HTML operations, databases, ... we want the best of both worlds OML for ontology aware tasks general purpose programming language for everything else Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 16
  17. 17. Embed OML InitialProgram ne e ut bi ec m lit ex id co sp Perl Perl Perl Perl Perl Perl Perl + Perl Result OML Perl Perl Perl Perl OML Perl compile Final Result Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 17
  18. 18. Embedded OML AlgorithmAlgorithm 1: Weaver(program,split,compile,combine) : programInput: program – original program to processInput: split – function that separates the code parts by languageInput: compile – tranforms OML into PerlInput: combine – joins parts of code togetherparts ← split(program)forall the (lang , code) ∈ parts do if lang is DSL then code ← compile(code) push(parts2, code)returncombine(parts2) Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 18
  19. 19. Embed OML in PerlWhy Perl? provides modules for ”everything else” easy to extendExample:1 use Biblio : : Thesaurus : : ModRewrite : : Embed ;23 my $term = $ARGV [ 0 ] ;4 my $ontology = thesaurusLoad ( $ARGV [ 1 ] ) ;56 OML printTerms ( ontology , term )7 term $r $t = sub { print ”term $ r $ t n ” ; } . >8 $t $r term = sub { print ”$ t $ r term n ” ; } . >9 ENDOML1011 printTerms ( $ontology , $term ) ; Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 19
  20. 20. Example: OntoMapNuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 20
  21. 21. Example Screenshot Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 21
  22. 22. Information in JSONGET /locations.cgi HTTP/1.1(...)Content-Type: application/json; charset=UTF-8{"markers":[{"name":"Braga","desc":"Braga<hr><b>CITY-OF</b>Portugal<br><b>IS-A</b> city<br><b>LAT</b> 41.5517605<br><b>LNG</b> -8.4229034<br>","lat":"41.5517605","lng":"-8.4229034","is":"city"},{"name":"Castelo de Alva","desc":"Castelode Alva<hr><b>IS-A</b> castle<br><b>LAT</b> 41.0913745<br><b>LNG</b> -6.8078773<br>","lat":"41.0913745","lng":"-6.8078773","is":"castle"},{"name":"Castelo de Tavira","desc":"Castelo de Tavira<hr><b>IS-A</b> castle<br><b>LAT</b> 37.1213122<br><b>LNG</b> -7.6533538<br>","lat":"37.1213122","lng":"-7.6533538","is":"castle"},{"name":"Guimaraes","desc":"Guimaraes<hr><b>CITY-OF</b> Portugal<br><b>IS-A</b> city<br><b>LAT</b> 41.4419546<br><b>LNG</b> -8.2956069<br>","lat":"41.4419546","lng":"-8.2956069","is":"city"},{"name":"Lagos","d Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 22
  23. 23. OML Program: locations.cgi1 use CGI ;2 use JSON ;3 use Biblio : : Thesaurus : : ModRewrite : : Embed ;45 my $onto = thesaurusLoad ( ’ geo . iso ’ ) ;6 my $filter = param ( ’ FILTER ’ ) or ’ ANY ’ ;7 print header ,8 ”{ m a r k e r s : ” ,9 get points ( $onto , $filter ) ,10 ”} ” ;1112 OML get points ( ontology , filter )13 $point LAT $x AND $point LNG $y14 AND $point ISA filter15 = sub { >16 print to json ( {name= >$point , lat=>$x , lng=>$y} ) ;17 }.18 ENDOML Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 23
  24. 24. OML Program: addlocation.cgi1 use CGI ;2 use Biblio : : Thesaurus : : ModRewrite : : Embed ;34 my $name = param ( ’ NAME ’ ) ;5 my $isa = param ( ’ ISA ’ ) ;6 my $lat = param ( ’ LAT ’ ) ;7 my $lng = param ( ’ LNG ’ ) ;89 my $onto = thesaurusLoad ( ’ geo . iso ’ ) ;10 add location ( $onto , $name , $isa , $lat , $lng ) ;11 $onto−>save ( ’ geo . iso ’ ) ;1213 OML add location ( ontology , name , isa , lat , lng )14 do =>15 add ( name ISA isa )16 add ( name LAT lat )17 add ( name LNG lng ) .18 ENDOML Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 24
  25. 25. Conclusionlanguage easy to use, efficienteasy to compose with other toolselegant and simple approach to build ontology-awareapplicationsmodular, build complex applications using small blocksembedded mechanism is a clear advantageweaving mechanism can be extended for other languages Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 25
  26. 26. Conclusion weaving mechanism can be language-agnostic split many languages having compilers for each language ne e ut bi ec m lit ex id co sp Perl Perl Perl Perl Perl PerlPerl + Perl ResultDSL* Perl Perl Perl Perl DSL Perl compile* Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 26
  27. 27. Conclusion this mechanism can be adopted in any GPL dynamic language allows pre-processing of source code ne e ut bi ec m lit ex id co sp Perl Perl Perl Perl GPL GPLGPL + GPL ResultDSL* Perl Perl Perl Perl DSL GPL compile* Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 27
  28. 28. Thank You!Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 28

×