9

我目前正在研究 python,因为我真的很喜欢文本解析功能和 nltk 库,但传统上我是一个 .Net/C# 程序员。我不认为 IronPython 对我来说是一个集成点,因为我使用的是 NLTK,并且可能需要将该库的端口移植到 CLR。我看了一点Python for .NET,想知道这是否是一个不错的起点。有没有办法将 python 类编组到 C# 中?另外,这个解决方案还在使用吗?更好的是,有人做过吗?我正在考虑的一件事是使用持久性介质作为中间人(在 Python 中解析,在 MongoDB 中存储,在 .NET 中运行站点)。

4

3 回答 3

9

NLTK 是纯 python,因此可以轻松地在 IronPython 上运行。搜索出现了这张票- 只需安装几个默认不随 IronPython 提供的额外 Python 库。

这可能是您集成的最简单方法。否则,您将不得不将 Python 作为子进程运行,这听起来很复杂,或者将 Python 作为响应您的请求的服务器运行。这可能是最可扩展但最复杂的方法。如果您采用这种方式,请考虑使用 Twisted 来简化服务器代码。

但请先尝试 IronPython ......

于 2009-11-24T06:18:44.543 回答
6

I don't know why you have a problem with IronPython. you can still use any and all nltk calls there.

To answer your question about porting a Python class into C#: try compiling your python code into an EXE. This creates a DLL with all your python classes in it. This is something that has been around for a while and it has worked like a charm for me in the past

于 2009-11-24T04:34:09.700 回答
2

Just an Idea

How about running Python behind as a server, and connect it from .NET with socket?

Since NLTK loading take time and better load it in advance anyway.

于 2009-11-24T04:32:18.360 回答