Lab: OWL 1: Difference between revisions

From info216
No edit summary
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Topics==
==Topics==
Basic OWL ontology programming with RDFlib and owlrl.
* Basic OWL ontology programming with RDFlib and owlrl.
* RDFS is relevant too.
* WebVOWL visualisation.


WebVOWL visualisation.
==Useful materials==
 
Readings:
RDF and RDFS might be relevant too.
* [https://wiki.app.uib.no/info216/index.php?title=File:S08-OWL.pdf Lecture Notes]
 
* [https://wiki.uib.no/info216/index.php/Python_Examples#RDFS_Plus_.2F_OWL_inference_with_RDFLib Example page]
==Classes/Vocabularies==
* [https://www.w3.org/TR/owl-ref/ OWL Documentation]
* [https://docs.google.com/presentation/d/1N8nN53I2-4Erp-SPoU0rI9yWjyfWaBKgwcRjr7R7c7w/ OWL 1 - Lab Presentation]


Vocabulary:
Vocabularies and terms:
* OWL (sameAs, equivalentClass, equivalentProperty, differentFrom, disjointWith, inverseOf)
* OWL (sameAs, equivalentClass, equivalentProperty, differentFrom, disjointWith, inverseOf)
* OWL (SymmetricProperty, AsymmetricProperty, ReflexiveProperty, IrreflexiveProperty, TransitiveProperty, FunctionalProperty, InverseFunctionalProperty, AllDifferent)
* OWL (SymmetricProperty, AsymmetricProperty, ReflexiveProperty, IrreflexiveProperty, TransitiveProperty, FunctionalProperty, InverseFunctionalProperty, AllDifferent)


==Tasks==
==Tasks==
'''Task 1'''
'''Task.'''
 
''Write OWL triples that corresponds to the following text.'' Try to continue your example from labs 1 and 2, or extend the triples at the bottom of this page. OWL terms can be imported from rdflib in the same way as RDF and RDFS terms.
'''Write OWL triples that corresponds to the following text. '''.If you can, try to build on your example from labs 1 and 2, or extend the triples at the bottom of the page. OWL terms can be imported from rdflib in the same way as RDF and RDFS terms.


* Donald Trump and Robert Mueller are two different persons.
* Donald Trump and Robert Mueller are two different persons.
Line 22: Line 24:
* Tax evation is a kind of bank and tax fraud.
* Tax evation is a kind of bank and tax fraud.
* The Donald Trump involved in the Mueller investigation is ''dbpedia:Donald_Trump'' and not ''dbpedia:Donald_Trump_Jr.'' .
* The Donald Trump involved in the Mueller investigation is ''dbpedia:Donald_Trump'' and not ''dbpedia:Donald_Trump_Jr.'' .
** ''Tip:'' rdflib's Turtle parser does not like URLs with punctuation marks written "prefix style" (''dbpedia:Donald_Trump_Jr.''), but it will accept the full URL written in angle brackets (''<http://dbpedia.org/resource/Donald_Trump_Jr.>'')
* Congress, FBI and the Mueller investigation are ''foaf:Organization''s.
* Congress, FBI and the Mueller investigation are ''foaf:Organization''s.
* Nothing can be both a person and an organization.  
* Nothing can be both a person and an organization.  
Line 28: Line 31:
* Donald Trump is a politician and a Republican.  
* Donald Trump is a politician and a Republican.  
* A  Republican politician is both a politician and a Republican.
* A  Republican politician is both a politician and a Republican.
* ''Harder:'' Someone who supports a Republican politician is a Republican.


'''Task 2'''
'''Task.'''
<syntaxhighlight>
<syntaxhighlight>
g.add((ex:Paul_Manafort, ex:hasBusinessPartner ex:Rick_Gates))
g.add((ex.Paul_Manafort, ex.hasBusinessPartner, ex.Rick_Gates))
g.add((ex:Michael_Flynn ex:adviserTo ex:Donald_Trump))
g.add((ex.Michael_Flynn, ex.adviserTo, ex.Donald_Trump))
g.add((ex:Rick_Gates_Lying ex:wasLyingTo ex:FBI))
g.add((ex.Rick_Gates_Lying, ex.wasLyingTo, ex.FBI))
g.add((ex:Donald_Trump ex:presidentOf ex:USA))
g.add((ex.Donald_Trump, ex.presidentOf, ex.USA))
g.add((ex:USA ex:hasPpresident ex:Donald_Trump))
g.add((ex.USA, ex.hasPresident, ex.Donald_Trump))
</syntaxhighlight>  
</syntaxhighlight>  


Look through the predicates (properties) above and add new triples for each one that describes them as any of the following: a reflexive , irreflexive, symmetric, asymmetric, transitive, functional, or an inverse functional property.
Look through the predicates (properties) above and add new triples for each one that describes them as any of the following: a reflexive, irreflexive, symmetric, asymmetric, transitive, functional, or an inverse functional property.
e.g
e.g
<syntaxhighlight>
<syntaxhighlight>
Line 45: Line 47:
</syntaxhighlight>
</syntaxhighlight>


'''Task 3'''
'''Task.'''
 
Serialize the ontology and look at the results. Create an owlrl closure as below to infer additional triples and serialize it again. Can you spot the many inferences?
Print/Serialize the ontology. Then use owlrl as below to infer additional triples. Can you spot the many inferences?
<syntaxhighlight>
<syntaxhighlight>
DeductiveClosure(OWLRL_Semantics).expand(graph)
DeductiveClosure(OWLRL_Semantics).expand(graph)
</syntaxhighlight>
</syntaxhighlight>


Finally write the ontology to a XML file, and visualise it using https://service.tib.eu/webvowl/. The purpose of WebVOWL is to visualise classes and their properties, so the individuals may not show.
'''Task.'''
Finally write the ontology to a XML file, and visualise it using http://vowl.visualdataweb.org/webvowl.html. The purpose of WebVOWL is to visualise classes and their properties, so the individuals may not show.  


==Useful Reading==
''Tip:'' When you save OWL files as XML, the extension ''.owl-xml'' can be used.
* [https://wiki.uib.no/info216/index.php/File:S06-OWL-1.pdf Lecture Notes]


* [https://wiki.uib.no/info216/index.php/Python_Examples#RDFS_Plus_.2F_OWL_inference_with_RDFLib Example page]
Most likely, your ontology is still quite disconnected. Add ''rdfs:subClassOf'', ''rdfs:domain'', and ''rdfs:range'' triples to turn it into a more connected graph that represents the domain. Calculate owlrl closures to see the effects of your triples as you add them.


==Triples you can extend for the tasks==
===Triples you can use in the first task===
'''Turtle'''
<syntaxhighlight>
<syntaxhighlight>
@prefix ex: <http://example/org#> .
@prefix ex: <http://example/org#> .
Line 105: Line 105:
         ex:Rick_Gates_Lying .
         ex:Rick_Gates_Lying .
</syntaxhighlight>
</syntaxhighlight>
==If you have more time==
'''Task.'''
Inspect your ontology with [https://webprotege.stanford.edu/ Webprotégé].
* Register as a new user and log in.
* ''Create a new project'' and use ''Create from existing sources'' to upload your OWL/XML file.
* Explore how to edit and extend your ontology using Protégé.
You can also [https://protege.stanford.edu/software.php#desktop-protege download Protégé Desktop] for free and run it on your local machine. The stand-alone version is even more powerful with lots of plug-ins.

Latest revision as of 12:31, 10 April 2024

Topics

  • Basic OWL ontology programming with RDFlib and owlrl.
  • RDFS is relevant too.
  • WebVOWL visualisation.

Useful materials

Readings:

Vocabularies and terms:

  • OWL (sameAs, equivalentClass, equivalentProperty, differentFrom, disjointWith, inverseOf)
  • OWL (SymmetricProperty, AsymmetricProperty, ReflexiveProperty, IrreflexiveProperty, TransitiveProperty, FunctionalProperty, InverseFunctionalProperty, AllDifferent)

Tasks

Task. Write OWL triples that corresponds to the following text. Try to continue your example from labs 1 and 2, or extend the triples at the bottom of this page. OWL terms can be imported from rdflib in the same way as RDF and RDFS terms.

  • Donald Trump and Robert Mueller are two different persons.
  • Actually, all the names mentioned in connection with the Muelle investigation refer to different people.
  • All these people are foaf:Persons as well as schema:Persons (they are http://xmlns.com/foaf/0.1/Person and http://schema.org/Person).
  • Tax evation is a kind of bank and tax fraud.
  • The Donald Trump involved in the Mueller investigation is dbpedia:Donald_Trump and not dbpedia:Donald_Trump_Jr. .
    • Tip: rdflib's Turtle parser does not like URLs with punctuation marks written "prefix style" (dbpedia:Donald_Trump_Jr.), but it will accept the full URL written in angle brackets (<http://dbpedia.org/resource/Donald_Trump_Jr.>)
  • Congress, FBI and the Mueller investigation are foaf:Organizations.
  • Nothing can be both a person and an organization.
  • Leading an organization is a way of being involved in an organization.
  • Being a campaign manager or an advisor for is a way of supporting someone.
  • Donald Trump is a politician and a Republican.
  • A Republican politician is both a politician and a Republican.

Task.

g.add((ex.Paul_Manafort, ex.hasBusinessPartner, ex.Rick_Gates))
g.add((ex.Michael_Flynn, ex.adviserTo, ex.Donald_Trump))
g.add((ex.Rick_Gates_Lying, ex.wasLyingTo, ex.FBI))
g.add((ex.Donald_Trump, ex.presidentOf, ex.USA))
g.add((ex.USA, ex.hasPresident, ex.Donald_Trump))

Look through the predicates (properties) above and add new triples for each one that describes them as any of the following: a reflexive, irreflexive, symmetric, asymmetric, transitive, functional, or an inverse functional property. e.g

g.add((ex.wasLyingTo, RDF.type, OWL.IrreflexiveProperty))

Task. Serialize the ontology and look at the results. Create an owlrl closure as below to infer additional triples and serialize it again. Can you spot the many inferences?

DeductiveClosure(OWLRL_Semantics).expand(graph)

Task. Finally write the ontology to a XML file, and visualise it using http://vowl.visualdataweb.org/webvowl.html. The purpose of WebVOWL is to visualise classes and their properties, so the individuals may not show.

Tip: When you save OWL files as XML, the extension .owl-xml can be used.

Most likely, your ontology is still quite disconnected. Add rdfs:subClassOf, rdfs:domain, and rdfs:range triples to turn it into a more connected graph that represents the domain. Calculate owlrl closures to see the effects of your triples as you add them.

Triples you can use in the first task

@prefix ex: <http://example/org#> .

ex:Mueller_Investigation ex:involved ex:George_Papadopoulos,
        ex:Michael_Cohen,
        ex:Michael_Flynn,
        ex:Paul_Manafort,
        ex:Rick_Gates,
        ex:Roger_Stone ;
    ex:leadBy ex:Robert_Mueller .

ex:Michael_Cohen ex:attorneyFor ex:Donald_Trump ;
    ex:pleadedGuilty ex:Michael_Cohens_Lying .

ex:Michael_Cohens_Lying a ex:Lying ;
    ex:wasLyingAbout ex:Trump_RealEstateDeal ;
    ex:wasLyingTo ex:Congress .

ex:Michael_Flynn ex:adviserTo ex:Donald_Trump ;
    ex:negotiatedAgreement ex:PleaAgreement ;
    ex:pleadedGuilty ex:Michael_Flynns_Lying .

ex:Michael_Flynns_Lying a ex:Lying ;
    ex:wasLyingTo ex:FBI .

ex:Paul_Manafort ex:campaignManager ex:Donald_Trump ;
    ex:chargedWith ex:ForeignLobbying,
        ex:MoneyLaundering,
        ex:TaxEvasion ;
    ex:convictedFor ex:BankAndTaxFraud ;
    ex:hasBusinessPartner ex:Rick_Gates ;
    ex:negotiatedAgreement ex:PleaAgreement ;
    ex:pleadedGuilty ex:Conspiracy ;
    ex:sentencedTo ex:Prison .

ex:Rick_Gates_Lying a ex:Lying ;
    ex:wasLyingTo ex:FBI .

ex:Rick_Gates ex:chargedWith ex:ForeignLobbying,
        ex:MoneyLaundering,
        ex:TaxEvasion ;
    ex:pleadedGuilty ex:Conspiracy,
        ex:Rick_Gates_Lying .

If you have more time

Task. Inspect your ontology with Webprotégé.

  • Register as a new user and log in.
  • Create a new project and use Create from existing sources to upload your OWL/XML file.
  • Explore how to edit and extend your ontology using Protégé.

You can also download Protégé Desktop for free and run it on your local machine. The stand-alone version is even more powerful with lots of plug-ins.