SlideShare a Scribd company logo
1 of 28
Ontology Aware Applications


         Portuguese Perl Workshop 2011


      Nuno Carvalho <smash@cpan.org>




Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   1
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 applications

Perl × ontology −→ modern rich ontology aware applications




          Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   2
Introduction




Motivations
    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
Background
Ontology
A domain ontology is an engineered artifact that informally defines
concepts from a specific domain, representing and organizing them
as conceptualizations which a set of systems working cooperatively
with 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
Ontology Representation

Biblio::Thesaurus + ISO 2778
     simple and uses a simple representation
    not only thesaurus
    easy to push features
    is written in Perl

Braga
CITY-OF Portugal
IS-A city

Vigo
CITY-OF Spain
IS-A city


          Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   5
Ontology Manipulation


OML 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 programs

Rules
                            pattern => actions.



          Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   6
OML Syntax Overview

OML 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 ontology

Action
     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
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 ..                                         country


terms       relations




            Nuno Carvalho <smash@cpan.org>          PtPW2011: Ontology Aware Applications        8
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
OML Actions Examples



Manipulate Information
    add(Portugal ISA country)
   del($place ISA city)

Arbitrary Effect
sub {
  $db->execute(
     ’INSERT INTO cities (name) VALUES ($city)’
  );
}




        Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   10
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
OML Compiler




Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   12
Architecture Overview




                               ontology




     program                  compiler                    result




    Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   13
Compiler Architecture Overview


     program                   parser



                              ontology                     pTree



                             expander


     diTree


                               reactor                     result




    Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   14
Embedded OML




Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   15
Embedded OML


Challenge
     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
Embed OML


 Initial
Program




                                                       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
Embedded OML Algorithm


Algorithm 1: Weaver(program,split,compile,combine) : program
Input: program – original program to process
Input: split – function that separates the code parts by language
Input: compile – tranforms OML into Perl
Input: combine – joins parts of code together

parts ← 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
Embed OML in Perl

Why Perl?
   provides modules for ”everything else”
     easy to extend

Example:
1    use Biblio : : Thesaurus : : ModRewrite : : Embed ;
2
3    my $term = $ARGV [ 0 ] ;
4    my $ontology = thesaurusLoad ( $ARGV [ 1 ] ) ;
5
6    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    ENDOML
10
11   printTerms ( $ontology , $term ) ;



            Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   19
Example: OntoMap




Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   20
Example Screenshot




    Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   21
Information in JSON

GET /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.42290
34","is":"city"},{"name":"Castelo de Alva","desc":"Castelo
de 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.8078
773","is":"castle"},{"name":"Castelo de Tavira","desc":"Cas
telo de Tavira<hr><b>IS-A</b> castle<br><b>LAT</b> 37.12131
22<br><b>LNG</b> -7.6533538<br>","lat":"37.1213122","lng":"
-7.6533538","is":"castle"},{"name":"Guimaraes","desc":"Guim
araes<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
OML Program: locations.cgi

1    use CGI ;
2    use JSON ;
3    use Biblio : : Thesaurus : : ModRewrite : : Embed ;
4
5    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                 ”} ” ;
11
12   OML get points ( ontology , filter )
13     $point LAT $x AND $point LNG $y
14     AND $point ISA filter
15       = sub {
          >
16          print to json ( {name= >$point , lat=>$x , lng=>$y} ) ;
17       }.
18   ENDOML


            Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   23
OML Program: addlocation.cgi

1    use CGI ;
2    use Biblio : : Thesaurus : : ModRewrite : : Embed ;
3
4    my   $name = param ( ’ NAME ’ ) ;
5    my   $isa = param ( ’ ISA ’ ) ;
6    my   $lat = param ( ’ LAT ’ ) ;
7    my   $lng = param ( ’ LNG ’ ) ;
8
9    my $onto = thesaurusLoad ( ’ geo . iso ’ ) ;
10   add location ( $onto , $name , $isa , $lat , $lng ) ;
11   $onto−>save ( ’ geo . iso ’ ) ;
12
13   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
Conclusion




