コード例 #1
0
ファイル: oovfreeling.py プロジェクト: zni1/pghumor
    def calcular_feature(self, tweet):
        texto = tweet.texto
        texto = remover_hashtags(texto)
        texto = remover_usuarios(texto)
        oraciones = Freeling.procesar_texto(texto)
        tokens = list(itertools.chain(*oraciones))

        cant_palabras_oov = 0
        for token_freeling in tokens:
            if not token_freeling.tag.startswith('F') \
                    and not token_freeling.tag.startswith('Z') \
                    and not token_freeling.tag.startswith('W'):
                token = eliminar_underscores(token_freeling.token)
                if not Freeling.esta_en_diccionario(token):
                    cant_palabras_oov += 1

        if len(tokens) == 0:
            return 0
        else:
            return cant_palabras_oov / math.sqrt(len(tokens))
コード例 #2
0
ファイル: oov.py プロジェクト: bryant1410/pghumor
    def calcular_feature(self, tweet):
        texto = tweet.texto
        texto = remover_hashtags(texto)
        texto = remover_usuarios(texto)
        oraciones = Freeling.procesar_texto(texto)
        tokens = list(itertools.chain(*oraciones))

        cant_palabras_oov = 0
        for token_freeling in tokens:
            if not token_freeling.tag.startswith('F') \
                    and not token_freeling.tag.startswith('Z') \
                    and not token_freeling.tag.startswith('W'):
                token = eliminar_underscores(token_freeling.token)
                if not Freeling.esta_en_diccionario(token) and not Google.esta_en_google(token):
                    cant_palabras_oov += 1

        if len(tokens) == 0:
            return 0
        else:
            return cant_palabras_oov / math.sqrt(len(tokens))
コード例 #3
0
ファイル: exclamacion.py プロジェクト: zni1/pghumor
    def calcular_feature(self, tweet):
        freeling = Freeling(tweet)

        exclamaciones = 0
        for token in freeling.tokens:
            if token.tag == 'Fat' or token.tag == 'Faa':
                exclamaciones += 1

        if len(freeling.tokens) == 0:
            return 0
        else:
            return exclamaciones / math.sqrt(len(freeling.tokens))
コード例 #4
0
ファイル: negacion.py プロジェクト: zni1/pghumor
    def calcular_feature(self, tweet):
        freeling = Freeling(tweet)

        negaciones = 0
        for token in freeling.tokens:
            if token.token.lower() == 'no':
                negaciones += 1

        if len(freeling.tokens) == 0:
            return 0
        else:
            return negaciones / math.sqrt(len(freeling.tokens))
コード例 #5
0
    def calcular_feature(self, tweet):
        oraciones = Freeling.procesar_texto(remover_hashtags(remover_usuarios(tweet.texto)))
        tokens = Freeling.get_tokens_de_oraciones(oraciones)

        cant_antonimos = 0

        for token in tokens:
            antonimos = []
            for synset in self.wncr.synsets(token.lemma):
                for lemma in synset.lemmas():
                    antonimos += [lemma_antonimo.name() for lemma_antonimo in lemma.antonyms()]

            for otro_token in tokens:
                if otro_token.lemma in antonimos:
                    cant_antonimos += 1
                    break

        if len(tokens) == 0:
            return 0
        else:
            return cant_antonimos / math.sqrt(len(tokens)) / 2.0  # divido entre 2 para contar una vez cada par
コード例 #6
0
ファイル: npersona.py プロジェクト: zni1/pghumor
    def calcular_feature(self, tweet):
        tf = Freeling(tweet)
        primera_persona = 0
        for token in tf.tokens:
            if esta_en_persona(token.tag, self.persona):
                primera_persona += 1

        if len(tf.tokens) == 0:
            print("Error de tokens vacíos en " + self.nombre + ": ",
                  tweet.texto)
            return 0
        else:
            return primera_persona / math.sqrt(len(tf.tokens))
コード例 #7
0
    def test_escapar(self):
        tweet = Tweet()
        tweet.id = 58179039764021248
        tweet.texto = "3 Cosas que he aprendi en la escuela: Enviar WhatsApp's sin mirar. Dormir sin que me vean." \
                      + " El trabajo en equipo durante los exámenes."
        tweet.texto_original = tweet.texto
        tweet.favoritos = 3
        tweet.retweets = 14
        tweet.es_humor = 1
        tweet.cuenta = 132679073

        freeling = Freeling(tweet)
        self.assertNotEqual(freeling.tokens, [], "Error de tokens vacíos")
