简体   繁体   English

RDF / OWL中的字符串操作

[英]String manipulation in RDF/OWL

A Beginner question about the semantic web. 关于语义网的初学者问题。

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. 我有颜色的知识库,其中包括相似的颜色,颜色修改器(深色,浅色,〜ish等),颜色关系(较暗,更明亮),颜色同义词等。我试图弄清楚RDF / OWL是否为处理(主要是查询)此KB的好选择。 Here are the queries I need to support. 这是我需要支持的查询。

1) Find all colors similar to a given color. 1)查找与给定颜色相似的所有颜色。 If I represent color similarity with a "similar" predicate, a simple Sparql query will do. 如果我用“相似”谓词表示颜色相似度,则将执行简单的Sparql查询。 Same for synonyms and relations. 同义词和关系也一样。 Good. 好。

2) The problem becomes more tricky when I need to find if a token or phrase x is a valid color. 2)当我需要查找标记或短语x是否为有效颜色时,问题变得更加棘手。 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. 如果x是未修改的颜色,则可以通过创建Color类并确保所有已知颜色都是该类的实例来解决该问题。 But what if x is a modified color like "redish" ? 但是,如果x是修饰的颜色(如“红色”)怎么办? Obviously, one solution would be to have all the modified colors part of the KB by adding them explicitly. 显然,一种解决方案是通过显式添加它们,将所有修改后的颜色部分包含在KB中。

But, is it possible to add all the modified colors automatically to the RDF? 但是,是否可以将所有修改后的颜色自动添加到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? 那有可能吗?

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. 另一个解决方案是具有一些逻辑来分解x并检查a)是否包含已知修饰符,以及b)修饰后的事物是否为有效颜色。 Of course, I'd like this logic to be described in RDF/OWL as well. 当然,我也希望在RDF / OWL中描述这种逻辑。 Any idea? 任何的想法?

Thanks in advance for any input or suggestion. 在此先感谢您的任何意见或建议。

What you want to do seems to be better handled, IMO, with a custom piece of code in your favourite programming language. IMO,使用您喜欢的编程语言编写的自定义代码,似乎可以更好地处理您想做的事情。 Difficult to express these kinds of things in OWL, and certainly not efficient. 很难用OWL来表达这些东西,而且肯定没有效率。

But FWIW, here is something you can do. 但是FWIW,这是您可以做的。 Fasten your seat belt, here begins a trip to advanced OWL 2 modelling. 系好安全带,从这里开始进行高级OWL 2建模的旅程。 Assume that you have the base colours "blue", "green", "red". 假设您具有“蓝色”,“绿色”,“红色”的基色。 You can define a datatype that includes the three strings (I use Turtle syntax): 您可以定义一个包含三个字符串的数据类型(我使用Turtle语法):

: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)?" ]
        )
    ] .

you could even have more datatypes such as :lightColor , :darkColor , mediumColor . 您甚至可以拥有更多的数据类型,例如:lightColor:darkColormediumColor

Then you make a class :Color that has a datatype property :hasColor : 然后,创建具有数据类型属性:hasColor的类:Color

: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 ) .

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). 在此,我强加:Color实例至少具有一个颜色字符串,并且强加该颜色字符串是该颜色的唯一标识符(这是一个键)。 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:lightColor:mediumColor ,我还可以表达:darker:lighter关系:

: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
    ] .

Then you want to say that all :DarkColor s are :darker than all :MediumColor and all :LightColor . 然后,您要说所有:DarkColor都比所有:MediumColor和所有:LightColor :darker 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: 在论文《 所有大象比所有老鼠都更大》中对此进行了解释,在DL术语中,它被称为概念产品:

: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
] .

Do the same for :lighter . :lighter做同样的事情。

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. 无论如何,IMO不应该使用我提供的OWL代码,因为通过定制程序可以更好/更有效地解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM