Skip to content

Commit

Permalink
with window analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jun 5, 2016
1 parent 369ed48 commit 54b78f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions empath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def load(self,file):
self.cats[name].append(t)
#self.invcats[t].append(name)

def analyze_term_window(self,doc,targets,categories=None,window_size=10,normalize=False):
tokenizer = util.window_tokenizer(window_size,targets)
return self.analyze(doc,categories,tokenizer,normalize)

def analyze(self,doc,categories=None,tokenizer="default",normalize=False):
if isinstance(doc,list):
doc = "\n".join(doc)
Expand Down
2 changes: 1 addition & 1 deletion empath/data/categories.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ giving bring generous thank favor save return generously redeem earn gift thankf
contentment languid pleaser closeness pulsing fullness happiness gentleness nostalgia fervor pleasing pleasurable amorous compassion tantalizing kindness thrill profound delightful delightfully sensation arouse momentary familiarity exhilaration passion gratitude joy relaxation lightness bask fondness deliciously certainty sweetness feel satisfaction remembrance moan contentment bliss tranquillity tranquility appreciation orgasm warmth excitement feeling affection coolness contented fulfillment genuine savor pure enjoyment delight pleasure calmness relief intimacy gratification
writing essay poetry paper thesis portfolio creative parchment write calligraphy tablet writing blackboard clipboard stationery brainstorm homework descriptive notation read eulogy diary postcard list summary revision page wrote lettering excerpt scribe compile font publish pen paragraph assignment print reading email blurb handwritten jot booklet journal binder article scribbling planner informational revise manuscript pamphlet marker poem sheet script transcript handbook typing pencil paperwork paperback detail brochure copy word instruction chalk printing neat editorial newspaper handwriting prompt rewrite file ink autobiography typed author alphabet note book composition typewriter quote notebook printed letter bulletin entry
rural ramshackle barren cornfield schoolhouse quaint plantation townsfolk folk forested idyllic scenic farmhouse meadow uninhabited prairie migration southwest settlement farm wheat outlying farmland environment settler road secluded colony county village campground landscape vineyard west locally lakeside live acre farming farmer wildlife landscaping western cottage valley heartland bungalow property tractor grassy pasture cultivate picturesque woodland isolated barn province agricultural countryside resident grove ranch south grassland rural inhabitant
positive_emotion happiness enlighten better enthusiasm pride joyful compassion dearly forgiving kindness bravery closure thrill honestly triumph bond honesty alive concern reunite joy surprise forgiveness assurance sympathize understanding reason rejoice care faith great empathy certainty keep trustworthy affection cherish emotion love family trusting respect trust gratitude confidence adoration friend happy overjoyed determination reassurance glad loved admiration wish accomplishment optimism excitement convince hope freedom feeling eagerness willingness sincere sincerity honest genuine comfort elation thrilled loyalty curiosity unconditionally proud
positive_emotion happiness enlighten better enthusiasm pride joyful compassion dearly forgiving kindness bravery closure thrill honestly triumph bond honesty alive concern reunite joy surprise forgiveness assurance sympathize understanding reason rejoice care faith great empathy certainty keep trustworthy affection cherish emotion love family trusting respect trust gratitude confidence adoration friend happy overjoyed determination reassurance glad loved admiration wish accomplishment optimism excitement convince hope freedom feeling eagerness willingness sincere sincerity honest genuine comfort elation thrilled loyalty curiosity unconditionally proud
musical chord producer radio keyboard clarinet ballet harmonica glee instrument production rhythm piano songwriting string song songwriter band banjo artist audience saxophone acoustic gospel quartet auditorium concert turntable medley melody harp album chorus rehearse orchestra lyric violinist rendition solo bass compilation guitar tuner genre sing impromptu lyrical soundtrack drumming drum talented musically cd composer singing classical theme interlude gig hymn symphony music upbeat ballad melodic hum musician singer instrumental burlesque soprano vocal video duet performer classic soloist sax tenor violin trumpet mainstream dancing perform guitarist actor note freestyle drummer harmony performance pianist jamming composition reggae play jazz theatre collaboration flute rehearsal audition vocalist tune nirvana recital playing riff bassist audio musical
25 changes: 25 additions & 0 deletions empath/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
from itertools import islice

def partitions(l, n):
for i in range(0, len(l), n):
yield l[i:i+n]

def window(seq, n):
it = iter(seq)
result = tuple(islice(it, n))
if len(result) == n:
yield result
for elem in it:
result = result[1:] + (elem,)
yield result

def default_tokenizer(doc):
return doc.split()

Expand All @@ -7,3 +22,13 @@ def bigram_tokenizer(doc):
yield t1
yield t1+"_"+t2
yield tokens[-1]

def window_tokenizer(window_size, targets):
def window_func(doc,target_dic={t:t for t in targets}):
tokens = doc.split()
print(tokens)
for w in partitions(tokens, window_size):
if any([x in target_dic for x in w]):
for w_ in w:
yield w_
return window_func

0 comments on commit 54b78f6

Please sign in to comment.