Last active
June 4, 2016 00:23
-
-
Save milesrout/cfcfac51e8544358b59b111b3ea914d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def accumulate(accum_type): | |
def outer_wrapper(f): | |
@functools.wraps(f) | |
def inner_wrapper(*args, **kwds): | |
return accum_type(iter(f(*args, **kwds))) | |
return inner_wrapper | |
return outer_wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyaccum import accumulate | |
# ORIGINAL CODE | |
class Conjunction: | |
def min_spec(self, neginst, attributes): | |
return list(self._min_spec(neginst, attributes)) | |
def _min_spec(self, neginst, attributes): | |
for i in range(len(self)): | |
if is_wildcard(self[i]): | |
for v in attributes[i]: | |
hypothesis = Conjunction(v if i == j else self[j] for j in range(len(self))) | |
if not hypothesis.match(neginst): | |
yield hypothesis | |
# NEW CODE | |
class Conjunction: | |
@accumulate(list) | |
def min_spec(self, neginst, attributes): | |
for i in range(len(self)): | |
if is_wildcard(self[i]): | |
for v in attributes[i]: | |
hypothesis = Conjunction(v if i == j else self[j] for j in range(len(self))) | |
if not hypothesis.match(neginst): | |
yield hypothesis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyaccum import accumulate | |
# ORIGINAL CODE | |
class Conjunction: | |
def min_gen(self, inst): | |
return [self._min_gen(inst)] | |
def _min_gen(self, inst): | |
features = [] | |
for i in range(len(self)): | |
if self[i] is None: | |
features.append(inst[i]) | |
elif is_wildcard(self[i]) or self[i] == inst[i]: | |
features.append(self[i]) | |
else: | |
features.append(Wildcard) | |
return Conjunction(tuple(features)) | |
# NEW CODE | |
class Conjunction: | |
@accumulate(lambda x: [Conjunction(tuple(x))]) | |
def min_gen(self, inst): | |
for i in range(len(self)): | |
if self[i] is None: | |
yield inst[i] | |
elif is_wildcard(self[i]) or self[i] == inst[i]: | |
yield self[i] | |
else: | |
yield Wildcard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment