コード例 #1
0
    def __new__(self, annotationFile="../annotate/emo20q.txt"):
        # read in tournament, do some testing, get some stats
        tournament = HumanHumanTournament(annotationFile)

        #count turns in a dict, for pruning
        qcounts = defaultdict(int)
        for m in tournament.matches():
            for t in m.turns():
                qcounts[t.qgloss] += 1

        #create graph
        G = nx.MultiDiGraph()
        G.add_node("Emotion")

        #add emo20q data to graph
        for m in tournament.matches():
            H = nx.MultiDiGraph()
            parent = "Emotion"
            prevAns = "yes"
            H.add_node(parent)
            for t in m.turns():
                if (qcounts[t.qgloss] < 2): continue
                #deal with guesses:
                guess = re.search(r'^e==(\w+)$', t.qgloss)
                if (guess):
                    H.add_edge(parent, guess.group(1), ans=prevAns)
                    #G.add_nodes_from(H)
                    continue
                #deal with questions
                if (t.qgloss.find("non-yes-no") == 0): continue
                if (t.qgloss.find("giveup") == 0): continue
                ans = "other"
                if t.agloss.find("yes") == 0: ans = "yes"
                if t.agloss.find("no") == 0: ans = "no"
                #if ans == "other": continue
                H.add_edge(parent, t.qgloss, ans=prevAns)
                parent = t.qgloss
                prevAns = ans

            else:  #python has for... else!
                # if(parent == "Emotion"):   # add intermediate node
                #    H.add_edge(parent,"LowFrequencyGuesses")
                #    parent = "LowFrequencyGuesses"

                emotionSynonyms = re.search(r'(\w+)(?:/(\w+))*$', m.emotion())
                for e in emotionSynonyms.groups():
                    if e is not None: H.add_edge(parent, e, ans=prevAns)

                    # plt.figure(figsize=(18,18))
                    # pos=nx.graphviz_layout(H,prog='twopi',root='Emotion',args='',)
                    # nx.draw(H,pos,node_size=10,alpha=0.5,node_color="blue", with_labels=True)

                    # edge_labels=dict([((u,v,),d['ans'])
                    #                   for u,v,d in H.edges(data=True)])
                    # nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_labels)
                    # plt.show()
                G.add_edges_from(H.edges(data=True))

        return G
コード例 #2
0
   def __new__(self, annotationFile="../annotate/emo20q.txt"):
      # read in tournament, do some testing, get some stats
      tournament = HumanHumanTournament(annotationFile)
      
      #count turns in a dict, for pruning
      qcounts = defaultdict(int)
      for m in tournament.matches():
         for t in m.turns(): 
            qcounts[t.qgloss]+=1 

      #create graph
      G = nx.MultiDiGraph()
      G.add_node("Emotion")

      #add emo20q data to graph
      for m in tournament.matches():
         H = nx.MultiDiGraph()
         parent = "Emotion"
         prevAns = "yes"
         H.add_node(parent)
         for t in m.turns():
            if(qcounts[t.qgloss]<2): continue
            #deal with guesses:
            guess = re.search(r'^e==(\w+)$',t.qgloss )
            if(guess):
               H.add_edge(parent,guess.group(1),ans=prevAns)
               #G.add_nodes_from(H)
               continue
            #deal with questions
            if (t.qgloss.find("non-yes-no")==0): continue
            if (t.qgloss.find("giveup")==0): continue
            ans = "other" 
            if t.agloss.find("yes") == 0 : ans = "yes" 
            if t.agloss.find("no") == 0 : ans = "no"
            #if ans == "other": continue
            H.add_edge(parent,t.qgloss,ans=prevAns)
            parent = t.qgloss 
            prevAns = ans

         else:  #python has for... else!
            # if(parent == "Emotion"):   # add intermediate node 
            #    H.add_edge(parent,"LowFrequencyGuesses")
            #    parent = "LowFrequencyGuesses"
               
            emotionSynonyms = re.search(r'(\w+)(?:/(\w+))*$',m.emotion() )
            for e in emotionSynonyms.groups():
               if e is not None: H.add_edge(parent,e,ans=prevAns)

               # plt.figure(figsize=(18,18))
               # pos=nx.graphviz_layout(H,prog='twopi',root='Emotion',args='',)
               # nx.draw(H,pos,node_size=10,alpha=0.5,node_color="blue", with_labels=True)
               
               # edge_labels=dict([((u,v,),d['ans']) 
               #                   for u,v,d in H.edges(data=True)]) 
               # nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_labels) 
               # plt.show()
            G.add_edges_from(H.edges(data=True))

      return G
コード例 #3
0
    def __new__(self, annotationFile="../annotate/emo20q.txt"):
        # read in tournament, do some testing, get some stats
        tournament = HumanHumanTournament(annotationFile)

        #count turns in a dict, for pruning
        qcounts = defaultdict(int)
        for m in tournament.matches():
            for t in m.turns():
                qcounts[t.qgloss] += 1

        #create graph
        G = nx.DiGraph()
        G.add_node("Emotion")

        #add emo20q data to graph
        for m_idx, m in enumerate(tournament.matches()):
            H = nx.DiGraph()
            parent = "Emotion"
            edge = "yes"
            H.add_node(parent)
            for t in m.turns():
                if (qcounts[t.qgloss] > 1):
                    #deal with guesses:
                    guess = re.search(r'^e==(\w+)$', t.qgloss)
                    if (guess):
                        H.add_edge(parent, guess.group(1))
                        #G.add_nodes_from(H)
                        continue
                    #deal with questions
                    if (t.qgloss.find("non-yes-no") == 0): continue
                    if (t.qgloss.find("giveup") == 0): continue
                    ans = "other"
                    if t.agloss.find("yes") == 0: ans = "yes"
                    if t.agloss.find("no") == 0: ans = "no"
                    #if ans == "other": continue
                    newNode = (t.qgloss, ans)
                    H.add_edge(parent, newNode)
                    parent = newNode

            else:  #python has for... else!
                # if(parent == "Emotion"):   # add intermediate node
                #    H.add_edge(parent,"LowFrequencyGuesses")
                #    parent = "LowFrequencyGuesses"

                emotionSynonyms = re.search(r'(\w+)(?:/(\w+))*$', m.emotion())
                for e in emotionSynonyms.groups():
                    if e is not None: H.add_edge(parent, e)
                G.add_edges_from(H.edges())
        return G
コード例 #4
0
    def __init__(self):
        # read in tournament, do some testing, get some stats
        tournament = HumanHumanTournament()

        self._dictionary = defaultdict(list)

        for m in tournament.matches():
            for t in m.turns():
                self._dictionary[t.questionId()].append(t.q)
コード例 #5
0
   def __init__(self):
      # read in tournament, do some testing, get some stats
      tournament = HumanHumanTournament()
      
      self._dictionary = defaultdict(list)

      for m in tournament.matches():
         for t in m.turns():
            self._dictionary[t.questionId()].append(t.q)
コード例 #6
0
            out['param'] = {'type':x.type}
        if x.provenance: 
            out['param'] = {'provenance':x.provenance}
        out['container'] = [{'type':'Match', 
                             'container':x.turns()}] 
        #out['turns'] = []
        return out
    if isinstance(x,Turn):
        out['type'] = 'Turn'
        out['container'] = [{'type':'Question',
                             'param':{'text':x.q,
                                      'gloss':x.qgloss}},
                            {'type':'Answer',
                             'param':{'text':x.a,
                                      'gloss':x.agloss}}]
        return out
        #return {}

for m in hh.matches():
    m.type='dialog:human-human'
    m.provenance= ['xmpp','text','students','generation0']
    #create empty dialog in couch
    
    #print dir(m)
    
    #print json.dumps(m,sys.stdout,default=match2JsonEncoder,sort_keys=True, indent=2)
    #time.sleep(0.1)
    doc_id, doc_rev = db.save(json.loads(json.dumps(m,sys.stdout,default=match2JsonEncoder,sort_keys=False, indent=2)))
    print
    #    print t.qgloss
