Skip to content

Commit

Permalink
handle pickling differently
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Jun 27, 2024
1 parent 0c6b65c commit 9271305
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
22 changes: 3 additions & 19 deletions parseratorvariable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ def __init__(
else:
self._string_comparison = affineGap

# setting up some information for pickling this variable
self._definition = {
"field": field,
"tagger": tagger,
"block_parts": block_parts,
"crf": crf,
"log_file": log_file,
}
self._definition.update(**kwargs)

self.variable_types, self.variable_parts = comparisons(self.components)

self.n_type_indicators = len(self.variable_types) - 1
Expand All @@ -62,8 +52,7 @@ def __init__(
fields = self.fields(field)

self.higher_vars = [
DerivedType(variable, field_type)
for variable, field_type in fields
DerivedType(variable, field_type) for variable, field_type in fields
]

self.log_file = log_file
Expand Down Expand Up @@ -100,12 +89,6 @@ def tag(self, field, *args):

return result

def __getstate__(self):
return self._definition.copy()

def __setstate__(self, d):
self.__init__(**d)

def comparator(self, field_1, field_2):
distances = numpy.zeros(self.expanded_size)
i = 0
Expand Down Expand Up @@ -167,7 +150,8 @@ def fields(self, field):
fields += [(part, "Derived") for part in self.variable_parts]

fields += [
("%s: Not Missing" % (part,), "Not Missing") for part in self.variable_parts
("{}: Not Missing".format(part), "Not Missing")
for part in self.variable_parts
]

fields += [("full string", "String")]
Expand Down
12 changes: 6 additions & 6 deletions parseratorvariable/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from probableparsing import RepeatedLabelError


class PartialIndex(object):
class PartialIndex:
def __init__(self, *args, **kwargs):
self.part = kwargs.pop("part")
self.tag = kwargs.pop("tag")
super(PartialIndex, self).__init__(*args, **kwargs)
self.__name__ = "(%s, %s, %s)" % (self.threshold, self.field, self.part)
super().__init__(*args, **kwargs)
self.__name__ = "({}, {}, {})".format(self.threshold, self.field, self.part)

def preprocess(self, doc):
try:
Expand All @@ -16,7 +16,7 @@ def preprocess(self, doc):
part = ""
else:
part = tags.get(self.part, "")
return super(PartialIndex, self).preprocess(part)
return super().preprocess(part)


class PLCPredicate(PartialIndex, predicates.LevenshteinCanopyPredicate):
Expand Down Expand Up @@ -48,7 +48,7 @@ class PartialString(predicates.StringPredicate):

def __init__(self, func, field, part, tag):
self.func = func
self.__name__ = "(%s, %s, %s)" % (func.__name__, field, part)
self.__name__ = "({}, {}, {})".format(func.__name__, field, part)
self.field = field
self.part = part
self.tag = tag
Expand All @@ -65,4 +65,4 @@ def __call__(self, record, **kwargs):
else:
part = tags.get(self.part, "")

return super(PartialString, self).__call__({self.field: part})
return super().__call__({self.field: part})

0 comments on commit 9271305

Please sign in to comment.