コード例 #8
0
    def calcular_feature(self, tweet):
        tf = Freeling(tweet)
        cant_palabras_sexuales = 0
        for token in tf.tokens:
            if token.token in self.palabrasSexuales or token.lemma in self.palabrasSexuales:
                cant_palabras_sexuales += 1

        if len(tf.tokens) == 0:
            print("Error de tokens vacíos en " + self.nombre + ": ",
                  tweet.texto)
            return 0
        else:
            return cant_palabras_sexuales / math.sqrt(len(tf.tokens))
コード例 #9
0
ファイル: testfreeling.py プロジェクト: bryant1410/pghumor
 def test_procesar_texto_una_oracion(self):
     texto = "Hola, ¿cómo andás?"
     resultado = Freeling.procesar_texto(texto)
     esperado = [
         [
             TokenFL('hola', 'hola', 'I', '1'),
             TokenFL(',', ',', 'Fc', '1'),
             TokenFL('¿', '¿', 'Fia', '1'),
             TokenFL('cómo', 'cómo', 'PT000000', '0.993927'),
             TokenFL('andás', 'andás', 'VMIF2S0', '0.00938678'),
             TokenFL('?', '?', 'Fit', '1'),
         ],
     ]
     self.assertEquals(esperado, resultado,
                       "El parseo del texto \"" + texto + "\" no coincide con el esperado")
コード例 #10
0
 def test_procesar_texto_una_oracion(self):
     texto = "Hola, ¿cómo andás?"
     resultado = Freeling.procesar_texto(texto)
     esperado = [
         [
             TokenFL('hola', 'hola', 'I', '1'),
             TokenFL(',', ',', 'Fc', '1'),
             TokenFL('¿', '¿', 'Fia', '1'),
             TokenFL('cómo', 'cómo', 'PT000000', '0.993927'),
             TokenFL('andás', 'andás', 'VMIF2S0', '0.00938678'),
             TokenFL('?', '?', 'Fit', '1'),
         ],
     ]
     self.assertEquals(
         esperado, resultado, "El parseo del texto \"" + texto +
         "\" no coincide con el esperado")
コード例 #11
0
ファイル: testfreeling.py プロジェクト: bryant1410/pghumor
 def test_procesar_texto_dos_oraciones(self):  # TODO: agregar test de tres oraciones
     texto = "Hola. ¿Cómo andás?"
     resultado = Freeling.procesar_texto(texto)
     esperado = [
         [
             TokenFL('hola', 'hola', 'I', '1'),
             TokenFL('.', '.', 'Fp', '1'),
         ],
         [
             TokenFL('¿', '¿', 'Fia', '1'),
             TokenFL('cómo', 'cómo', 'PT000000', '0.993927'),
             TokenFL('andás', 'andás', 'VMIF2S0', '0.00938678'),
             TokenFL('?', '?', 'Fit', '1'),
         ],
     ]
     self.assertEquals(esperado, resultado,
                       "El parseo del texto \"" + texto + "\" no coincide con el esperado")
コード例 #12
0
ファイル: palabrasnoespanolas.py プロジェクト: zni1/pghumor
    def calcular_feature(self, tweet):
        texto = tweet.texto
        texto = remover_hashtags(texto)
        texto = remover_usuarios(texto)
        oraciones = Freeling.procesar_texto(texto)
        tokens = list(itertools.chain(*oraciones))

        cant_palabras_no_espanolas = 0
        for token_freeling in tokens:
            token = eliminar_underscores(token_freeling.token)
            if len(token) >= 3 and contiene_caracteres_no_espanoles(token):
                cant_palabras_no_espanolas += 1

        if len(tokens) == 0:
            return 0
        else:
            return cant_palabras_no_espanolas / math.sqrt(len(tokens))
コード例 #13
0
 def test_procesar_texto_dos_oraciones(
         self):  # TODO: agregar test de tres oraciones
     texto = "Hola. ¿Cómo andás?"
     resultado = Freeling.procesar_texto(texto)
     esperado = [
         [
             TokenFL('hola', 'hola', 'I', '1'),
             TokenFL('.', '.', 'Fp', '1'),
         ],
         [
             TokenFL('¿', '¿', 'Fia', '1'),
             TokenFL('cómo', 'cómo', 'PT000000', '0.993927'),
             TokenFL('andás', 'andás', 'VMIF2S0', '0.00938678'),
             TokenFL('?', '?', 'Fit', '1'),
         ],
     ]
     self.assertEquals(
         esperado, resultado, "El parseo del texto \"" + texto +
         "\" no coincide con el esperado")
