Skip to content

Commit

Permalink
with cat construction cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Fast authored and Ethan Fast committed Jun 6, 2016
1 parent 945893f commit fe3251c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions empath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, backend_url="http://54.148.189.209:8000"):
self.staging = {}
self.backend_url = backend_url
self.base_dir = os.path.dirname(util.__file__)
self.inv_cache = {}
self.load(self.base_dir+"/data/categories.tsv")
for f in os.listdir(self.base_dir+"/data/user/"):
if len(f.split(".")) > 1 and f.split(".")[1] == "empath":
Expand Down Expand Up @@ -42,8 +43,13 @@ def analyze(self,doc,categories=None,tokenizer="default",normalize=False):
if not categories:
categories = self.cats.keys()
invcats = defaultdict(list)
for k in categories:
for t in self.cats[k]: invcats[t].append(k)
key = tuple(sorted(categories))
if key in self.inv_cache:
invcats = self.inv_cache[key]
else:
for k in categories:
for t in self.cats[k]: invcats[t].append(k)
self.inv_cache[key] = invcats
count = {}
tokens = 0.0
for cat in categories: count[cat] = 0.0
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
setup(
name = 'empath',
packages = ['empath'], # this must be the same as the name above
version = '0.088',
version = '0.089',
description = 'A tool for text analysis',
author = 'Ethan Fast',
author_email = '[email protected]',
url = 'https://github.com/Ejhfast/empath-client', # use the URL to the github repo
download_url = 'https://github.com/Ejhfast/meta/empath-client/0.39',
download_url = 'https://github.com/Ejhfast/meta/empath-client/0.40',
keywords = ['social science', 'lexicon', 'text analysis'], # arbitrary keywords
package_data= { 'empath': ['data/categories.tsv', "data/user/blank"]},
classifiers = [],
Expand Down
2 changes: 2 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
empath = Empath()

print(empath.analyze(["this","that"]))
print(empath.analyze(["this","that"]))
print(empath.analyze("the person typed on the keyboard"))

0 comments on commit fe3251c

Please sign in to comment.