简体   繁体   English

如何获得自治市的国家?

[英]How to get country of a municipality?

The ontology lies in XML here . 本体论在于XML 这里

I also tried to ask which are the classes of my world and then tried to check if my resource (the municipality) really belongs to that class, but still Country slips away (although it's fetched when I ask for all the classes, it fails to connect via the property belongs_to to my resource). 我还试图询问我的世界是哪个班级,然后尝试检查我的资源(市政当局)是否确实属于该班级,但是乡村仍然溜走了(尽管当我要求所有班级时都已获取了该资源,但它未能通过属性属居连接到我的资源)。

I have also enabled Forward chaining for reasoning in Sesame! 我还在芝麻中启用了正向推理链接 BTW, I am a beginner, so any tip would be gold to me. 顺便说一句,我是一个初学者,所以任何提示对我来说都是黄金。 What am I missing? 我想念什么?


Edit: 编辑:

New query: 新查询:

"SELECT ?res ?belongs " +
"WHERE  {" +
         "?res a geo:Mun ;"+
            "geo:hasName \"mun name\" ;"+
            "geo:belongs_to+ ?belongs ."+
        "}";

Output: 输出:

[belongs=http://geo.linkedopendata.gr/gag/id/1304;res=http://geo.linkedopendata.gr/gag/id/9325]
[belongs=http://geo.linkedopendata.gr/gag/id/13;res=http://geo.linkedopendata.gr/gag/id/9325]
[belongs=http://geo.linkedopendata.gr/gag/id/997;res=http://geo.linkedopendata.gr/gag/id/9325]

If I understand your data model correctly, you have instances of class geo:Municipality , which belong to an instance of geo:RegionUnit , which in turn belongs to an instance of geo:Region , etc, until ultimately they belong to an instance of geo:Country . 如果我正确理解了您的数据模型,则将拥有类geo:Municipality的实例,这些实例属于geo:RegionUnit的实例,而该实例又属于geo:Region的实例, geo:RegionUnit ,直到最终它们最终属于geo:Country的实例geo:Country And unless I misunderstand, your query tries to get back all these instances for one particular munipicality. 除非我误会,否则您的查询会尝试针对一种特定的多用途性来取回所有这些实例。

This is quite simply done, and does not even require any RDFS inferencing support. 这非常简单,甚至不需要任何RDFS推理支持。

Let's build up the query one step at a time. 让我们一次建立查询。 First, let's grab the actual municipality itself: 首先,让我们获取实际的市政当局本身:

SELECT ?res 
WHERE  {
           ?res a geo:Municipality ;
                geo:έχει_επίσημο_όνομα "ΔΗΜΟΣ ΧΑΝΙΩΝ" .
}

I'm assuming here (since I don't speak Greek) that geo:έχει_επίσημο_όνομα is the RDF property that links the Municipality resource with its name label. 我假设在这里(因为我不会说希腊语) geo:έχει_επίσημο_όνομα是将市政资源与其名称标签链接在一起的RDF属性。

The second step is that we want to grab all other resources it belongs to. 第二步是我们要获取它所属的所有其他资源。

SELECT ?res ?belongs
WHERE  {
           ?res a geo:Municipality ;
                geo:έχει_επίσημο_όνομα "ΔΗΜΟΣ ΧΑΝΙΩΝ" ;
                geo:belongsTo ?belongs .
}

Of course, the above only gets us back the things that it directly belongs to. 当然,以上内容只能使我们找回它直接属于的事物。 If we believe your ontology, this will give us back the region unit(s) it belongs to, but nothing else. 如果我们相信您的本体,这将使我们归还其所属的区域单位,但仅此而已。 But we want all of them, N steps removed, so we want to transitively follow the geo:belongsTo relation. 但是我们希望所有这些geo:belongsTo删除N步,因此我们希望可传递地遵循geo:belongsTo关系。 This can be done using a transitive property path: 这可以使用传递属性路径来完成:

SELECT ?res ?belongs
WHERE  {
           ?res a geo:Municipality ;
                geo:έχει_επίσημο_όνομα "ΔΗΜΟΣ ΧΑΝΙΩΝ" ;
                geo:belongsTo+ ?belongs .
}

Notice the + . 注意+ This means "one or more times", so the variable ?belongs will be bound to any values that can be reached by following the geo:belongsTo property one or more times (the * that you used in your question, btw, expresses 'zero or more times'). 这意味着“一次或多次”,因此变量?belongs将绑定到可以通过遵循geo:belongsTo属性一次或多次(可以在问题中使用的* btw表示*的零表示)的任何值。或更多次”)。

Update 更新

Now, if in addition to getting the individual resources, you also want to get back the classes themselves that they belong to (that is, geo:RegionUnit , geo:Country , etc), you can amend the query like so: 现在,如果除了获取单个资源之外,您还想要获取它们所属的类本身(即geo:RegionUnitgeo:Country等),则可以像这样修改查询:

SELECT ?res ?belongs ?adminUnit
WHERE  {
           ?res a geo:Municipality ;
                geo:έχει_επίσημο_όνομα "ΔΗΜΟΣ ΧΑΝΙΩΝ" ;
                geo:belongsTo+ ?belongs .
           ?belongs a ?adminUnit .
} 

This will give you back all administrative units that the given municipality belongs to, and the class of each particular administrative unit. 这将返回给定市镇所属的所有行政单位以及每个特定行政单位的类别。 Here, by the way, RDFS inferencing will make a slight difference: because all your admin-unit classes are defined as a rdfs:subClassOf the class geo:AdministrativeUnit , you will get back two results for each unit: once the specific class, and once the superclass geo:AdministrativeUnit . 顺便说一句,这里的RDFS推断会有所不同:因为所有管理单元类都定义为rdfs:subClassOf geo:AdministrativeUnit类的rdfs:subClassOf ,所以您将为每个单元返回两个结果:一次是特定的类,另一个是曾经是超类geo:AdministrativeUnit

Update 2 if the problem is that you get all the administrative units back except the country , then the most likely cause of this is that the geo:belongsTo relation between the specific Decentralised Admin (Let's call it geo:DecAdm for short) and the Country is missing. 如果问题是您将除国家以外的所有行政单位都geo:belongsTo ,请更新2 ,那么最可能的原因是特定分散管理(我们将其geo:DecAdmgeo:DecAdm )与国家/地区之间的geo:belongsTo关系不见了。 If you wish to verify this, you can do the following query: 如果您希望验证这一点,则可以执行以下查询:

ASK WHERE { 
    <http://geo.linkedopendata.gr/gag/id/997> geo:belongsTo [ a geo:Country ] . 
} 

Replace <http://geo.linkedopendata.gr/gag/id/997> with the actual id of the geo:DecAdmin you're interested in. The query will return true if the relation exists, false otherwise. <http://geo.linkedopendata.gr/gag/id/997>替换为您感兴趣的geo:DecAdmin的实际ID。如果关系存在,查询将返回true ,否则返回false

Or if you want to check more generally, you can do the following: 或者,如果您想更一般地进行检查,则可以执行以下操作:

SELECT ?decAdmin ?country 
WHERE { 
       ?decAdmin a geo:DecAdm .
       OPTIONAL { ?decAdmin geo:belongsTo ?country .
                  ?country a geo:Country .
       }
} ORDER BY ?decAdmin

This query will give you an overview of all decentralized administration instances, and the country to which they belong. 该查询将为您提供所有分散管理实例的概述,以及它们所属的国家。 If there is no country known for a particular ?decAdmin , the second column in your query result will be empty for that row. 如果没有?decAdmin国家/地区特定的?decAdmin ,查询结果中的第二列对于该行将为空。

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

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