py_tradutor.cpp 1.66 KB
//*****************************************************************
/*
	VLibras: Automatic contents translator from Portuguese to LIBRAS

	Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo
	VLibras-Core group at LAViD, Federal University of Paraiba
*/
//*****************************************************************

/**
 * \file py_tradutor.cpp
 * \authors Erickson Silva, Gustavo Sobral, Leonardo Araújo
 * \date Janeiro 2015
 */

#include "py_tradutor.h"

PyTradutor::PyTradutor()
{
	Py_Initialize();
	// Imports the Aelius and Tradutor inside the Unity python interpreter 
    PyRun_SimpleString("import sys, os\n"
		"sys.path.append(os.path.expanduser('~') + '/vlibras-libs/tradutor')\n"
		"sys.path.append(os.path.expanduser('~') + '/vlibras-libs')\n");
  	pName = PyString_FromString("PortGlosa");
  	assert(pName!=NULL);
  	pModule = PyImport_Import(pName);
    PyErr_Print();
  	assert(pModule!=NULL);
  	pDict = PyModule_GetDict(pModule);
  	PyErr_Print();
  	assert(pDict!=NULL);
  	pFunc = PyDict_GetItemString(pDict, "traduzir");
  	PyErr_Print();
  	assert(pFunc!=NULL);


}

PyTradutor::~PyTradutor()
{
	// Free the allocated memory and finalize the Python interpreter
	Py_Finalize();
}

char * PyTradutor::convertStringToGlosa(const char * input)
{
	// Generates a new Tuple object with size '1' and value 'input' (converted)
	pArgs = PyTuple_Pack(1, PyString_FromString(input));
	PyErr_Print();
	assert(pArgs!=NULL);
	// Call the callable object 'pFunc' with arguments given by the tuple 'pArgs'
	pResult = PyObject_CallObject(pFunc, pArgs);
	PyErr_Print();
	assert(pResult!=NULL);
	// Converts the string Python type to C++
	return PyString_AsString(pResult);
}