RDF/OWL 中的字符串操作 [英] String manipulation in RDF/OWL

查看:57
本文介绍了RDF/OWL 中的字符串操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于语义网的初学者问题.

A Beginner question about the semantic web.

我有一个颜色知识库,其中包括相似的颜色、颜色修饰符(暗、亮、~ish 等)、颜色关系(更深、更亮)、颜色同义词等.我想弄清楚 RDF/OWL 是操作(主要是查询)此 KB 的不错选择.以下是我需要支持的查询.

I have a knowledge base of colors which includes similar colors, color modifiers (dark, light, ~ish, etc), color relations (darker, brighter), color synonyms, etc. I am trying to figure out if RDF/OWL is a good choice to manipulate (mainly query) this KB. Here are the queries I need to support.

1) 找出与给定颜色相似的所有颜色.如果我用相似"谓词表示颜色相似性,一个简单的 Sparql 查询就可以了.同义词和关系也是如此.不错.

1) Find all colors similar to a given color. If I represent color similarity with a "similar" predicate, a simple Sparql query will do. Same for synonyms and relations. Good.

2) 当我需要查找标记或短语 x 是否为有效颜色时,问题变得更加棘手.如果 x 是未修改的颜色,则可以通过创建 Color 类并确保所有已知颜色都是该类的实例来解决该问题.但是如果 x 是像 "redish" 这样的修改颜色呢?显然,一种解决方案是通过显式添加来使知识库中所有修改过的颜色部分都包含在内.

2) The problem becomes more tricky when I need to find if a token or phrase x is a valid color. If x is an unmodified color, the problem can be solved by creating a Color class and making sure all the known colors are instances of that class. But what if x is a modified color like "redish" ? Obviously, one solution would be to have all the modified colors part of the KB by adding them explicitly.

但是,是否可以将所有修改后的颜色自动添加到 RDF 中?换句话说,是否可以定义一类包含所有修改颜色的修改颜色?这需要一些连接运算符.这可能吗?

But, is it possible to add all the modified colors automatically to the RDF? In other words, is it possible to define a class of modified colors that would entail all modified colors? This requires some concatenation operator. Is that at all possible?

另一种解决方案是有一些逻辑来分解 x 并检查 a) 它是否包含已知的修饰符和 b) 修改的东西是否是有效的颜色.当然,我也希望在 RDF/OWL 中描述这种逻辑.有什么想法吗?

Another solution would be to have some logic to decompose x and check a) if it contains a known modifier and b) if the modified thing is a valid color. Of course, I'd like this logic to be described in RDF/OWL as well. Any idea?

预先感谢您的任何意见或建议.

Thanks in advance for any input or suggestion.

推荐答案

您想要做的事情似乎可以更好地处理,IMO,使用您最喜欢的编程语言的自定义代码段.用OWL很难表达这些东西,当然效率也不高.

What you want to do seems to be better handled, IMO, with a custom piece of code in your favourite programming language. Difficult to express these kinds of things in OWL, and certainly not efficient.

但是 FWIW,这是您可以做的事情.系好安全带,这里开始高级 OWL 2 建模之旅.假设您有基色蓝色"、绿色"、红色".您可以定义包含三个字符串的数据类型(我使用 Turtle 语法):

But FWIW, here is something you can do. Fasten your seat belt, here begins a trip to advanced OWL 2 modelling. Assume that you have the base colours "blue", "green", "red". You can define a datatype that includes the three strings (I use Turtle syntax):

:baseColor  a  rdfs:Datatype;
    owl:equivalentClass  [
        a  rdfs:Datatype;
        owl:withRestrictions ( [ xsd:pattern "blue|green|red" ] )
    ] .

然后您可以定义修改后的颜色:

Then you can define modified colours:

:modColor  a  rdfs:Datatype;
    owl:equivalentClass  [
        a  rdfs:Datatype;
        owl:withRestrictions (
            [ xsd:pattern "(dark|light)?(blue|green|red)(ish)?" ]
        )
    ] .

