syntaxnet_wrapper icon indicating copy to clipboard operation
syntaxnet_wrapper copied to clipboard

Python wrapper for Google's syntaxnet

Description

A Python 3 wrapper for Google's SyntaxNet parser. The wrapper is considered to work with dockerized SyntaxNet server. The wrapper connects to container via tcp and performs basic preparation/parsing of SyntaxNet parser results.

Basic usage

The basic example of usage is presented in src/test.py

1. Using ProcessorSyntaxNet

ProcessorSyntaxNet needs tokenized and splitted text for work. It can also handle only raw unicode text, in which words are splitted by spaces.

# -*- coding: utf-8 -*-

from syntaxnet_wrapper import ProcessorSyntaxNet

def print_result(result):
    for sent in result:
        for word in sent:
            print(word)
        print

host = '<myhsot>'
port = 8111 # E.g.
text = u'Мама мыла раму . Дом , который построил Джек .'

proc = ProcessorSyntaxNet(host, port)
result = proc.parse(text)
print_result(result)

2. Using PipelineSyntaxNet

The pipeline performs tokenization and sentence splitting for Russian and launches ProcessorSyntaxNet. It also supplies results with information about spans.

# -*- coding: utf-8 -*-

from syntaxnet_wrapper import PipelineSyntaxNet

def print_result(result):
    for sent in result:
        for word in sent:
            print(word)
        print

host = '<myhsot>'
port = 8111 # E.g.
text = u'Мама мыла раму. Дом, который построил Джек.'

proc = PipelineSyntaxNet(host, port)
result = proc.process(text)
print_result(result)