1

如果我有这两个具有两个不同属性但名称相同的类:

[RdfSerializable]
public class Type1
{
    [RdfProperty(true), Name = "title"]
    public string Title { get; set; }
}

[RdfSerializable]
public class Type2
{
    [RdfProperty(true), Name = "title"]
    public string Title { get; set; }
}

并尝试将它们序列化为 RDF 并使用http://www.w3.org/RDF/Validator/服务对其进行验证。一切都很好,他们是正确的。但在我尝试使用 OntologyExtractor.exe 工具从这些类生成 OWL 文件后,我收到以下消息:“本体提取失败。http: //test.org/1.0#title被分配给多个类型。” 这是一个奇怪的消息,因为上层类是正确的,并且有一些 RDF 规范具有相同的情况,不同的类具有相同的命名属性。

4

1 回答 1

2

我希望这是 ROWLEX 中的一个错误。您的案例是有效的,但我假设我在编写 OntologyExtractor 时没有为此做好准备。我会尽快发布修复程序。

编辑:ROWLEX2.1 已发布,您可以从http://rowlex.nc3a.nato.int下载。2.1 版(除其他外)现在支持共享属性功能。问题中的确切代码仍然会导致相同的错误!为了克服这个问题,您应该按如下方式更改代码的装饰:

[RdfSerializable] 
public class Type1 
{ 
    [RdfProperty(true, Name = "title", ExcludeFromOntology=true)] 
    public string Title { get; set; } 
} 

[RdfSerializable] 
public class Type2 
{ 
    [RdfProperty(true, Name = "title", 
               DomainAsType = new Type[]{typeof(Type1), typeof(Type2)})] 
    public string Title { get; set; } 
} 

使用 OntologyExtractor.exe,此代码将生成一个带有匿名域类的 OWL 属性,该类是 Type1 和 Type2 的 UNION。
虽然这在技术上是完全正确的解决方案,但在属性上设置域会限制它们未来可能的重用。作为一种解决方案,您可能希望用本地限制替换属性域。您可以按如下方式实现:

[RdfSerializable] 
public class Type2 
{ 
    [RdfProperty(true, Name = "title", 
               DomainAsType = new Type[]{typeof(Type1), typeof(Type2)},
               UseLocalRestrictionInsteadOfDomain = true)] 
    public string Title { get; set; } 
} 

如果您未设置 UseLocalRestrictionInsteadOfDomain,ROWLEX 将根据当前上下文在域和本地限制之间进行选择。

于 2009-08-07T09:26:52.220 回答