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.")
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)
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)
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))
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)
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)
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}')
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))
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}')
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))
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')
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
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))
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