pyTradutor.cpp
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//*****************************************************************
/*
VLibras: Automatic contents translator from Portuguese to LIBRAS
Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo,
Bruno santos
VLibras-Core group at LAViD, Federal University of Paraiba
*/
//*****************************************************************
/**
* \file pyTradutor.cpp
* \authors Erickson Silva, Gustavo Sobral
* \date Janeiro 2015
*/
#include "pyTradutor.h"
PyTradutor::PyTradutor()
{
// Initialize the Python interpreter
Py_Initialize();
// Type conversion between C++ string to Py string
pName = PyString_FromString("PortGlosa");
assert(pName!=NULL);
// Loads the script name saved in 'pName'
pModule = PyImport_Import(pName);
//PyErr_Print();
assert(pModule!=NULL);
// Returns the dictionary object that implements the namespace pModule
pDict = PyModule_GetDict(pModule);
//PyErr_Print();
assert(pDict!=NULL);
// Return the object from dictionary pDict which has a key 'iniciar'
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);
}