简体   繁体   English

如何在OWL文字值中放入整数“范围”?

[英]how to put integer “range” in OWL literal value?

Let's say that I have metal material in db that have property Yield strength which can go from 300 to 500 MPa. 假设我在db中有金属材料,其材料的屈服强度可以从300到500 MPa。 How can i enter that as literal value. 我如何输入该字面值。

Should I put 2 properties like YieldStrengthMin and YieldStrengthMax , or it can be done in single entry and formatted something like 300 - 500. I know that I can put it like that as a string type, but what I need is that when I SPARQL my db, I should make query that will find all materials that have let's say YieldStrength > 350 . 我应该放置2个属性,例如YieldStrengthMinYieldStrengthMax ,还是可以在单个条目中完成并设置格式,例如300-500。我知道我可以将其作为字符串类型放置,但是我需要的是当我使用SPARQL db,我应该进行查询,以找到所有让我们说YieldStrength > 350 If it's in that interval even partial it should be a valid result. 如果在该间隔内,即使是部分间隔,也应该是有效的结果。

OK, another example to clarify 好,再举一个例子来说明

I will have db of materials and each type of material have many properties. 我将拥有db的材料,每种类型的材料都有许多属性。 Let's say prop:hasMeltingTemperature . 假设prop:hasMeltingTemperature

material:ZA-12 prop:hasMeltingTemperature    "380 - 430".

material:Zn    prop:hasMeltingTemperature    "420".

Some of them (clean materials) will have one melting temp, and temp of alloys will vary depending of percent of some components. 其中一些(清洁材料)将具有一个熔化温度,合金的温度将根据某些成分的百分比而变化。

My application will have to get all materials from db that have let's say melting temperature > 400. So in this case it should get both of them. 我的应用程序必须从db中获取所有材料,这些材料的熔点温度>400。因此,在这种情况下,应该同时获取它们。

And if I query that i need all materials that have melting temp < 425 it should take both of them too. 如果我查询到我需要所有熔点<425以下的材料,则也应同时使用这两种材料。 If query is < 400, then only first material. 如果查询<400,则仅第一个材料。

Anyway, my question is: 无论如何,我的问题是:

Should i make properties like this: 我应该做这样的属性:

material:ZA-12 prop:hasMeltingTemperature_MIN "380".

material:ZA-12 prop:hasMeltingTemperature_MAX "430".

material:Zn    prop:hasMeltingTemperature     "420".

then when I query I have to detect ">" then compare it to "MIN" temp and "solo" temp, and if it's "<" then compare it to "MAX" temp and "solo" temp. 那么当我查询时,我必须检测“>”,然后将其与“ MIN”温度和“ solo”温度进行比较,如果它是“ <”,则将其与“ MAX”温度和“ solo”温度进行比较。

In this case I have to first detect does material have only "one" or "min-max" temp or "none" temp property. 在这种情况下,我必须首先检测材料是否仅具有“一个”或“最小-最大”温度或“无”温度属性。

OR 要么

I can do it something like in the first example and have only one property like: 我可以像第一个示例中那样做,并且只有一个属性,如:

material:ZA-12 prop:hasMeltingTemperature "380 - 430".

material:Zn    prop:hasMeltingTemperature "420" .

and make some kind of sparql query that could understand "intervals" and compare them? 并进行某种sparql查询,可以理解“间隔”并进行比较?

That's what I was wondering because there are many properties of materials, and many materials, and some of them have "min max" value, some "solo" value, and some don't have that property at all, but have another one with the same problem... 那就是我想知道的,因为材料有很多特性,很多材料,其中一些具有“最小最大”值,一些“单独”值,有些根本不具有该特性,但又有一个具有同样的问题...

My application will be in php so i will have to generate sparql query in php, so that's why i was looking for some "universal" type of query (checking only one property).. 我的应用程序将在php中,因此我将不得不在php中生成sparql查询,因此这就是为什么我在寻找某种“通用”类型的查询(仅检查一个属性)的原因。

So my problem is more how to efficiently sparql query it, what's better choice of that 2 for storing data, and how to query it' 因此,我的问题更多是如何有效地对sparql进行查询,该2用于存储数据的更好选择以及如何查询它。

There a few different things that you could mean here. 在这里您可能要说几件事。 You could 你可以

  1. declare that the range of a property is a value within some range; 声明属性的范围是某个范围内的值;
  2. assert that for some particular individual, its values of a particular property are within some range; 断言,对于某些特定个人,其特定属性的值在一定范围内;

