[735bb5]: / src / features / character_length_feature.py

Download this file

44 lines (31 with data), 1.1 kB

 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
# Base Dependencies
# ----------------
import numpy
# Local Dependencies
# ------------------
from models import RelationCollection
# 3rd-Party Dependencies
# ----------------------
from sklearn.base import BaseEstimator
class CharacterLengthFeature(BaseEstimator):
"""
CharacterLengthFeature
Computes the number of characters of each relation's sentence. Used for evaluation.
"""
def __init__(self):
pass
def get_feature_names(self, input_features=None):
return ["char_length"]
def create_character_length_feature(
self, collection: RelationCollection
) -> numpy.array:
features = []
for r in collection.relations:
features.append([len(r.text)])
return numpy.array(features)
def fit(self, x: RelationCollection, y=None):
return self
def transform(self, x: RelationCollection, y=None) -> numpy.array:
return self.create_character_length_feature(x)
def fit_transform(self, x: RelationCollection, y=None) -> numpy.array:
return self.create_character_length_feature(x)