我有一个给定的本体,我喜欢对其进行推理。我使用 .NET 的 ROWLEX API。
我怎样才能找到一个类的所有owlSubClasses?
ROWLEX 不是推理者。它实现了一些推理器的功能——这对于 C# 类的生成非常必要——但它的 API 并不是为此而设计的。但是,仍然有希望,只是不是最优雅的解决方案。
我假设您有一个本体,并且您使用 OwlGrinder.exe 从中生成了 .NET 类。因此,默认情况下,您会为本体中的每个对应的 OWL 类生成两个关联的 .NET 类:一个轻量级和一个完整类。我们将只使用灯光类。我们只需遍历所有 .NET 类并过滤掉是否是子类。这就对了。
string baseClassUri = "http://myontology/2012/10#mybaseclass";
Assembly asm = GetMyAssemblyGeneratedByOwlGrinder();
Type[] subClasses = (from type in asm.GetTypes()
where type.IsSubclassOf(typeof(NC3A.SI.Rowlex.OwlThing))
// selecting subclasses only
let attributes = type.GetCustomAttributes(typeof(NC3A.SI.Rowlex.SubClassOfAttribute), false)
from attr in attributes
let subClassAttr = attr as NC3A.SI.Rowlex.SubClassOfAttribute
where subClassAttr.TypeUri == baseClassUri
// selecting light classes only
let lightAttributes = type.GetCustomAttributes(typeof(NC3A.SI.Rowlex.LightVersionAttribute), false)
from lightAttr in lightAttributes
let lightAttr_ = lightAttr as NC3A.SI.Rowlex.LightVersionAttribute
where lightAttr_.LightVersion == true
select type).ToArray();
我没有尝试代码,它可能是错误的。但它确实表明了这个想法。每个生成的类都添加了一堆属性。这些包括它们在 SubClassOfAttribute 中的基类,以及它们是使用 LightVersionAttribute 的轻类还是完整类。您可以根据这些属性过滤掉您感兴趣的类。