-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.py
55 lines (42 loc) · 1.36 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
cophi.dkpro.model
~~~~~~~~~~~~~~~~~
This module implements model classes for the DARIAH-DKPro Wrapper.
"""
import csv
from pathlib import Path
import pandas as pd
from cophi import dkpro, text
class DKPro:
"""DARIAH DKPro-Wrapper.
"""
def __init__(self, jar, xms="4g"):
self.jar = jar
self.xms = xms
def process(self, **parameters):
"""Process a single text file or a whole directory.
Parameters:
path (str): Path to text file or directory.
config (str): Config file.
language (str): Corpus language code. Defaults to `en`.
output (str): Path to output directory.
reader (str): Either `text` (default) or `xml`.
Returns:
True, if call was successful.
"""
return dkpro.core.call(self.jar, self.xms, **parameters)
class Document:
def __init__(self, filepath):
self.filepath = Path(filepath)
@property
def raw(self):
document = pd.read_csv(self.filepath,
sep="\t",
quoting=csv.QUOTE_NONE)
filename = Path(self.filepath.stem)
document.name = filename.stem
return document
def filter(self, pos):
document = self.raw[self.raw["CPOS"].isin(pos)]
document.name = self.raw.name
return document