Difference between revisions of "Python Examples"

From Info216
Line 6: Line 6:
 
===Lab 1===
 
===Lab 1===
  
# From the first Lab  
+
# Lab 1
g.add((ex.Cade, ex.married, ex.Mary))
+
# g.add((ex.Cade, ex.married, ex.Mary))
g.add((ex.Mary, ex.interest, ex.Hiking))
+
# g.add((ex.Mary, ex.interest, ex.Hiking))
g.add((ex.Mary, ex.interest, ex.Chocolate))
+
# g.add((ex.Mary, ex.interest, ex.Chocolate))
g.add((ex.Mary, ex.interest, ex.Biology))
+
# g.add((ex.Mary, ex.interest, ex.Biology))
g.add((ex.Mary, RDF.type, ex.Student))
+
# g.add((ex.Mary, RDF.type, ex.Student))
g.add((ex.Cade, ex.age, Literal("27", datatype=XSD.integer)))
+
# g.add((ex.Cade, ex.age, Literal("27", datatype=XSD.integer)))
g.add((ex.Mary, ex.age, Literal("26", datatype=XSD.integer)))
+
# g.add((ex.Mary, ex.age, Literal("26", datatype=XSD.integer)))
g.add((ex.France, ex.capital, ex.Paris))
+
# g.add((ex.France, ex.capital, ex.Paris))
g.add((ex.Paris, ex.capitalOf, ex.France))
+
# g.add((ex.Paris, ex.capitalOf, ex.France))
g.add((ex.Paris, RDF.type, ex.City))
+
# g.add((ex.Paris, RDF.type, ex.City))
g.add((ex.Paris, ex.locatedIn, ex.France))
+
# g.add((ex.Paris, ex.locatedIn, ex.France))
g.add((ex.Cade, ex.characteristic, ex.Kind))
+
# g.add((ex.Cade, ex.characteristic, ex.Kind))
g.add((ex.Mary, ex.characteristic, ex.Kind))
+
# g.add((ex.Mary, ex.characteristic, ex.Kind))
    # We are talking about people.
+
# g.add((ex.Mary, RDF.type, FOAF.Person))
g.add((ex.Mary, RDF.type, FOAF.Person))
+
# g.add((ex.Cade, RDF.type, FOAF.Person))
g.add((ex.Cade, RDF.type, FOAF.Person))
 
  
  
 
<div class="credits" style="text-align: right; direction: ltr; margin-left: 1em;">''INFO216, UiB, 2017-2020. All code examples are [https://creativecommons.org/choose/zero/ CC0].'' </div>
 
<div class="credits" style="text-align: right; direction: ltr; margin-left: 1em;">''INFO216, UiB, 2017-2020. All code examples are [https://creativecommons.org/choose/zero/ CC0].'' </div>

Revision as of 12:08, 24 January 2020

This page will be updated with Python examples related to the lectures and labs. We will add more examples after each lab has ended. The first examples will use Python's RDFlib. We will introduce other relevant libraries later.


Lecture 1: Python, RDFlib, and PyCharm

Lab 1

  1. Lab 1
  2. g.add((ex.Cade, ex.married, ex.Mary))
  3. g.add((ex.Mary, ex.interest, ex.Hiking))
  4. g.add((ex.Mary, ex.interest, ex.Chocolate))
  5. g.add((ex.Mary, ex.interest, ex.Biology))
  6. g.add((ex.Mary, RDF.type, ex.Student))
  7. g.add((ex.Cade, ex.age, Literal("27", datatype=XSD.integer)))
  8. g.add((ex.Mary, ex.age, Literal("26", datatype=XSD.integer)))
  9. g.add((ex.France, ex.capital, ex.Paris))
  10. g.add((ex.Paris, ex.capitalOf, ex.France))
  11. g.add((ex.Paris, RDF.type, ex.City))
  12. g.add((ex.Paris, ex.locatedIn, ex.France))
  13. g.add((ex.Cade, ex.characteristic, ex.Kind))
  14. g.add((ex.Mary, ex.characteristic, ex.Kind))
  15. g.add((ex.Mary, RDF.type, FOAF.Person))
  16. g.add((ex.Cade, RDF.type, FOAF.Person))


INFO216, UiB, 2017-2020. All code examples are CC0.