你甚至可以有更多的数据类型,例如 :lightColor:darkColormediumColor.

you could even have more datatypes such as :lightColor, :darkColor, mediumColor.

然后创建一个具有数据类型属性 :hasColor:

Then you make a class :Color that has a datatype property :hasColor:

:hasColor  a  owl:DatatypeProperty;
    rdfs:domain  :Color;
    rdfs:range  [
        a  rdfs:Dataype;
        owl:unionOf  ( :baseColor :modColor )
    ]
:Color  a  owl:Class;
    rdfs:subClassOf  [
       a  owl:Restriction;
       owl:onProperty  :hasColor;
       owl:someValuesFrom  xsd:string
    ];
    owl:hasKey  ( :hasColor ) .

在这里,我强加 :Color 的实例至少有一个颜色字符串,并且我强加颜色字符串是颜色的唯一标识符(它是一个键).因此,每当我用颜色字符串给出颜色时,我就可以验证该字符串是否在上面给出的正则表达式模式中.假设我定义了数据类型 :darkColor:lightColor:mediumColor,我也可以表达 :darker:lighter 关系:

Here, I impose that instances of :Color have at least a color string and I impose that the color string is a unique identifier for the color (it's a key). So, whenever I have a color given with its color string, I can verify that the string is in the regex patterns given above. Assuming I defined the datatypes :darkColor, :lightColor and :mediumColor, I can also express the :darker and :lighter relations:

:DarkColor  a  owl:Class;
    rdfs:subClassOf  :Color, [
        a  owl:Restriction;
        owl:onProperty  :hasColor;
        owl:allValuesFrom  :darkColor
    ] .
:LightColor  a  owl:Class;
    rdfs:subClassOf  :Color, [
        a  owl:Restriction;
        owl:onProperty  :hasColor;
        owl:allValuesFrom  :lightColor
    ] .
:MediumColor  a  owl:Class;
    rdfs:subClassOf  :Color, [
        a  owl:Restriction;
        owl:onProperty  :hasColor;
        owl:allValuesFrom  :mediumColor
    ] .

那么你想说所有的:DarkColor比所有的:MediumColor和所有的:LightColor:darker代码>.这样的公理实现起来并不容易,因为它需要引入辅助项.论文所有大象都比所有老鼠都大,在深度学习术语中,它被称为概念产品:

Then you want to say that all :DarkColors are :darker than all :MediumColor and all :LightColor. Such an axiom is not trivial to implement as it demands to introduce auxiliary terms. It is explained in the paper All Elephants are Bigger than All Mice and it's called, in DL terminology, concept product:

:p1  a  owl:ObjectProperty . # auxiliary property (do not reuse elsewhere)
:p2  a  owl:ObjectProperty . # idem
:x  a  owl:Thing .           # auxiliary individual
:darker  owl:propertyChainAxiom ( :p1 :p2 ) .
:DarkColor  rdfs:subClassOf  [
    a  owl:Restriction;
    owl:onProperty  :p1;
    owl:hasValue  :x
] .
[ owl:unionOf ( :LightColor :MediumColor ) ] rdfs:SubClassOf  [
    a  owl:Restriction;
    owl:onProperty  [ owl:inverseOf :p2 ];
    owl:hasValue  :x
] .

:lighter 执行相同的操作.

Do the same for :lighter.

您无法真正自动引入修改后的颜色.您确实必须提供一个包含所有基色 + 修饰符的图案.但这可以很容易地以编程方式完成.无论如何,不​​应使用我提供的 OWL 代码,IMO,因为定制程序可以更好/更有效地解决它.

You can't really introduce the modified colours automatically. You really have to provide a pattern that contain all the base colors + the modifiers. But this can easily be done programmatically. In any case, the OWL code that I give should not be used, IMO, as it's much better/more efficiently addressed by a customised programme.

这篇关于RDF/OWL 中的字符串操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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