コード例 #7
0
    def __new__(self, annotationFile="../annotate/emo20q.txt"):
        # read in tournament, do some testing, get some stats
        tournament = HumanHumanTournament(
            annotationFile) + HumanComputerTournament()

        #count turns in a dict, for pruning
        qcounts = defaultdict(int)
        for m in tournament.matches():
            for t in m.turns():
                qcounts[t.qgloss] += 1

        #create graph
        G = nx.DiGraph()
        G.add_node(("Emotion", ))

        #add emo20q data to graph
        for m_idx, m in enumerate(tournament.matches()):
            H = nx.DiGraph()
            parent = ("Emotion", )
            edge = "yes"
            H.add_node(parent)
            for t in m.turns():
                if (qcounts[t.qgloss] > 0):
                    #deal with guesses:
                    guess = re.search(r'^e==(\w+)(\|\|.*)*$', t.qgloss)
                    if (guess):
                        #if re.search(r'close', t.a ): #connect a close guess
                        #   H.add_edge(parent,guess.group(1), weight=20)
                        continue
                    #deal with questions
                    if (t.qgloss.find("non-yes-no") == 0): continue
                    if (t.qgloss.find("clarification") == 0): continue
                    if (t.qgloss.find("giveup") == 0): continue
                    ans = "other"
                    # #use nlp module here!
                    # if t.a.find("yes") == 0 :
                    #    ans = "yes"
                    #    weight = -5
                    # if t.a.find("no") == 0 :
                    #    ans = "no"
                    #    weight = 2
                    # if ans == "other":
                    #    weight = 5
                    if nlp.classifyYN(t.a) == 1:
                        ans = "yes"
                        weight = -1
                    if nlp.classifyYN(t.a) == -1:
                        ans = "no"
                        weight = 0
                    if ans == "other":
                        weight = 1

                    newNode = parent, (t.qgloss, ans)
                    H.add_edge(parent, newNode, weight=weight)
                    parent = newNode

                    if t.qgloss == "e.valence==positive" and m.emotion(
                    ) == "happiness" and ans == "no":
                        print "wtf!"
                        print t.qgloss, t.a, m.emotion()
                        for t in m.turns():
                            print t.qgloss, t.a
            else:  #python has for... else!
                #if(parent == "Emotion"):   # add intermediate node
                #   H.add_edge(parent,"LowFrequencyGuesses")
                #   parent = "LowFrequencyGuesses"

                emotionSynonyms = re.search(r'(\w+)(?:/(\w+))*$', m.emotion())
                for e in emotionSynonyms.groups():
                    if e is not None: H.add_edge(parent, e, weight=20)
                G.add_edges_from(H.edges(data=True))
        return G
コード例 #8
0
#!/usr/bin/python

from emo20q.data.base import HumanHumanTournament
import networkx as nx
from networkx import graphviz_layout
import matplotlib.pyplot as plt
from collections import defaultdict
import re

# read in tournament, do some testing, get some stats
tournament = HumanHumanTournament("../annotate/emo20q.txt")

#count turns in a dict, for pruning
qcounts = defaultdict(int)
for m in tournament.matches():
    for t in m.turns():
        qcounts[t.qgloss] += 1

#create graph
G = nx.DiGraph()
G.add_node(("Emotion", ))

#add emo20q data to graph
for m_idx, m in enumerate(tournament.matches()):
    H = nx.DiGraph()
    parent = "Emotion",
    #parent = ()
    H.add_node(parent)
    for t in m.turns():
        if (qcounts[t.qgloss] > 10):
            #deal with guesses:
コード例 #9
0
from emo20q.data.base import HumanHumanTournament
import networkx as nx
from networkx import graphviz_layout
import matplotlib.pyplot as plt
from collections import defaultdict
import re



# read in tournament, do some testing, get some stats
tournament = HumanHumanTournament("../annotate/emo20q.txt")

#count turns in a dict, for pruning
qcounts = defaultdict(int)
for m in tournament.matches():
   for t in m.turns(): 
       qcounts[t.qgloss]+=1 

#create graph
G = nx.DiGraph()
G.add_node(("Emotion",))

#add emo20q data to graph
for m_idx,m in enumerate(tournament.matches()):
   H = nx.DiGraph()
   parent = "Emotion",
   #parent = ()
   H.add_node(parent)
   for t in m.turns():
      if(qcounts[t.qgloss]>10):
コード例 #10
0
            'param': {
                'text': x.q,
                'gloss': x.qgloss
            }
        }, {
            'type': 'Answer',
            'param': {
                'text': x.a,
                'gloss': x.agloss
            }
        }]
        return out
        #return {}


for m in hh.matches():
    m.type = 'dialog:human-human'
    m.provenance = ['xmpp', 'text', 'students', 'generation0']
    #create empty dialog in couch

    #print dir(m)

    #print json.dumps(m,sys.stdout,default=match2JsonEncoder,sort_keys=True, indent=2)
    #time.sleep(0.1)
    doc_id, doc_rev = db.save(
        json.loads(
            json.dumps(m,
                       sys.stdout,
                       default=match2JsonEncoder,
                       sort_keys=False,
                       indent=2)))