Difference between revisions of "Lab: Getting started with VSCode, Python and RDFlib"

From Info216
Line 10: Line 10:
 
RDFLib is a Python package for working with RDF. With this we can create RDF graphs, parse and serialize RDF, perform SPARQL queries on graphs and more.
 
RDFLib is a Python package for working with RDF. With this we can create RDF graphs, parse and serialize RDF, perform SPARQL queries on graphs and more.
  
==Preparations==
 
If needed here is an introduction of how to create projects and python files in Pycharm [https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html Eclipse IDE - Tutorial by jetbrains.com].
 
 
[https://rdflib.readthedocs.io/en/stable/index.html# RDFLib Documentation]- Todays focus are the following:
 
* [https://rdflib.readthedocs.io/en/stable/intro_to_creating_rdf.html  Intro to creating triples]
 
* [https://rdflib.readthedocs.io/en/stable/intro_to_parsing.html Loading and saving RDF]
 
 
Additional recommended in depth documentation:
 
* [https://rdflib.readthedocs.io/en/stable/rdf_terms.html RDF Terms]
 
* [https://rdflib.readthedocs.io/en/stable/namespaces_and_bindings.html Namespaces and Bindings]
 
 
Useful code [[examples]] can be found of this wiki.
 
 
[[Lecture Notes]]
 
 
==Relevant RDFlib classes/interfaces (and methods)==
 
import [https://rdflib.readthedocs.io/en/stable/py-modindex.html rdflib]:
 
*Graph (add, remove, serialize)
 
*URIRef
 
*Literal
 
*NameSpace
 
*RDF, FOAF
 
 
All RDFlib modules can be found [https://rdflib.readthedocs.io/en/stable/py-modindex.html here]
 
Browser search (often Ctrl-F) is useful here to find the module that you want.
 
  
 
==Tasks==
 
==Tasks==
Line 69: Line 44:
  
 
'''Coding Tasks'''
 
'''Coding Tasks'''
 
  
  
Line 80: Line 54:
 
''"Cade Tracy lives in 1516 Henry Street, Berkeley, California 94709, USA. He has a B.Sc. in biology from the University of California, Berkeley from 2011. His interests include birds, ecology, the environment, photography and travelling. He has visited Canada and France."''
 
''"Cade Tracy lives in 1516 Henry Street, Berkeley, California 94709, USA. He has a B.Sc. in biology from the University of California, Berkeley from 2011. His interests include birds, ecology, the environment, photography and travelling. He has visited Canada and France."''
 
Try to use as many different methods as possible to create the triples.
 
Try to use as many different methods as possible to create the triples.
 +
 +
 +
 +
 +
==Preparations==
 +
If needed here is an introduction of how to create projects and python files in Pycharm [https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html Eclipse IDE - Tutorial by jetbrains.com].
 +
 +
[https://rdflib.readthedocs.io/en/stable/index.html# RDFLib Documentation]- Todays focus are the following:
 +
* [https://rdflib.readthedocs.io/en/stable/intro_to_creating_rdf.html  Intro to creating triples]
 +
* [https://rdflib.readthedocs.io/en/stable/intro_to_parsing.html Loading and saving RDF]
 +
 +
Additional recommended in depth documentation:
 +
* [https://rdflib.readthedocs.io/en/stable/rdf_terms.html RDF Terms]
 +
* [https://rdflib.readthedocs.io/en/stable/namespaces_and_bindings.html Namespaces and Bindings]
 +
 +
Useful code [[examples]] can be found of this wiki.
 +
 +
[[Lecture Notes]]
 +
 +
==Relevant RDFlib classes/interfaces (and methods)==
 +
import [https://rdflib.readthedocs.io/en/stable/py-modindex.html rdflib]:
 +
*Graph (add, remove, serialize)
 +
*URIRef
 +
*Literal
 +
*NameSpace
 +
*RDF, FOAF
 +
 +
All RDFlib modules can be found [https://rdflib.readthedocs.io/en/stable/py-modindex.html here]
 +
Browser search (often Ctrl-F) is useful here to find the module that you want.

Revision as of 16:46, 13 January 2020

Lab 1: Getting started with Pycharm, Python and RDFlib

Topics

Installation of and introduction to Python, Pycharm, Pip and RDFlib.

PyCharm is a Python Integrated Development Environment (IDE) that can be used for writing python code.

Pip is used to easily install additional python packages for your coding environment.

RDFLib is a Python package for working with RDF. With this we can create RDF graphs, parse and serialize RDF, perform SPARQL queries on graphs and more.


Tasks

You likely already have Python installed on your computer (it comes with MAC for instance). To find out, type 'python' in the commandline on windows or type 'python --version' in the terminal on your MAC. If you don't already have Python, download and install the Python for your operative system here. We recommend downloading the most recent version.

If you are already using a different Python IDE than Pycharm that you are comfortable with, then you are free to use that program instead.

Otherwise Download and Install the free and open source Pycharm Community IDE here.


Pip On Windows: Download pip here: https://bootstrap.pypa.io/get-pip.py. (Right click on this link and click "Save link as". You can save it to you desktop or somewhere else if you would like)

Open a command prompt and navigate to the folder containing get-pip.py. (e.g enter 'cd Desktop' to get to the desktop)

Now run the following command in the promt 'python get-pip.py'

Pip On Mac:

Open the terminal and first run: 'curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py'

Now run this: 'python get-pip.py'


RDFlib

Using the Pycharm terminal, install RDFlib by simply entering: pip install rdflib

Start Pycharm and create a new project with a new .py file.


Coding Tasks


Create a python program that creates a single triple and writes it out. Use the Classes/interfaces and methods listed above.


If you have more time...

If you have more time you can continue extending your graph with some of the stuff from lab 2: "Cade Tracy lives in 1516 Henry Street, Berkeley, California 94709, USA. He has a B.Sc. in biology from the University of California, Berkeley from 2011. His interests include birds, ecology, the environment, photography and travelling. He has visited Canada and France." Try to use as many different methods as possible to create the triples.



Preparations

If needed here is an introduction of how to create projects and python files in Pycharm Eclipse IDE - Tutorial by jetbrains.com.

RDFLib Documentation- Todays focus are the following:

Additional recommended in depth documentation:

Useful code examples can be found of this wiki.

Lecture Notes

Relevant RDFlib classes/interfaces (and methods)

import rdflib:

  • Graph (add, remove, serialize)
  • URIRef
  • Literal
  • NameSpace
  • RDF, FOAF

All RDFlib modules can be found here Browser search (often Ctrl-F) is useful here to find the module that you want.