Completed
Push — master ( 3de2d7...fcfe03 )
by Gus
01:06
created

Processor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 11
Bugs 0 Features 0
Metric Value
c 11
b 0
f 0
dl 0
loc 14
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 2 1
A annotate() 0 9 2
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
# use data structures
5
from .ds import Document, Sentence, Dependencies
6
from .utils import post_json
7
import json
8
9
10
class Processor(object):
11
12
    def __init__(self, address):
13
        self.service = "{}/annotate".format(address)
14
15
    def annotate(self, text):
16
        try:
17
            # load json and build Sentences and Document
18
            annotated_text = post_json(self.service, json.dumps({"text":"{}".format(text)}))
19
            return Document.load_from_JSON(annotated_text)
20
21
        except Exception as e:
22
            #print(e)
23
            return None
24
            #raise Exception("Connection refused!  Is the server running?")
25
26
class FastNLPProcessor(Processor):
27
28
    def __init__(self, address):
29
        self.service = "{}/fastnlp/annotate".format(address)
30
31
    def annotate(self, text):
32
        return super(FastNLPProcessor, self).annotate(text)
33
34
class BioNLPProcessor(Processor):
35
36
    def __init__(self, address):
37
        self.service = "{}/bionlp/annotate".format(address)
38
39
    def annotate(self, text):
40
        return super(BioNLPProcessor, self).annotate(text)
41