예제 #1
0
def entityRecognition(client, text: str) -> None:
    print(optionsTitle('--entity'))

    translatedText: str
    baseText: Dict[str, str]
    response: Dict[str, list]
    numberOfEntityFound: int
    wordlist: List[dict]

    if text:

        translatedText = traduzir('en', text)
        baseText = {"document": translatedText}

        algoritimo = client.algo('StanfordNLP/NamedEntityRecognition/0.2.0')
        response = algoritimo.pipe(baseText).result

        numberOfEntityFound = len(response['sentences'])
        wordlist = response['sentences'][numberOfEntityFound -
                                         1]['detectedEntities']

        if not wordlist:
            print("Não foram encontradas nenhuma entidade.")
            sys.exit(1)
        else:
            for name in wordlist:
                print(
                    f'Nome: {name["word"]} \nEntidade: {traduzir("pt", name["entity"]).capitalize()}'
                )

    else:
        print("Texto em branco.")
예제 #2
0
def getTags(client, arquivo: str) -> None:
    print(optionsTitle('--tag'))

    algoritimo = client.algo('nlp/AutoTag/1.0.1')
    response: List[str] = algoritimo.pipe(arquivo).result

    print(response)
예제 #3
0
def countWords(client, text: str) -> None:
    print(optionsTitle('--count'))

    algoritimo = client.algo('diego/WordCounter/0.1.0')
    response: int = algoritimo.pipe(text).result

    print(response)
예제 #4
0
def summarizeText(client, texto: str) -> None:
    print(optionsTitle('--summarize'))

    translatedText: str = traduzir('en', texto)
    algoritimo = client.algo('nlp/Summarizer/0.1.8')
    response: str = algoritimo.pipe(translatedText).result

    print(traduzir('pt', response))
예제 #5
0
def getTags(client: 'Client', text: str) -> NoReturn:
    from interface import texts

    print(texts.optionsTitle('tag'))

    algoritimo = client.algo('nlp/AutoTag/1.0.1')
    response: List[str] = algoritimo.pipe(text).result

    print(response)
예제 #6
0
def countWords(client: 'Client', text: str) -> NoReturn:
    from interface import texts

    print(texts.optionsTitle('count'))

    algoritimo = client.algo('diego/WordCounter/0.1.0')
    response: int = algoritimo.pipe(text).result

    print(response)
예제 #7
0
def emailExtract(client, text: str) -> None:
    print(optionsTitle('--email'))

    algo = client.algo('cindyxiaoxiaoli/EmailExtractor/0.2.0')
    response: List[str] = algo.pipe(text).result

    if len(response) >= 0:
        print(f'foram encontrados {len(response)} emails:\n')
        for item in response:
            print(f'{item}')
예제 #8
0
def summarizeText(client: 'Client', text: str) -> NoReturn:
    from utils.translate import traduzir
    from interface import texts

    print(texts.optionsTitle('summarize'))

    translatedText: str = traduzir('en', text)
    algoritimo = client.algo('nlp/Summarizer/0.1.8')
    response: str = algoritimo.pipe(translatedText).result

    print(traduzir('pt', response))
예제 #9
0
def emailExtract(client: 'Client', text: str) -> NoReturn:
    from interface import texts

    print(texts.optionsTitle('email'))

    algo = client.algo('cindyxiaoxiaoli/EmailExtractor/0.2.0')
    response: List[str] = algo.pipe(text).result

    if len(response) >= 0:
        print(f'foram encontrados {len(response)} emails:\n')
        for item in response:
            print(f'{item}')
예제 #10
0
def feelingAnalisys(client, sentenca: str) -> None:
    print(optionsTitle('--feeling'))

    text: Dict[str, str] = {"sentence": traduzir('en', sentenca)}

    algoritimo = client.algo('nlp/SocialSentimentAnalysis/0.1.4')
    response: List[dict] = algoritimo.pipe(text).result

    positive: int = math.floor(response[0]['positive'] * 100)
    negative: int = math.floor(response[0]['negative'] * 100)
    neutral: int = math.floor(response[0]['neutral'] * 100)

    print("Positivi: {}%\nNegativo: {}%\nNeutro: {}%".format(
        positive, negative, neutral))
예제 #11
0
def dateExtractor(client: 'Client', text: str) -> NoReturn:
    from utils.translate import traduzir
    from interface import texts

    print(texts.optionsTitle('date'))

    translatedText = traduzir('en', text)
    algorithm = client.algo('PetiteProgrammer/DateExtractor/0.1.0')
    response: List[str] = algorithm.pipe(translatedText).result

    if len(response) > 0:
        for date in response:
            print(date)
    else:
        print('Nenhuma data encontrada')