コード例 #14
0
ファイル: testfreeling.py プロジェクト: bryant1410/pghumor
 def test_esta_en_diccionario_palabra_inexistente(self):
     texto = "wkalskjv"
     self.assertFalse(Freeling.esta_en_diccionario(texto),
                      "No debería estar en el diccionario el texto \"" + texto + "\"")
コード例 #15
0
 def test_esta_en_diccionario_palabra_inexistente(self):
     texto = "wkalskjv"
     self.assertFalse(
         Freeling.esta_en_diccionario(texto),
         "No debería estar en el diccionario el texto \"" + texto + "\"")
コード例 #16
0
 def test_esta_en_diccionario_palabra_comun(self):
     texto = "reja"
     self.assertTrue(
         Freeling.esta_en_diccionario(texto),
         "Debería estar en el diccionario el texto \"" + texto + "\"")
コード例 #17
0
ファイル: utilanalisis.py プロジェクト: bryant1410/pghumor
def tweets_parecidos_con_distinto_humor(corpus):
    print("Buscando tweets muy parecidos pero con distinto valor de humor...")

    parecidos_con_distinto_humor = set()

    ids_parecidos_con_distinto_humor = cargar_parecidos_con_distinto_humor()

    if ids_parecidos_con_distinto_humor:
        corpus_por_id = {tweet.id: tweet for tweet in corpus}
        for id_tweet_humor, id_tweet_no_humor in ids_parecidos_con_distinto_humor:
            parecidos_con_distinto_humor.add((corpus_por_id[id_tweet_humor], corpus_por_id[id_tweet_no_humor]))
    else:
        subcorpus_cuentas_de_humor = []
        subsubcorpus_cuentas_de_humor_humor = []
        subsubcorpus_cuentas_de_humor_no_humor = []
        for tweet in corpus:
            if tweet.es_chiste:
                subcorpus_cuentas_de_humor.append(tweet)
                if tweet.es_humor:
                    subsubcorpus_cuentas_de_humor_humor.append(tweet)
                else:
                    subsubcorpus_cuentas_de_humor_no_humor.append(tweet)

        subsubcorpus_cuentas_de_humor_no_humor_por_largo = defaultdict(list)

        bar = IncrementalBar("Tokenizando\t\t\t", max=len(subcorpus_cuentas_de_humor),
                             suffix=SUFIJO_PROGRESS_BAR)
        bar.next(0)
        for tweet_cuenta_humor in subcorpus_cuentas_de_humor:
            tweet_cuenta_humor.oraciones = Freeling.procesar_texto(tweet_cuenta_humor.texto_original)
            tweet_cuenta_humor.tokens = list(itertools.chain(*tweet_cuenta_humor.oraciones))
            bar.next()
        bar.finish()

        for tweet_no_humor in subsubcorpus_cuentas_de_humor_no_humor:
            subsubcorpus_cuentas_de_humor_no_humor_por_largo[len(tweet_no_humor.tokens)].append(tweet_no_humor)

        bar = IncrementalBar("Buscando en tweets\t\t", max=len(subsubcorpus_cuentas_de_humor_humor),
                             suffix=SUFIJO_PROGRESS_BAR)
        bar.next(0)
        for tweet_humor in subsubcorpus_cuentas_de_humor_humor:
            margen = int(round(len(tweet_humor.tokens) / 5))
            largo_min = len(tweet_humor.tokens) - margen
            largo_max = len(tweet_humor.tokens) + margen

            for largo in range(largo_min, largo_max + 1):
                for tweet_no_humor in subsubcorpus_cuentas_de_humor_no_humor_por_largo[largo]:
                    if distancia_edicion(tweet_humor.tokens, tweet_no_humor.tokens)\
                            <= max(len(tweet_humor.tokens), len(tweet_no_humor.tokens)) / 5:
                        parecidos_con_distinto_humor.add((tweet_humor, tweet_no_humor))
                        print('')
                        print(tweet_humor.id)
                        print(tweet_humor.texto_original)
                        print("------------")
                        print(tweet_no_humor.id)
                        print(tweet_no_humor.texto_original)
                        print("------------")
                        print('')
            bar.next()
        bar.finish()

        guardar_parecidos_con_distinto_humor(parecidos_con_distinto_humor)

    return parecidos_con_distinto_humor
コード例 #18
0
ファイル: testfreeling.py プロジェクト: bryant1410/pghumor
 def test_esta_en_diccionario_palabra_comun(self):
     texto = "reja"
     self.assertTrue(Freeling.esta_en_diccionario(texto),
                     "Debería estar en el diccionario el texto \"" + texto + "\"")