Commit b7623085e091855139e33437d568b971076dffca
1 parent
a35c2caf
Exists in
master
Versão integrada com unit
Showing
28 changed files
with
470 additions
and
253 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +# -- coding: utf-8 -- | |
| 2 | +import ctypes | |
| 3 | + | |
| 4 | +def clip(): | |
| 5 | + | |
| 6 | + dll = ctypes.windll | |
| 7 | + | |
| 8 | + try: | |
| 9 | + dll.user32.OpenClipboard(None) #Para Python 3 | |
| 10 | + except ctypes.ArgumentError: | |
| 11 | + dll.user32.OpenClipboard(0) #Para python 2 | |
| 12 | + | |
| 13 | + handle = dll.user32.GetClipboardData(13) #Texto em unicode | |
| 14 | + text = ctypes.c_wchar_p(handle).value | |
| 15 | + dll.user32.CloseClipboard() | |
| 16 | + | |
| 17 | + if isinstance(text, unicode): | |
| 18 | + return text.encode("utf-8") | |
| 19 | + else: | |
| 20 | + return "Selecione um texto" | |
| 0 | 21 | \ No newline at end of file | ... | ... |
No preview for this file type
Makefile
| ... | ... | @@ -15,27 +15,57 @@ LFLAGS = -link C:\Python27\libs\python27.lib |
| 15 | 15 | CC = cl |
| 16 | 16 | |
| 17 | 17 | # Nome do arquivo de saída |
| 18 | -OUT = tradutor | |
| 18 | +OUT = testLibras | |
| 19 | 19 | |
| 20 | 20 | # Arquivos de implementação |
| 21 | -FILES = src\pyTradutor.cpp src\Main.cpp | |
| 21 | +FILES = src\pyTradutor.cpp src\pyClip.cpp | |
| 22 | 22 | |
| 23 | 23 | #Headers |
| 24 | -INCLUDES = include\pyTradutor.h | |
| 24 | +INCLUDES = include\pyTradutor.h include\pyClip.h | |
| 25 | 25 | |
| 26 | -all: $(FILES) $(INCLUDES) | |
| 27 | - $(CC) -Fe$(OUT) -clr $(FILES) $(CFLAGS) $(LFLAGS) | |
| 26 | +#Gera executável testLibras | |
| 27 | +all: $(FILES) $(INCLUDES) src\testLibras.cpp | |
| 28 | + $(CC) -Fe$(OUT) -EHsc src\testLibras.cpp $(FILES) $(CFLAGS) $(LFLAGS) | |
| 28 | 29 | |
| 29 | -Main: Main.cpp | |
| 30 | - $(CC) -c -FoMain -clr Main.cpp $(CFLAGS) $(LFLAGS) | |
| 30 | +#Gera dll na arquitetura x86 | |
| 31 | +plugin-x86: $(FILES) $(INCLUDES) | |
| 32 | + $(CC) -Feplugin\Plugin-x86\CorePlugin -EHsc -LD plugin\corePlugin.cpp $(FILES) -I plugin\corePlugin.h $(CFLAGS) $(LFLAGS) | |
| 31 | 33 | |
| 32 | -pyTradutor: src\pyTradutor.cpp | |
| 33 | - $(CC) -c -FopyTradutor -clr src\pyTradutor.cpp $(CFLAGS) $(LFLAGS) | |
| 34 | +#Gera dll na arquitetura x64 | |
| 35 | +plugin-x64: $(FILES) $(INCLUDES) | |
| 36 | + $(CC) -Feplugin\Plugin-x64\CorePlugin -EHsc -LD plugin\corePlugin.cpp $(FILES) -I plugin\corePlugin.h $(CFLAGS) $(LFLAGS) | |
| 34 | 37 | |
| 35 | -obj: $(FILES) $(INCLUDES) | |
| 36 | - $(CC) -c -Fo$(OUT) -clr $(FILES) $(CFLAGS) $(LFLAGS) | |
| 38 | +#Gera .obj da classe de teste | |
| 39 | +testLibras: $(FILES) $(INCLUDES) src\testLibras.cpp | |
| 40 | + $(CC) -c -FotestLibras -EHsc Main.cpp $(FILES) $(CFLAGS) $(LFLAGS) | |
| 37 | 41 | |
| 42 | +#Gera.obj do pyTradutor | |
| 43 | +pyTradutor: src\pyTradutor.cpp src\pyTradutor.h | |
| 44 | + $(CC) -c -FopyTradutor -EHsc src\pyTradutor.cpp $(CFLAGS) $(LFLAGS) | |
| 45 | + | |
| 46 | +#Gera .obj do pyClip | |
| 47 | +pyClip: src\pyClip.cpp src\pyClip.h | |
| 48 | + $(CC) -c -FopyClip -EHsc src\pyClip.cpp $(CFLAGS) $(LFLAGS) | |
| 49 | + | |
| 50 | +#Limpa arquivos objetos e executáveis criados | |
| 38 | 51 | clean: |
| 39 | - del -q *.exe *.obj *.manifest | |
| 52 | + del -q *.exe *.obj | |
| 53 | + | |
| 54 | +#Limpa dll criada em arquitetura x-86 | |
| 55 | +clean-plugin-x86: | |
| 56 | + del -q plugin\Plugin-x86\* | |
| 57 | + | |
| 58 | +#Limpa dll criada em arquiterutra x64 | |
| 59 | +clean-plugin-x64: | |
| 60 | + del -q plugin\Plugin-x64\* | |
| 61 | + | |
| 62 | +#Gera executável para testar a dll | |
| 63 | +test-plugin: | |
| 64 | + $(CC) plugin\testPlugin.cpp -EHsc | |
| 65 | + | |
| 66 | +# Baixa e instala dependências | |
| 67 | +install: | |
| 68 | + instalador\install | |
| 40 | 69 | |
| 70 | +#Gera documentação | |
| 41 | 71 | doc: | ... | ... |
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +#ifndef _PYCLIP_H | |
| 2 | +#define _PYCLIP_H | |
| 3 | + | |
| 4 | +#include "Python.h" | |
| 5 | + | |
| 6 | +namespace Clipboard | |
| 7 | +{ | |
| 8 | + class PyClip | |
| 9 | + { | |
| 10 | + private: | |
| 11 | + PyObject * pName; | |
| 12 | + PyObject * pModule; | |
| 13 | + PyObject * pDict; | |
| 14 | + PyObject * pFunc; | |
| 15 | + PyObject * pArgs; | |
| 16 | + PyObject * pResult; | |
| 17 | + public: | |
| 18 | + PyClip(); | |
| 19 | + ~PyClip(); | |
| 20 | + char* clip(); | |
| 21 | + | |
| 22 | + }; | |
| 23 | +} | |
| 24 | + | |
| 25 | +#endif | |
| 26 | + | ... | ... |
include/pyTradutor.h
| 1 | -/** | |
| 2 | - * @author Erickson Silva | |
| 3 | - * @date 14/10/2013 | |
| 4 | - * | |
| 5 | - */ | |
| 1 | +//***************************************************************** | |
| 2 | +/* | |
| 3 | + VLibras: Automatic contents translator from Portuguese to LIBRAS | |
| 6 | 4 | |
| 7 | -#include "Python.h" | |
| 5 | + Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo | |
| 6 | + VLibras-Core group at LAViD, Federal University of Paraiba | |
| 7 | +*/ | |
| 8 | +//***************************************************************** | |
| 8 | 9 | |
| 10 | +/** | |
| 11 | + * \file pyTradutor.hpp | |
| 12 | + * \authors Erickson Silva, Gustavo Sobral | |
| 13 | + * \date Janeiro 2015 | |
| 14 | + */ | |
| 9 | 15 | #ifndef _PYTRADUTOR_H |
| 10 | 16 | #define _PYTRADUTOR_H |
| 11 | 17 | |
| 12 | -namespace Tradutor { | |
| 13 | - class PyTradutor{ | |
| 14 | - public: | |
| 15 | - PyTradutor(); | |
| 16 | - ~PyTradutor(); | |
| 17 | - char * convertStringToGlosa(const char * input); | |
| 18 | - PyObject * pName; | |
| 19 | - PyObject * pModule; | |
| 20 | - PyObject * pDict; | |
| 21 | - PyObject * pFunc; | |
| 22 | - PyObject * pArgs; | |
| 23 | - PyObject * pResult; | |
| 24 | - bool isRunning; | |
| 25 | - }; | |
| 26 | -} | |
| 18 | +#include "Python.h" | |
| 19 | + | |
| 20 | +/** \brief Classe para execução do Tradutor | |
| 21 | + * | |
| 22 | + * Essa classe permite a execução e comunição do Tradutor | |
| 23 | + * (Português -> Glosa) do sistema escrito em Python | |
| 24 | + * permitindo sua utilização numa aplicação C++. | |
| 25 | + */ | |
| 26 | + namespace Tradutor | |
| 27 | + { | |
| 28 | + class PyTradutor | |
| 29 | + { | |
| 30 | + private: | |
| 31 | + PyObject * pName; | |
| 32 | + PyObject * pModule; | |
| 33 | + PyObject * pDict; | |
| 34 | + PyObject * pFunc; | |
| 35 | + PyObject * pArgs; | |
| 36 | + PyObject * pResult; | |
| 37 | + public: | |
| 38 | + /** \brief O construtor da classe | |
| 39 | + * | |
| 40 | + * O construtor inicia o ambiente Python para execução da tradução do tradutor. | |
| 41 | + */ | |
| 42 | + PyTradutor(); | |
| 27 | 43 | |
| 28 | -#endif | |
| 44 | + /** \brief O destrutor da classe | |
| 45 | + * | |
| 46 | + * O Destrutor finaliza o ambiente Python montado para execução da tradução. | |
| 47 | + */ | |
| 48 | + ~PyTradutor(); | |
| 29 | 49 | |
| 50 | + /** \brief Converte Português para Glosa | |
| 51 | + * | |
| 52 | + * Converte a string de entrada em Português para Glosa | |
| 53 | + * através da execução do Tradutor e retorna esse resultado | |
| 54 | + * | |
| 55 | + * \param input Ponteiro para char com o texto de entrada em Portugês | |
| 56 | + * \return Ponteiro para char com a tradução da entrada em Glosa | |
| 57 | + */ | |
| 58 | + char * convertStringToGlosa(const char * input); | |
| 59 | + }; | |
| 60 | +} | |
| 30 | 61 | |
| 62 | +#endif | |
| 31 | 63 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,91 @@ |
| 1 | +::############################## Instalador VLibras ############################ | |
| 2 | +::# # | |
| 3 | +::# Bruno Santos # | |
| 4 | +::# brunosantos@lavid.ufpb.br # | |
| 5 | +::# # | |
| 6 | +::############################################################################## | |
| 7 | + | |
| 8 | +::Define Título da janela do prompt | |
| 9 | +TITLE Instalador VLibras-Core Windows | |
| 10 | + | |
| 11 | +::Limpa a tela | |
| 12 | +CLS | |
| 13 | + | |
| 14 | +::Desabilita mensagens | |
| 15 | +@ECHO off | |
| 16 | + | |
| 17 | +ECHO ############### Instalando VLibras ############### | |
| 18 | + | |
| 19 | +::################# Variáveis de Ambiente ################# | |
| 20 | +:VAR | |
| 21 | +ECHO Deseja Exportar as variaveis de ambiente: (S - N) | |
| 22 | + | |
| 23 | +::Solicita valor do usuário | |
| 24 | +SET /p valor=--^> | |
| 25 | + | |
| 26 | +IF /I %valor% == n GOTO NO_VAR | |
| 27 | +IF /I %valor% == s (ECHO OK!) ELSE (GOTO VAR) | |
| 28 | + | |
| 29 | +ECHO. | |
| 30 | +ECHO Exportando Variaveis de Ambiente: | |
| 31 | +ECHO. | |
| 32 | + | |
| 33 | +::Váriaveis Permanentes (Sistema) | |
| 34 | +ECHO AELIUS_DATA | |
| 35 | +SETX AELIUS_DATA %HOMEPATH%\vlibras-libs\aelius_data /M | |
| 36 | + | |
| 37 | +ECHO NLTK_DATA | |
| 38 | +SETX NLTK_DATA %HOMEPATH%\vlibras-libs\nltk_data /M | |
| 39 | + | |
| 40 | +ECHO HUNPOS_TAGGER | |
| 41 | +SETX HUNPOS_TAGGER %HOMEPATH%\vlibras-libs\bin\hunpos-tag.exe /M | |
| 42 | + | |
| 43 | +ECHO PYTHONPATH | |
| 44 | +SETX PYTHONPATH %HOMEDRIVE%\Python27;%HOMEDRIVE%\Python27\Scripts;%HOMEDRIVE%\Python27\Lib\site-packages;%HOMEPATH%\vlibras-libs;%HOMEPATH%\vlibras-libs\tradutor;%HOMEPATH%\vlibras-core-win\Clipboard /M | |
| 45 | + | |
| 46 | +SETX "PATH" "%PATH%";%HOMEPATH%\vlibras-libs\bin;%HOMEDRIVE%\Python27;%HOMEDRIVE%\Python27\Scripts;%HOMEDRIVE%\Python27\Lib\site-packages;%HOMEDRIVE%"\Program Files (x86)\7-Zip" /M | |
| 47 | + | |
| 48 | +::Código executa a partir desse ponto caso o usuário não precise configurar as variáveis de ambiente | |
| 49 | +:NO_VAR | |
| 50 | + | |
| 51 | +::################# Instalação do Python ################# | |
| 52 | +:PYTHON | |
| 53 | +ECHO Deseja Instalar o Python-2.7.9: (S - N) | |
| 54 | + | |
| 55 | +SET /p valor=--^> | |
| 56 | +IF /I %valor% == n GOTO NO_PYTHON | |
| 57 | +IF /I %valor% == s (ECHO OK!) ELSE (GOTO PYTHON) | |
| 58 | + | |
| 59 | +msiexec /i python-2.7.9.msi /passive | |
| 60 | + | |
| 61 | +::Código executa a partir desse ponto caso o usuário não precise Instalar o Python | |
| 62 | +:NO_PYTHON | |
| 63 | + | |
| 64 | +::################# Instalação do Aelius ################# | |
| 65 | +:TRADUTOR | |
| 66 | +ECHO Deseja Instalar o VLibras Tradutor (S - N) | |
| 67 | + | |
| 68 | +SET /p valor=--^> | |
| 69 | +IF /I %valor% == n GOTO END | |
| 70 | +IF /I %valor% == s (ECHO OK!) ELSE (GOTO TRADUTOR) | |
| 71 | + | |
| 72 | +pyyaml.exe | |
| 73 | +numpy.exe | |
| 74 | +matplotlib.exe | |
| 75 | +nltk.exe | |
| 76 | + | |
| 77 | +IF NOT EXIST C:"\Program Files (x86)\7-Zip" (msiexec /i 7zip.msi /passive) | |
| 78 | + | |
| 79 | +ECHO 7-Zip instalado com sucesso! | |
| 80 | + | |
| 81 | +COPY C:"\Program Files (x86)\7-Zip\7z.exe" %SYSTEMROOT%\System32 | |
| 82 | + | |
| 83 | +::################# Instalação do VLibras ################# | |
| 84 | + | |
| 85 | +ECHO Extraindo Arquivos... | |
| 86 | +7z x -o%HOMEPATH% vlibras-libs.zip vlibras-libs | |
| 87 | + | |
| 88 | +:END | |
| 89 | +ECHO VLibras Tradutor instalado com sucesso! | |
| 90 | + | |
| 91 | +cd %HOMEPATH%\vlibras-libs | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
| ... | ... | @@ -0,0 +1,40 @@ |
| 1 | + | |
| 2 | +#if _MSC_VER | |
| 3 | +#define EXPORT_API __declspec(dllexport) | |
| 4 | +#else | |
| 5 | +#define EXPORT_API __declspec(dllimport) | |
| 6 | +#endif | |
| 7 | + | |
| 8 | +#include "corePlugin.h" | |
| 9 | + | |
| 10 | + extern "C" | |
| 11 | +{ | |
| 12 | + EXPORT_API int coreInitialize() | |
| 13 | + { | |
| 14 | + //Objeto usado para traduzir | |
| 15 | + tradutor = new PyTradutor(); | |
| 16 | + | |
| 17 | + //Objeto usado para copiar texto da área de transferência | |
| 18 | + clipboard = new PyClip(); | |
| 19 | + return 1; | |
| 20 | + } | |
| 21 | + | |
| 22 | + EXPORT_API char* coreExecute() | |
| 23 | + { | |
| 24 | + //Copia área de transferência para input | |
| 25 | + char *input = clipboard->clip(); | |
| 26 | + | |
| 27 | + //Retorna a tradução do texto para glosa | |
| 28 | + return tradutor->convertStringToGlosa(input); | |
| 29 | + } | |
| 30 | + | |
| 31 | + EXPORT_API int coreFinalize() | |
| 32 | + { | |
| 33 | + delete tradutor; | |
| 34 | + return 1; | |
| 35 | + } | |
| 36 | + | |
| 37 | +} | |
| 38 | + | |
| 39 | + | |
| 40 | + | ... | ... |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +#ifndef _COREPLUGIN_H | |
| 2 | +#define _COREPLUGIN_H | |
| 3 | + | |
| 4 | +#include "pyTradutor.h" | |
| 5 | +#include "pyClip.h" | |
| 6 | + | |
| 7 | +using namespace Tradutor; | |
| 8 | +using namespace Clipboard; | |
| 9 | + | |
| 10 | +extern "C" | |
| 11 | +{ | |
| 12 | + //Usado para traduzir português para glosa | |
| 13 | + PyTradutor *tradutor; | |
| 14 | + | |
| 15 | + //Usado para copiar texto da área de transferência | |
| 16 | + PyClip *clipboard; | |
| 17 | + | |
| 18 | + //Inicializa Objetos | |
| 19 | + EXPORT_API int coreInitize(void); | |
| 20 | + | |
| 21 | + //Faz tradução de Português para glosa | |
| 22 | + EXPORT_API char* coreExecute(void); | |
| 23 | + | |
| 24 | + //Libera Objetos utilizados | |
| 25 | + EXPORT_API int coreFinalize(void); | |
| 26 | +} | |
| 27 | + | |
| 28 | +#endif | |
| 0 | 29 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +#include <IOSTREAM> | |
| 2 | +#include <windows.h> | |
| 3 | + | |
| 4 | +using namespace std; | |
| 5 | + | |
| 6 | +//Assinatura dos métodos utilizados na dll | |
| 7 | +typedef int (WINAPI*metodo1)(); | |
| 8 | +metodo1 initialize; | |
| 9 | + | |
| 10 | +typedef char* (WINAPI*metodo2)(); | |
| 11 | +metodo2 execute; | |
| 12 | + | |
| 13 | +typedef int (WINAPI*metodo3)(); | |
| 14 | +metodo3 finalize; | |
| 15 | + | |
| 16 | +int main(int argc, char *argv[]) | |
| 17 | +{ | |
| 18 | + //Carrega a dll | |
| 19 | + HINSTANCE hDLL = LoadLibrary("plugin\\Plugin-x86\\CorePlugin.dll"); | |
| 20 | + | |
| 21 | + if (hDLL) | |
| 22 | + cout << "dll criada com sucesso" <<endl; | |
| 23 | + else | |
| 24 | + cout << "dll falhou" <<endl; | |
| 25 | + | |
| 26 | + //Relaciona método local com o método implementado na dll | |
| 27 | + initialize=(metodo1)GetProcAddress((HMODULE)hDLL, "coreInitialize"); | |
| 28 | + execute=(metodo2)GetProcAddress((HMODULE)hDLL, "coreExecute"); | |
| 29 | + finalize=(metodo3)GetProcAddress((HMODULE)hDLL, "coreFinalize"); | |
| 30 | + | |
| 31 | + //Executa coreInitialize | |
| 32 | + int init = initialize(); | |
| 33 | + cout <<"return initialize: " << init <<endl; | |
| 34 | + | |
| 35 | + //Executa coreExecute | |
| 36 | + char* exec = execute(); | |
| 37 | + cout << "return execute: " << exec <<endl; | |
| 38 | + | |
| 39 | + //Executa coreFinalize | |
| 40 | + int final = finalize(); | |
| 41 | + cout << "return finalize: " << final <<endl; | |
| 42 | + | |
| 43 | + //Libera dll | |
| 44 | + FreeLibrary((HMODULE)hDLL); | |
| 45 | + | |
| 46 | + return 0; | |
| 47 | +} | ... | ... |
src/Main.cpp
| ... | ... | @@ -1,75 +0,0 @@ |
| 1 | -#include <IOSTREAM> | |
| 2 | -#include <string> | |
| 3 | -#include <msclr/marshal.h> | |
| 4 | -#include <fstream> | |
| 5 | -#include <algorithm> | |
| 6 | -#include "pyTradutor.h" | |
| 7 | - | |
| 8 | -#using <system.dll> | |
| 9 | -#using <system.Drawing.dll> | |
| 10 | -#using <system.windows.forms.dll> | |
| 11 | - | |
| 12 | -using namespace System; | |
| 13 | -using namespace System::Windows::Forms; | |
| 14 | - | |
| 15 | -using namespace std; | |
| 16 | -using namespace Tradutor; | |
| 17 | - | |
| 18 | - | |
| 19 | -[STAThread]int main(int argc, char *argv[]) | |
| 20 | -{ | |
| 21 | - //Objeto para acessar a área de transferência do windows | |
| 22 | - System::Windows::Forms::IDataObject^ data = Clipboard::GetDataObject( ); | |
| 23 | - //Objeto para traduzir para glosa | |
| 24 | - PyTradutor *tradutor = new PyTradutor(); | |
| 25 | - //Objeto para converter system::String para consta char* | |
| 26 | - msclr::interop::marshal_context convert; | |
| 27 | - //Variável para armazenar a glosa | |
| 28 | - std::string glosa; | |
| 29 | - //Entrada a ser traduzida | |
| 30 | - const char* input; | |
| 31 | - //Arquivo de texto de saída | |
| 32 | - ofstream myfile; | |
| 33 | - //Home do usuário corrente | |
| 34 | - char *home = getenv("HOMEPATH"); | |
| 35 | - | |
| 36 | - //Verifica se existe informação na área de transferência | |
| 37 | - if (data) | |
| 38 | - { | |
| 39 | - //Verifica se o arquivo é do tipo texto | |
| 40 | - if (data->GetDataPresent(DataFormats::Text)) | |
| 41 | - { | |
| 42 | - //Copia área de transferência para variável do sistema | |
| 43 | - String^ clip = static_cast<String^> (data->GetData(DataFormats::Text)); | |
| 44 | - | |
| 45 | - //Converte system::String para const char* | |
| 46 | - input = convert.marshal_as<const char*>(clip); | |
| 47 | - //Console::WriteLine(text); | |
| 48 | - } | |
| 49 | - else | |
| 50 | - //Área de transfência sem texto | |
| 51 | - Console::WriteLine("O conteúdo selecionado não é um texto."); | |
| 52 | - } | |
| 53 | - else | |
| 54 | - //Área de transferência vazia | |
| 55 | - Console::WriteLine("Nada foi selecionado."); | |
| 56 | - | |
| 57 | - //Converte o texto selecionado para glosa | |
| 58 | - glosa = tradutor->convertStringToGlosa(input); | |
| 59 | - | |
| 60 | - //imprime a glosa | |
| 61 | - cout << glosa <<endl; | |
| 62 | - | |
| 63 | - //Seta o texto pra lowercase | |
| 64 | - std::transform(glosa.begin(), glosa.end(), glosa.begin(), ::tolower); | |
| 65 | - | |
| 66 | - //Salva texto no arquivo que será lido pelo Unit | |
| 67 | - | |
| 68 | - strcat (home,"\\player\\vlibrasPlayer_Data\\glosaFile.txt"); | |
| 69 | - myfile.open (home , ios::out); | |
| 70 | - myfile << glosa << endl; | |
| 71 | - myfile.close(); | |
| 72 | - | |
| 73 | - delete tradutor; | |
| 74 | - return 0; | |
| 75 | -} | |
| 76 | 0 | \ No newline at end of file |
| ... | ... | @@ -0,0 +1,40 @@ |
| 1 | +#include "pyClip.h" | |
| 2 | + | |
| 3 | +namespace Clipboard | |
| 4 | +{ | |
| 5 | + PyClip::PyClip() | |
| 6 | + { | |
| 7 | + // Initialize the Python interpreter | |
| 8 | + Py_Initialize(); | |
| 9 | + | |
| 10 | + // Type conversion between C++ string to Py string | |
| 11 | + pName = PyString_FromString("Clipboard"); | |
| 12 | + assert(pName!=NULL); | |
| 13 | + // Loads the script name saved in 'pName' | |
| 14 | + pModule = PyImport_Import(pName); | |
| 15 | + //PyErr_Print(); | |
| 16 | + assert(pModule!=NULL); | |
| 17 | + // Returns the dictionary object that implements the namespace pModule | |
| 18 | + pDict = PyModule_GetDict(pModule); | |
| 19 | + //PyErr_Print(); | |
| 20 | + assert(pDict!=NULL); | |
| 21 | + // Return the object from dictionary pDict which has a key 'iniciar' | |
| 22 | + pFunc = PyDict_GetItemString(pDict, "clip"); | |
| 23 | + //PyErr_Print(); | |
| 24 | + assert(pFunc!=NULL); | |
| 25 | + } | |
| 26 | + | |
| 27 | + PyClip::~PyClip() | |
| 28 | + { | |
| 29 | + Py_Finalize(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + char * PyClip::clip() | |
| 33 | + { | |
| 34 | + // Call the callable object 'pFunc' with arguments given by the tuple 'pArgs' | |
| 35 | + pResult = PyObject_CallObject(pFunc,pArgs); | |
| 36 | + assert(pResult!=NULL); | |
| 37 | + | |
| 38 | + return PyString_AsString(pResult); | |
| 39 | + } | |
| 40 | +} | |
| 0 | 41 | \ No newline at end of file | ... | ... |
src/pyTradutor.cpp
| 1 | +//***************************************************************** | |
| 2 | +/* | |
| 3 | + VLibras: Automatic contents translator from Portuguese to LIBRAS | |
| 4 | + | |
| 5 | + Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo | |
| 6 | + VLibras-Core group at LAViD, Federal University of Paraiba | |
| 7 | +*/ | |
| 8 | +//***************************************************************** | |
| 9 | + | |
| 1 | 10 | /** |
| 2 | - * Essa classe invoca os metodos do tradutor em Python | |
| 3 | - * Onde efetua a tradução do texto passado por parametro | |
| 4 | - * | |
| 5 | - * @author Erickson Silva | |
| 6 | - * @date 14/10/2013 | |
| 7 | - * | |
| 11 | + * \file pyTradutor.cpp | |
| 12 | + * \authors Erickson Silva, Gustavo Sobral | |
| 13 | + * \date Janeiro 2015 | |
| 8 | 14 | */ |
| 9 | 15 | |
| 10 | -#include <IOSTREAM> | |
| 11 | 16 | #include "pyTradutor.h" |
| 12 | 17 | |
| 13 | -namespace Tradutor { | |
| 14 | - PyTradutor::PyTradutor() { | |
| 15 | - //DPRINTF("Done!\n"); | |
| 16 | - } | |
| 17 | - PyTradutor::~PyTradutor() { | |
| 18 | - Py_DECREF(pName); | |
| 19 | - Py_DECREF(pModule); | |
| 20 | - Py_DECREF(pDict); | |
| 21 | - Py_DECREF(pFunc); | |
| 22 | - Py_DECREF(pArgs); | |
| 23 | - Py_DECREF(pResult); | |
| 24 | - //DDDPRINTF("PyTranslator finalized!\n"); | |
| 25 | - } | |
| 26 | - | |
| 27 | -/** | |
| 28 | -* Traduz um texto (char * input) para uma string contendo a | |
| 29 | -* traducao para glosa | |
| 30 | -* | |
| 31 | -* @param input texto de entrada | |
| 32 | -* @return string contendo os tokens em glosa traduzidos. | |
| 33 | -**/ | |
| 34 | - char * PyTradutor::convertStringToGlosa(const char * input) { | |
| 18 | +namespace Tradutor | |
| 19 | +{ | |
| 20 | + PyTradutor::PyTradutor() | |
| 21 | + { | |
| 22 | + // Initialize the Python interpreter | |
| 23 | + Py_Initialize(); | |
| 35 | 24 | |
| 36 | - if(!isRunning){ | |
| 37 | - Py_Initialize(); | |
| 38 | - pName = PyString_FromString("ModuleTranslate"); | |
| 39 | - assert(pName!=NULL); | |
| 40 | - pModule = PyImport_Import(pName); | |
| 41 | - PyErr_Print(); | |
| 42 | - assert(pModule!=NULL); | |
| 43 | - pDict = PyModule_GetDict(pModule); | |
| 44 | - PyErr_Print(); | |
| 45 | - assert(pDict!=NULL); | |
| 46 | - pFunc = PyDict_GetItemString(pDict, "iniciar"); | |
| 47 | - PyErr_Print(); | |
| 48 | - assert(pFunc!=NULL); | |
| 49 | - isRunning = 1; | |
| 50 | - } | |
| 25 | + // Type conversion between C++ string to Py string | |
| 26 | + pName = PyString_FromString("ModuleTranslate"); | |
| 27 | + assert(pName!=NULL); | |
| 28 | + // Loads the script name saved in 'pName' | |
| 29 | + pModule = PyImport_Import(pName); | |
| 30 | + //PyErr_Print(); | |
| 31 | + assert(pModule!=NULL); | |
| 32 | + // Returns the dictionary object that implements the namespace pModule | |
| 33 | + pDict = PyModule_GetDict(pModule); | |
| 34 | + //PyErr_Print(); | |
| 35 | + assert(pDict!=NULL); | |
| 36 | + // Return the object from dictionary pDict which has a key 'iniciar' | |
| 37 | + pFunc = PyDict_GetItemString(pDict, "iniciar"); | |
| 38 | + //PyErr_Print(); | |
| 39 | + assert(pFunc!=NULL); | |
| 40 | + } | |
| 51 | 41 | |
| 52 | - pArgs = PyTuple_Pack(1,PyString_FromString(input)); | |
| 42 | + PyTradutor::~PyTradutor() | |
| 43 | + { | |
| 44 | + // Free the allocated memory and finalize the Python interpreter | |
| 45 | + Py_Finalize(); | |
| 46 | + } | |
| 53 | 47 | |
| 54 | - PyErr_Print(); | |
| 55 | - assert(pArgs!=NULL); | |
| 56 | - pResult = PyObject_CallObject(pFunc, pArgs); | |
| 57 | - PyErr_Print(); | |
| 58 | - assert(pResult!=NULL); | |
| 59 | - return PyString_AsString(pResult); | |
| 48 | + char * PyTradutor::convertStringToGlosa(const char * input) | |
| 49 | + { | |
| 50 | + // Generates a new Tuple object with size '1' and value 'input' (converted) | |
| 51 | + pArgs = PyTuple_Pack(1, PyString_FromString(input)); | |
| 52 | + PyErr_Print(); | |
| 53 | + assert(pArgs!=NULL); | |
| 54 | + // Call the callable object 'pFunc' with arguments given by the tuple 'pArgs' | |
| 55 | + pResult = PyObject_CallObject(pFunc, pArgs); | |
| 56 | + PyErr_Print(); | |
| 57 | + assert(pResult!=NULL); | |
| 58 | + // Converts the string Python type to C++ | |
| 59 | + return PyString_AsString(pResult); | |
| 60 | + //return "Ambulancia"; | |
| 60 | 61 | } |
| 61 | -} | |
| 62 | 62 | \ No newline at end of file |
| 63 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +#include <iostream> | |
| 2 | +#include "pyClip.h" | |
| 3 | +#include "pyTradutor.h" | |
| 4 | + | |
| 5 | +using namespace std; | |
| 6 | +using namespace Tradutor; | |
| 7 | +using namespace Clipboard; | |
| 8 | + | |
| 9 | +int main(int argc, char *argv[]) | |
| 10 | +{ | |
| 11 | + //Usado para traduzir português para glosa | |
| 12 | + PyTradutor *tradutor = new PyTradutor(); | |
| 13 | + | |
| 14 | + //Usado para copiar texto da área de transferência | |
| 15 | + PyClip *clipboard = new PyClip(); | |
| 16 | + | |
| 17 | + //Copia área de transferência para input | |
| 18 | + char *input = clipboard->clip(); | |
| 19 | + | |
| 20 | + //Traduz de português para glosa | |
| 21 | + char* glosa = tradutor->convertStringToGlosa(input); | |
| 22 | + | |
| 23 | + cout << glosa <<endl; | |
| 24 | + | |
| 25 | + delete clipboard; | |
| 26 | + delete tradutor; | |
| 27 | + | |
| 28 | + return 0; | |
| 29 | +} | |
| 0 | 30 | \ No newline at end of file | ... | ... |
vlibras_install/Bat_To_Exe_Converter.exe
No preview for this file type
vlibras_install/Bat_To_Exe_Converter_(x64).exe
No preview for this file type
vlibras_install/exe/7zip.msi
No preview for this file type
vlibras_install/exe/icon.ico
No preview for this file type
vlibras_install/exe/install.bat
| ... | ... | @@ -1,92 +0,0 @@ |
| 1 | -::############################## Instalador VLibras ############################ | |
| 2 | -::# # | |
| 3 | -::# Bruno Santos # | |
| 4 | -::# brunosantos@lavid.ufpb.br # | |
| 5 | -::# # | |
| 6 | -::############################################################################## | |
| 7 | - | |
| 8 | -::Define Título da janela do prompt | |
| 9 | -TITLE Instalador VLibras-Core Windows | |
| 10 | - | |
| 11 | -::Limpa a tela | |
| 12 | -CLS | |
| 13 | - | |
| 14 | -::Desabilita mensagens | |
| 15 | -@ECHO off | |
| 16 | - | |
| 17 | -ECHO ############### Instalando VLibras ############### | |
| 18 | - | |
| 19 | -::################# Variáveis de Ambiente ################# | |
| 20 | -:VAR | |
| 21 | -ECHO Deseja Exportar as variaveis de ambiente: (S - N) | |
| 22 | - | |
| 23 | -::Solicita valor do usuário | |
| 24 | -SET /p valor=--^> | |
| 25 | - | |
| 26 | -IF /I %valor% == n GOTO NO_VAR | |
| 27 | -IF /I %valor% == s (ECHO OK!) ELSE (GOTO VAR) | |
| 28 | - | |
| 29 | -ECHO. | |
| 30 | -ECHO Exportando Variaveis de Ambiente: | |
| 31 | -ECHO. | |
| 32 | - | |
| 33 | -::Váriaveis Permanentes (Sistema) | |
| 34 | -ECHO AELIUS_DATA | |
| 35 | -SETX AELIUS_DATA %HOMEPATH%\vlibras-libs\aelius_data /M | |
| 36 | - | |
| 37 | -ECHO NLTK_DATA | |
| 38 | -SETX NLTK_DATA %HOMEPATH%\vlibras-libs\nltk_data /M | |
| 39 | - | |
| 40 | -ECHO HUNPOS_TAGGER | |
| 41 | -SETX HUNPOS_TAGGER %HOMEPATH%\vlibras-libs\bin /M | |
| 42 | - | |
| 43 | -ECHO PYTHONPATH | |
| 44 | -SETX PYTHONPATH %HOMEDRIVE%\Python27;%HOMEDRIVE%\Python27\Scripts;%HOMEDRIVE%\Python27\Lib\site-packages;%HOMEPATH%\vlibras-libs;%HOMEPATH%\vlibras-libs\tradutor /M | |
| 45 | - | |
| 46 | -SETX "PATH" "%PATH%";%HOMEPATH%\vlibras-libs\bin;%HOMEDRIVE%\Python27;%HOMEDRIVE%\Python27\Scripts;%HOMEDRIVE%\Python27\Lib\site-packages;%HOMEDRIVE%"\Program Files (x86)\7-Zip" /M | |
| 47 | - | |
| 48 | -::Código executa a partir desse ponto caso o usuário não precise configurar as variáveis de ambiente | |
| 49 | -:NO_VAR | |
| 50 | - | |
| 51 | -::################# Instalação do Python ################# | |
| 52 | -:PYTHON | |
| 53 | -ECHO Deseja Instalar o Python-2.7.9: (S - N) | |
| 54 | - | |
| 55 | -SET /p valor=--^> | |
| 56 | -IF /I %valor% == n GOTO NO_PYTHON | |
| 57 | -IF /I %valor% == s (ECHO OK!) ELSE (GOTO PYTHON) | |
| 58 | - | |
| 59 | -msiexec /i python-2.7.9.msi /passive | |
| 60 | - | |
| 61 | -::Código executa a partir desse ponto caso o usuário não precise Instalar o Python | |
| 62 | -:NO_PYTHON | |
| 63 | - | |
| 64 | -::################# Instalação do Aelius ################# | |
| 65 | -:TRADUTOR | |
| 66 | -ECHO Deseja Instalar o VLibras Tradutor (S - N) | |
| 67 | - | |
| 68 | -SET /p valor=--^> | |
| 69 | -IF /I %valor% == n GOTO END | |
| 70 | -IF /I %valor% == s (ECHO OK!) ELSE (GOTO TRADUTOR) | |
| 71 | - | |
| 72 | -pyyaml.exe | |
| 73 | -numpy.exe | |
| 74 | -matplotlib.exe | |
| 75 | -nltk.exe | |
| 76 | - | |
| 77 | -IF NOT EXIST C:"\Program Files (x86)\7-Zip" (msiexec /i 7zip.msi /passive) | |
| 78 | - | |
| 79 | -ECHO 7-Zip instalado com sucesso! | |
| 80 | - | |
| 81 | -COPY C:"\Program Files (x86)\7-Zip\7z.exe" %SYSTEMROOT%\System32 | |
| 82 | - | |
| 83 | -::################# Instalação do VLibras ################# | |
| 84 | - | |
| 85 | -ECHO Extraindo Arquivos... | |
| 86 | -7z x -o%HOMEPATH% vlibras-libs.zip vlibras-libs | |
| 87 | - | |
| 88 | -:END | |
| 89 | -ECHO VLibras Tradutor instalado com sucesso! | |
| 90 | - | |
| 91 | -cd %HOMEPATH%\vlibras-libs | |
| 92 | -DragKing | |
| 93 | 0 | \ No newline at end of file |
vlibras_install/exe/matplotlib.exe
No preview for this file type
vlibras_install/exe/nltk.exe
No preview for this file type
vlibras_install/exe/numpy.exe
No preview for this file type
vlibras_install/exe/python-2.7.9.msi
No preview for this file type
vlibras_install/exe/pyyaml.exe
No preview for this file type
vlibras_install/exe/vlibras-libs.zip
No preview for this file type