language easy to use, efficient
easy to compose with other tools
elegant and simple approach to build ontology-aware
applications
modular, build complex applications using small blocks
embedded mechanism is a clear advantage
weaving mechanism can be extended for other languages




     Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   25
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                Perl
Perl
 +                                                      Perl                  Result
DSL*            Perl
               Perl                 Perl
                                   Perl
              DSL                 Perl


                       compile*




       Nuno Carvalho <smash@cpan.org>      PtPW2011: Ontology Aware Applications       26
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                 GPL
GPL
 +                                                      GPL                   Result
DSL*            Perl
               Perl                 Perl
                                   Perl
              DSL                 GPL


                       compile*




       Nuno Carvalho <smash@cpan.org>      PtPW2011: Ontology Aware Applications       27
Thank You!




Nuno Carvalho <smash@cpan.org>   PtPW2011: Ontology Aware Applications   28

More Related Content

Viewers also liked

Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story ofAndrew Shitov
 
Qué es la informatica
Qué es la informaticaQué es la informatica
Qué es la informaticapumasayay
 
Minha submissão (Robson Nascimento do Carmo)
Minha submissão (Robson Nascimento do Carmo)Minha submissão (Robson Nascimento do Carmo)
Minha submissão (Robson Nascimento do Carmo)Robson Carmo
 
Arogyaka rajmarg dr. shriniwas kashalikar
Arogyaka rajmarg dr. shriniwas kashalikarArogyaka rajmarg dr. shriniwas kashalikar
Arogyaka rajmarg dr. shriniwas kashalikarshriniwas kashalikar
 
iPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.comiPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.comSeth dickens
 
Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...
Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...
Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...shriniwas kashalikar
 
La direcció estratègica de l’empresa
La direcció estratègica de l’empresaLa direcció estratègica de l’empresa
La direcció estratègica de l’empresaLaura
 

Viewers also liked (13)

Introducing perl6
Introducing perl6Introducing perl6
Introducing perl6
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story of
 
Qué es la informatica
Qué es la informaticaQué es la informatica
Qué es la informatica
 
Conjoncture economique 4eme trimestre
Conjoncture economique 4eme  trimestreConjoncture economique 4eme  trimestre
Conjoncture economique 4eme trimestre
 
Minha submissão (Robson Nascimento do Carmo)
Minha submissão (Robson Nascimento do Carmo)Minha submissão (Robson Nascimento do Carmo)
Minha submissão (Robson Nascimento do Carmo)
 
Presentación1
Presentación1Presentación1
Presentación1
 
Unit writing
Unit writingUnit writing
Unit writing
 
Arogyaka rajmarg dr. shriniwas kashalikar
Arogyaka rajmarg dr. shriniwas kashalikarArogyaka rajmarg dr. shriniwas kashalikar
Arogyaka rajmarg dr. shriniwas kashalikar
 
iPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.comiPads in Educazione Seth Dickens - www.digitalang.com
iPads in Educazione Seth Dickens - www.digitalang.com
 
Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...
Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...
Arogyasmarana marathi bestseller on superhealth dr. shriniwas kashalikar & dr...
 
Numeracy
NumeracyNumeracy
Numeracy
 
Beautiful Parrot
Beautiful ParrotBeautiful Parrot
Beautiful Parrot
 
La direcció estratègica de l’empresa
La direcció estratègica de l’empresaLa direcció estratègica de l’empresa
La direcció estratègica de l’empresa
 

Recently uploaded

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 

Recently uploaded (20)

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

