Skip to content

Dependency parsing

Mika Hämäläinen edited this page Mar 9, 2019 · 8 revisions

UralicNLP provides a Python binding to Turku Finnish Dependency Parser and Turku Neural Parser.

How to use

UralicNLP currently supports only Finnish for dependency parsing. It requires the Turku Dependency Parser Docker to be configured and running.

If you want to use the latest neural parser, make sure you run it on docker like so (slower)

docker run -d -p 9876:7689 turkunlp/turku-neural-parser:finnish-cpu-plaintext-server

Note: If the neural parser hangs, you need to follow these instructions.

The older statistical parser can be used by running (faster)

docker run --restart always -d -p 0.0.0.0:9876:9876 kazhar/finnish-dep-parser

Dependency parsing

from uralicNLP import dependency
ud = dependency.parse_text("kissa nauroi kovaa\nLehmä lauloi ainiaan", "fin")
for sentence in ud:
	for word in sentence:
		print word.pos, word.lemma, word.get_attribute("deprel")
	print "---"
>>NOUN kissa nsubj
>>VERB nauraa root
>>ADJ kova obj
>>---
>>NOUN lehmä nsubj
>>VERB laulaa root
>>ADV ainiaan advmod
>>---

The result will be returned as a UD_collection object. If the docker is running in some other port than 9876 or on another server, you can specify that in the url parameter dependency.parse_text(text, "fin", url="http://localhost:9876").

Clone this wiki locally