2009-08-07 68 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

相關問題