English logga in

StartProgrammering

Denna sida finns bara på engelska.

The programming language Python is used in programming courses and several projects here.

NLTK

The Python package NLTK – Natural Language Toolkit – is of course interesting here. It contains several program modules and corpuses for research and education in NLP and is installed here.

>>> import nltk
>>> tokens = nltk.word_tokenize("This is a test.")
>>> tokens
['This', 'is', 'a', 'test', '.']
>>> nltk.pos_tag(tokens)
[('This', 'DT'), ('is', 'VBZ'), ('a', 'DT'), ('test', 'NN'), ('.', '.')]
>>> 

There is an accompanying book, Natural Language Processing with Python, which starts as a beginner’s instruction in Python that uses language technology examples from the start.

Version 2 or 3

There are some incompatible changes in Python version 3, so that some programs can only be run in Python 2 or only in Python 3.

The standard version (/usr/bin/python) in Centos is 2.7, but our locally modified path is changed so that just python runs Python 3.6.

With python2 or python3 you can explicitly run one of the either. (If you want to to use the Idle environment it is started with idle2 or idle3 respectively. The latter is also found in the Applications menu. Also there is ipython2 as well as ipython3.)

Version 3.6

On January 28 we upgraded from version 3.4 to 3.6. If you have made user package installations (see below) in 3.4 you need to do it again in 3.6.

If one of your programs stopped working because of this upgrade, you can run older python3.4 explicitly with that name while you investigate. You can ask Per to examine what happened. There may be a package we haven’t kept.

Installing packages with pip

One way to install Python packages is with pip. Use pip2 or pip3 depending on whether it is for Python2 och Python3.

Note that pip in normal usage assumes that you are a system administrator and are going to do a system-wide installation for everyone. You can’t do that.

To instead do a personal installation for just you, use the option --user. Example:

$ pip3 install --user inflect
Collecting inflect
  Using cached inflect-2.1.0-py2.py3-none-any.whl
Installing collected packages: inflect
Successfully installed inflect-2.1.0
$ python
Python 3.6.6 (default, Aug 13 2018, 18:24:23)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inflect
>>> p = inflect.engine()
>>> p.plural('example')
'examples'
>>> p.plural('archnemesis')
'archnemeses'
>>>

Some packages will install programs for you to run. With a personal installation they will be in ~/.local/bin, and be found in your PATH.