2009-08-07 71 views
1

如果我有有两个不同的属性,但具有相同名称的两个类:如何在ROWLEX中的两种不同类型上定义一个具有相同名称的属性?

[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规范与具有相同命名属性的不同类具有相同的情况。

回答

1

我认为这是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联盟匿名域类。
虽然这在技术上是完全正确的解决方案,但在属性上设置域限制了它们今后可能的重用。作为解决方案,您可能希望用本地限制来替换属性域。你可以做到这一点,如下所示:

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

你应该离开UseLocalRestrictionInsteadOfDomain没有设置,ROWLEX域,并根据当前上下文本地的限制之间进行选择。

+0

太棒了!谢谢!之后我会验证它。 – 2009-08-10 09:03:12

相关问题