我一直在使用 ROWLEX处理 RDF-s 的库。它附带了一个名为 OwlGrinder.exe 的设计时 GUI 工具,该工具可以从我的 OWL 本体生成 C# 帮助程序类(准确地说是 .NET 程序集)。我想知道是否有人知道我是否可以在运行时以编程方式执行相同的操作。
最佳答案
ROWLEX 刚刚开源,所以现在您有机会实际查看 OwlGrinder.exe 的代码并从那里复制代码。但是,这里有一个简短的示例:
private NC3A.SI.Rowlex.AssemblyGenerator generator;
private void RunAssemblyGeneration(XmlDocument ontologyFileInRdfXml)
{
this.generator = new NC3A.SI.Rowlex.AssemblyGenerator();
this.generator.GenerateAsync(ontologyFileInRdfXml, "myAssemblyName",
null, this.OnGenerationFinished);
}
private void OnGenerationFinished(string errorMessage)
{
if (errorMessage == null)
{
// Success
// Displaying warnings and saving result
string[] warnings = this.generator.Warnings;
this.generator.SaveResult(@"C:\myAssemblyName.dll");
// Important! One generator instance can be executed only once.
this.generator = null;
this.RejoiceOverSuccess();
}
else
{
// Failure
this.MournOverFailure();
}
}
如果您想在运行时生成程序集,我假设您可能希望根据用户的要求一遍又一遍地重复该操作。您必须注意这里,因为.NET 不允许您卸载程序集。因此,您无法删除之前运行中的程序集。解决方案是每次在可以卸载的新 AppDomain 中执行生成代码。 OwlGrinder.exe 正是这样做的,您可能希望在 MainForm.cs 中达到峰值
关于c# - 使用 ROLEX 以编程方式从 OWL 文件生成装配体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/865052/