编程方式生成的OWL文件组件与ROWLEX组件、方式、文件、ROWLEX

2023-09-03 15:17:14 作者:南风过境

我一直使用 ROWLEX 库来处理RDF-S。它附带一个designtime GUI工具称为OwlGrinder.exe,可以从我的OWL本体生成C#辅助类(.NET程序集是精确的)。我不知道是否有人知道,如果我能在运行时编程方式做同样的。

I have been using the ROWLEX library to handle RDF-s. It is shipped with a designtime GUI tool called OwlGrinder.exe that can generate C# helper classes (.NET assemblies to be exact) from my OWL ontologies. I wonder if anyone knows if I could do the same programatically in runtime.

推荐答案

ROWLEX刚刚成为开源的,所以现在你有机会真正往里OwlGrinder.exe的code和复制code那里。但是,这里有一个简单的例子:

ROWLEX just became open source, so now you have the chance to actually look inside the code of OwlGrinder.exe and copy the code from there. However, here is a short example:

	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不允许您卸载程序集。因此,你不能从你的previous摆脱运行的程序集。解决的办法是你在一个新的AppDomain可以卸载每次执行代code。 OwlGrinder.exe也正是这一点,你可能要到MainForm.cs内达到峰值

If you want to generate assemblies in runtime, I assume that you might want to repeat that over and over again as your user demands. You have to watch out here, because .NET does not allow you to unload an assembly. Therefore you cannot get rid of the assemblies from your previous runs. The solution is that you execute the generation code every time in a new AppDomain which can be unloaded. OwlGrinder.exe does exactly this, you might want to peak inside the MainForm.cs