简体   繁体   中英

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. Here are the queries I need to support.

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

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?

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.

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.

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

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

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

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

Then you want to say that all :DarkColor s 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
] .

Do the same for :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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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