Ontology Aware Applications

  • 1. Ontology Aware Applications Portuguese Perl Workshop 2011 Nuno Carvalho <smash@cpan.org> Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 1
  • 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 applications Perl × ontology −→ modern rich ontology aware applications Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 2
  • 3. Introduction Motivations 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. Background Ontology A domain ontology is an engineered artifact that informally defines concepts from a specific domain, representing and organizing them as conceptualizations which a set of systems working cooperatively with 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. Ontology Representation Biblio::Thesaurus + ISO 2778 simple and uses a simple representation not only thesaurus easy to push features is written in Perl Braga CITY-OF Portugal IS-A city Vigo CITY-OF Spain IS-A city Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 5
  • 6. Ontology Manipulation OML 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 programs Rules pattern => actions. Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 6
  • 7. OML Syntax Overview OML 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 ontology Action 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. 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 .. country terms relations Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 8
  • 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. OML Actions Examples Manipulate Information add(Portugal ISA country) del($place ISA city) Arbitrary Effect sub { $db->execute( ’INSERT INTO cities (name) VALUES ($city)’ ); } Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 10
  • 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. OML Compiler Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 12
  • 13. Architecture Overview ontology program compiler result Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 13
  • 14. Compiler Architecture Overview program parser ontology pTree expander diTree reactor result Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 14
  • 15. Embedded OML Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 15
  • 16. Embedded OML Challenge 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. Embed OML Initial Program 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. Embedded OML Algorithm Algorithm 1: Weaver(program,split,compile,combine) : program Input: program – original program to process Input: split – function that separates the code parts by language Input: compile – tranforms OML into Perl Input: combine – joins parts of code together parts ← 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. Embed OML in Perl Why Perl? provides modules for ”everything else” easy to extend Example: 1 use Biblio : : Thesaurus : : ModRewrite : : Embed ; 2 3 my $term = $ARGV [ 0 ] ; 4 my $ontology = thesaurusLoad ( $ARGV [ 1 ] ) ; 5 6 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 ENDOML 10 11 printTerms ( $ontology , $term ) ; Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 19
  • 20. Example: OntoMap Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 20
  • 21. Example Screenshot Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 21
  • 22. Information in JSON GET /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.42290 34","is":"city"},{"name":"Castelo de Alva","desc":"Castelo de 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.8078 773","is":"castle"},{"name":"Castelo de Tavira","desc":"Cas telo de Tavira<hr><b>IS-A</b> castle<br><b>LAT</b> 37.12131 22<br><b>LNG</b> -7.6533538<br>","lat":"37.1213122","lng":" -7.6533538","is":"castle"},{"name":"Guimaraes","desc":"Guim araes<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. OML Program: locations.cgi 1 use CGI ; 2 use JSON ; 3 use Biblio : : Thesaurus : : ModRewrite : : Embed ; 4 5 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 ”} ” ; 11 12 OML get points ( ontology , filter ) 13 $point LAT $x AND $point LNG $y 14 AND $point ISA filter 15 = 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. OML Program: addlocation.cgi 1 use CGI ; 2 use Biblio : : Thesaurus : : ModRewrite : : Embed ; 3 4 my $name = param ( ’ NAME ’ ) ; 5 my $isa = param ( ’ ISA ’ ) ; 6 my $lat = param ( ’ LAT ’ ) ; 7 my $lng = param ( ’ LNG ’ ) ; 8 9 my $onto = thesaurusLoad ( ’ geo . iso ’ ) ; 10 add location ( $onto , $name , $isa , $lat , $lng ) ; 11 $onto−>save ( ’ geo . iso ’ ) ; 12 13 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. Conclusion language easy to use, efficient easy to compose with other tools elegant and simple approach to build ontology-aware applications modular, build complex applications using small blocks embedded mechanism is a clear advantage weaving mechanism can be extended for other languages Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 25
  • 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 Perl Perl + Perl Result DSL* Perl Perl Perl Perl DSL Perl compile* Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 26
  • 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 GPL GPL + GPL Result DSL* Perl Perl Perl Perl DSL GPL compile* Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 27
  • 28. Thank You! Nuno Carvalho <smash@cpan.org> PtPW2011: Ontology Aware Applications 28