I am trying at my current application to integrate a pretty complex Python script in .NET platform using IronPython as a bridge.
In my python script I use NLTK and also some other string classifiers like sklearn.naive_bayes
, this are my import's:
import nltk
from nltk.classify.scikitlearn import SklearnClassifier
import pickle
from sklearn.naive_bayes import MultinomialNB, BernoulliNB
from sklearn.linear_model import LogisticRegression, SGDClassifier
Also I have in this script a function that receive as a parameter a string and return some output example:
def testFunction(text):
#do some things
return somethings
I want to call this function from my .NET application, I am using this code for calling the function:
ScriptEngine engine;
ScriptScope scope;
ScriptSource source;
CompiledCode compiled;
engine = Python.CreateEngine();
scope = engine.CreateScope();
ICollection<string> paths = engine.GetSearchPaths();
string dir = @"C:\Users\Desktop\WinPython-64bit-3.4.3.6\python-3.4.3.amd64\Lib";
paths.Add(dir);
string dir2 = @"C:\Users\Desktop\WinPython-64bit-3.4.3.6\python-3.4.3.amd64\Lib\site-packages";
paths.Add(dir2);
engine.SetSearchPaths(paths);
//loading and compiling code
source = engine.CreateScriptSourceFromFile(@"C:\Users\Desktop\script.py");
compiled = source.Compile();
//now executing this code (the code should contain a class)
compiled.Execute(scope);
When I try to execute the code I get the following eror:
SyntaxErrorException -> unexpected token 'from'.
I want to call the testFunction
with a string and then use the output if that function in .NET.