How to define a property with same name on two different types in ROWLEX?

╄→гoц情女王★ 提交于 2019-12-11 04:22:48

问题


If I have those two classes that have two different properties but with the same name:

[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; }
}

and try to serialize them to RDF and validate them with http://www.w3.org/RDF/Validator/ service. Everything is Okay and they are correct. But after I try to generate OWL files from those classes with OntologyExtractor.exe tool I get that message: "Ontology extraction failed. http://test.org/1.0#title is assigned to more than one type." This is strange message as the upper classes are correct and there are some RDF specifications that has same situation with different classes that have same named properties.


回答1:


I expect it is a bug in ROWLEX. Your case is a valid one, but I assume I did not prepare for it when I wrote OntologyExtractor. I will try to release a fix as soon as possible.

EDIT: ROWLEX2.1 is released, you can download it from http://rowlex.nc3a.nato.int. Version 2.1 (among others) supports now the shared property functionality. The exact code in the question would still result the same error! To overcome that, you should alter the decoration of your code as follows:

[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; } 
} 

Using the OntologyExtractor.exe, this code will result a OWL property of with an anonymous domain class that is the UNION of Type1 and Type2.
While this is technically perfectly correct solution, setting domains on properties limit their possible future reuse. As a solution, you might want to substitute the property domain with local restrictions. You can achieve that as follows:

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

Should you leave UseLocalRestrictionInsteadOfDomain not set, ROWLEX chooses between domain and local restriction according to the current context.



来源:https://stackoverflow.com/questions/1243410/how-to-define-a-property-with-same-name-on-two-different-types-in-rowlex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!