Given that you said that: 鉴于您说的是:

what i need is that when i SPARQL my db, i should make query that will find all materials that have let's say YieldStrength > 350. If it's in that interval even partial it should be a valid result. 我需要的是,当我SPARQL我的数据库时,我应该进行查询,以找到所有让我们说YieldStrength> 350的材料。如果在该间隔中,即使是部分间隔,也应该是有效的结果。

Using two properties 使用两个属性

I think that your best best is to use two properties (eg, minStrength / maxStrength ). 我认为最好的办法是使用两个属性(例如minStrength / maxStrength )。 This means that you can have data like: 这意味着您可以拥有以下数据:

metal72 minStrength 200 ;
        maxStrength 400 .

Then you can write a query with a pattern like 然后,您可以使用以下模式编写查询

?metal minStrength ?min ;
       maxStrength ?max .
filter( ?min <= 350 && 350 <= ?max )

I think this most closely matches the idea you're trying to capture, because it sounds like each metal is actual associated with some range of values. 我认为这与您尝试捕获的想法最接近,因为听起来每种金属实际上都与某个值范围相关联。 Where some metals can have exact values (and not a range), you can still use this approach, by putting in your data: 在某些金属可以具有精确值(而不是范围)的情况下,您仍然可以通过输入数据来使用这种方法:

Zn minStrength 420 ;
   maxStrength 420 .

Then all of your metals are consistent (they all have a min value and a max value), and your queries won't have to worry about different cases. 然后, 所有的金属都是一致的(他们都有一个最小值和最大值),和您的查询不会担心不同的情况。

Using ranges, and querying the RDF serialization of the OWL 使用范围,并查询OWL的RDF序列化

Now, while I think that the previous approach makes more sense, you can represent data ranges in OWL. 现在,虽然我认为以前的方法更有意义,但是您可以用OWL表示数据范围。 For instance, if there's a hasStrength property, you could say that some metal has strengths only within some range by using a restriction like 例如,如果具有hasStrength属性,则可以使用限制来说某些金属的强度仅在一定范围内

metal72 a (hasStrength only int[>=200,<=400])

In Protégé this looks like: 在Protégé中,它看起来像:

限制

What this actually means though is not that the metal has some strength range, but that for any triple of the form metal72 hasStrength x , the value of x must be an int in the range [200,400] , or else the data is inconsistent. 什么这实际上意味着虽然不是金属具有一定的强度范围内,但是,对于任何三重形式的metal72 hasStrength x ,值x必须是int在范围[200,400]否则数据不一致。 This is obviously different than saying that the metal has a strength range. 这显然不同于说金属具有强度范围。

The OWL ontology can be serialized in RDF, and then you can query the RDF using SPARQL. 可以在RDF中对OWL本体进行序列化 ,然后可以使用SPARQL查询RDF。 You'll need to know what the RDF looks like though. 您将需要知道RDF的外观。 In this case, it's: 在这种情况下,它是:

:metal72  a     owl:NamedIndividual , :Metal ;
        a       [ a                  owl:Restriction ;
                  owl:allValuesFrom  [ a                     rdfs:Datatype ;
                                       owl:onDatatype        xsd:int ;
                                       owl:withRestrictions  ( [ xsd:minInclusive
                                                         200 ] [ xsd:maxInclusive
                                                         400 ] )
                                     ] ;
                  owl:onProperty     :hasStrength
                ] .

That's a bit much, but you can query against it with SPARQL with a query like the following. 有点多,但是您可以使用SPARQL对其进行查询,如下所示。 It will return any ?metal which has a type hasStrength only int[>=min,<=max] , where min ≤ 350 ≤ max . 它会返回任何?metal ,其具有类型hasStrength only int[>=min,<=max]其中min ≤ 350 ≤ max

prefix metal: <http://www.example.org/metal#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix xsd:   <http://www.w3.org/2001/XMLSchema#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?metal where { 
  ?metal a metal:Metal ;
         a [ owl:allValuesFrom [ owl:withRestrictions [ rdf:rest* [ xsd:minInclusive ?min ] ] ;
                                                      [ rdf:rest* [ xsd:maxInclusive ?max ] ] ] ;
             owl:onProperty metal:hasStrength ] .
  filter( ?min <= 350 && 350 <= ?max ) 
}

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

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