Skip to content

Instantly share code, notes, and snippets.

@shogo82148
Created July 24, 2012 11:35
Show Gist options
  • Save shogo82148/3169498 to your computer and use it in GitHub Desktop.
Save shogo82148/3169498 to your computer and use it in GitHub Desktop.
Memo for tojima
def exstractFeature1(text):
return [len(text)]
class HasChar(object):
def __init__(self, ch):
self.ch = ch
def __call__(self, text):
return [0 if text.find(self.ch)<0 else 1]
class FeatureExtractor(object):
def __init__(self, features):
self._features = features
def __call__(self, text):
new_feature = []
for f in self._features:
new_feature.extend(f(text))
return new_feature
d = {
'Length': exstractFeature1,
'HasA': HasChar('A'),
'HasB': HasChar('B'),
}
features = FeatureExtractor(d.values())
print features('HAS') #-> [3, 1, 0]
@shogo82148
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment