如何在ROWLEX中的两个不同类型上定义具有相同名称的属性? [英] How to define a property with same name on two different types in ROWLEX?

查看:126
本文介绍了如何在ROWLEX中的两个不同类型上定义具有相同名称的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

推荐答案

我希望它是ROWLEX中的错误.您的案例是有效的案例,但是我想我在编写OntologyExtractor时没有为此做准备.我将尝试尽快发布修复程序.

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.

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

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

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

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

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

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

这篇关于如何在ROWLEX中的两个不同类型上定义具有相同名称的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