예제 #12
0
def frequencyOfWords(client, texto: str) -> None:
    print(optionsTitle('--frequency'))

    arguments: List[str] = sys.argv
    file: str = arguments[arguments.index('--file') + 1]

    try:
        wordCount: str = arguments[arguments.index('--frequency') + 1]
    except:
        print("Você não indicou o número de words analisadas!")
        print(
            f"analysis.py --file {file} --frequency [numero de words analisadas]")
        sys.exit(1)

    stopwords = [' a ', ' com ', ' da ', ' de ', ' do ',
                 ' e ', ' ele ', ' em ', ' na ', ' no ',
                 ' o ', ' para ', ' por ', ' que ', ' se ', ' sua ',
                 ' um ', ' uma ', ' os ', ' ao ', ' mais ', ' quando ',
                 ' como ', ' das ', ' vem ', ' ser ', ' foi ',  ' pela '
                 ]
    stopwordsWithoutSpace = ['a', 'com', 'da', 'de', 'de',
                             'do', 'e', 'ele', 'em', 'na', 'no',
                             'o', 'para', 'por', 'que', 'se', 'sua',
                             'um', 'uma', 'os', 'ao' 'mais', 'quando',
                             'como', 'das', 'vem', 'ser', 'foi', 'pela'
                             ]
    textWithoutStopwords: str = removeStopwords(texto, stopwords)

    wordList: List[str, bool] = [
        textWithoutStopwords,
        wordCount,
        True,
        True
    ]

    algoritimo = client.algo('WebPredict/WordFrequencies/0.1.0')
    response: List[dict] = algoritimo.pipe(wordList).result

    responseWithoutStopwords = []
    for wordInfo in response:
        if wordInfo['word'] not in stopwordsWithoutSpace:
            responseWithoutStopwords.append(wordInfo)

    count: int = 1
    for word in responseWithoutStopwords:
        print(f"{count}ª Palavra mais comum: {word['word']}")
        print(f"Frequência: {word['frequency']}\n")
        count += 1
예제 #13
0
def feelingAnalisys(client: 'Client', text: str) -> NoReturn:
    import math
    from utils.translate import traduzir
    from interface import texts

    print(texts.optionsTitle('feeling'))

    translatedText: Dict[str, str] = {"sentence": traduzir('en', text)}

    algoritimo = client.algo('nlp/SocialSentimentAnalysis/0.1.4')
    response: List[dict] = algoritimo.pipe(translatedText).result

    positive: int = math.floor(response[0]['positive'] * 100)
    negative: int = math.floor(response[0]['negative'] * 100)
    neutral: int = math.floor(response[0]['neutral'] * 100)

    print("Positivi: {}%\nNegativo: {}%\nNeutro: {}%".format(
        positive, negative, neutral))
예제 #14
0
def frequencyOfWords(client: 'Client', text: str) -> NoReturn:
    from matplotlib import pyplot as plt
    import sys

    from interface import texts

    from utils.removeStopwords import removeStopwords

    wordCount: str = input('nº de palavras a ser analisadas\n> ')
    print(texts.optionsTitle('frequency'))

    stopwords = [' a ', ' com ', ' da ', ' de ', ' do ',
                 ' e ', ' ele ', ' em ', ' na ', ' no ',
                 ' o ', ' para ', ' por ', ' que ', ' se ', ' sua ',
                 ' um ', ' uma ', ' os ', ' ao ', ' mais ', ' quando ',
                 ' como ', ' das ', ' vem ', ' ser ', ' foi ',  ' pela ',
                 ' eu ', ' te '
                 ]
    stopwordsWithoutSpace = ['a', 'com', 'da', 'de', 'de',
                             'do', 'e', 'ele', 'em', 'na', 'no',
                             'o', 'para', 'por', 'que', 'se', 'sua',
                             'um', 'uma', 'os', 'ao' 'mais', 'quando',
                             'como', 'das', 'vem', 'ser', 'foi', 'pela',
                             'eu', 'te'
                             ]
    textWithoutStopwords: str = removeStopwords(text, stopwords)

    wordList: List[str, bool] = [
        textWithoutStopwords,
        wordCount,
        True,
        True
    ]

    algoritimo = client.algo('WebPredict/WordFrequencies/0.1.0')
    response: List[dict] = algoritimo.pipe(wordList).result

    responseWithoutStopwords = []
    for wordInfo in response:
        if wordInfo['word'] not in stopwordsWithoutSpace:
            responseWithoutStopwords.append(wordInfo)

    print('Deseja exibir um gráfico com a frequencia de cada palavra? [s/n]')
    graphicChoice = input('> ')

    if graphicChoice == 's':
        wordsData = []
        frequencyData = []

        for word in responseWithoutStopwords:
            wordsData.append(word['word'])
            frequencyData.append(word['frequency'])

        plt.bar(wordsData, frequencyData)
        plt.show()
    else:
        count: int = 1
        for word in responseWithoutStopwords:
            print(f"{count}ª Palavra mais comum: {word['word']}")
            print(f"Frequência: {word['frequency']}\n")
            count += 1