Lab: Getting started with VSCode, Python and RDFlib

From Info216
Revision as of 16:39, 13 January 2020 by Say004 (talk | contribs)

Lab 1: Getting started with Pycharm, Python and RDFlib

Topics

Installation of and introduction to Pycharm and RDFlib.

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

RDFLib is a Python library 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 Eclipse IDE - Tutorial by jetbrains.com.

RDFLib Documentation- Todays focus are the following:

Additional recommended in depth documentation:

Useful code examples codes 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 I recommend to use browser search (often Ctrl-F) to find the module that you want.)

Tasks

Download and install a Java Runtime Environment (JRE) if you do not have it, for example the most recent update of Java 8 (such as u151): https://www.java.com/en/download/ . Java 9 is also out now, and you can try it out if you want. But because Java 9 is so new, we will stay with Java 8 this spring.

Download and unpack a Java SE Development Kit (JDK) 8 (the most recent update, such as u151/152): http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk .

Here is a smart thing to do from the start: Decide on a folder that you always use for downloading, unpacking and installing your own software. Different software packages you install - like Java, Jena and Eclipse - will go into separate subfolders of this folder. This way you will always know where you have them. On my Windows computer, I put everything under a folder called "C:\Programs\Java". On Linux, I use the folder "/opt/Java". It is good practice to use folder names without blank characters (spaces) in them, because they can cause problems for some software packages.

Download and unpack the Eclipse Oxygen IDE for Java Developers: go to https://eclipse.org/downloads/ and Get Eclipse Oxygen for your computer and operating system. This will download an installer program.

Start the installer program (on Linux, you go to the folder where you installed it and start the "eclipse-inst" program). Choose "Eclipse IDE for Java Developers" and choose an installation folder. (I use folders called "C:\Programs\eclipse-oxygen" and "/opt/eclipse-oxygen" for this.)

Start Eclipse from the start menu (on Linux, go to the folder where you installed it and start the "eclipse" program). If you want to, you can make a shortcut to the "eclipse" program from your desktop or task bar.

Tell Eclipse that you are going to use the JDK 8 you just downloaded: "Window" -> "Preferences" -> "Java" -> "Installed JREs" -> "Add..."

Download and unpack Jena 3.6.0: https://jena.apache.org/download/ . (I use folders called "C:\Programs\apache-jena" and "/opt/apache-jena" for this.) You can download and unpack the source files too.

While you are at it, you can download and unpack Apache Jena Fuseki too. You will need it later.

Re-start Eclipse and create an Eclipse project for Java (File -> New -> Java Project). You can call it INFO216Lab1 for example. Right click on the new project in the "Package Explorer" and choose "Build Path" -> "Add external Archives..." Now you can copy or link the Jena JAR-files into the project. You find them in: .../apache-jena/lib/*.jar .

Create a Java program that creates a single triple and writes it out. Use the Classes/interfaces and methods listed above. The simplest way to run the program is using the green "play" button in the top Eclipse toolbar.

Go to the "INFO216 Wiki" page in this wiki and download the file log4j.properties . You can get rid of all the "log4j warnings" by copying the log4j.properties file into exactly the same directory as your Java-files.

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.