Created
July 24, 2012 11:35
-
-
Save shogo82148/3169498 to your computer and use it in GitHub Desktop.
Memo for tojima
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
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果