简体   繁体   English

如何在 SPARQL 查询中过滤个人

[英]How to filter on individuals in SPARQL queries

I'm new to this language and queries.我是这种语言和查询的新手。 In Protege, I am using the PROV ontology and FOAF and I also added a few of my own instances and classes.在 Protege 中,我使用了 PROV 本体和 FOAF,还添加了一些我自己的实例和类。 With this ontology, I am trying to map the process of a medical research.有了这个本体,我正在尝试对map进行医学研究的过程。 With the SPARQL queries, I want to quickly retrieve important information about the process.通过 SPARQL 查询,我想快速检索有关流程的重要信息。

I have multiple questions:我有多个问题: 在此处输入图像描述

Looking at the query above, the output makes sense to me.查看上面的查询,output 对我来说很有意义。 On the left are some research papers (MetaAnalysis belongs to the class MetaAnalysisPaper and Paper2 belongs to the class Research) and on the right are some names that are part of the class Author.左边是一些研究论文(MetaAnalysis 属于 class MetaAnalysisPaper 和 Paper2 属于 class Research),右边是 class 作者的一些名称。

  1. How do I filter on MetaAnalysis?如何过滤 MetaAnalysis? So that only 'MetaAnalysis wasAttributedTo (name of author)' relations show up, and not Paper2.所以只有“MetaAnalysis wasAttributedTo(作者姓名)”关系出现,而不是 Paper2。
  2. How do I filter on Author, let's say for example Biederman?我如何过滤作者,例如比德曼? So that only the relation 'MetaAnalysis wasAttributedTo Biederman' shows up.所以只有关系“MetaAnalysis wasAttributedTo Biederman”出现。

The following is an individual:以下为个人: 在此处输入图像描述

I also have the CImin individual, also belonging to the ConfidenceInterval class, it has the same wasGeneratedBy relation, the value is 0.12 and defined in the same way as CImax.我也有 CImin 个体,也属于 ConfidenceInterval class,它具有相同的 wasGeneratedBy 关系,值为 0.12,定义方式与 CImax 相同。

  1. I want an output that gives me the value (0.39) of the CImax and the value (0.12) of the CImin.我想要一个 output,它给我 CImax 的值 (0.39) 和 CImin 的值 (0.12)。 Is it possible to get just both these outputs with one query?是否可以通过一个查询同时获得这两个输出? What would this query look like?这个查询会是什么样子? And if it isn't possible with one query, what would the query for just the value of CImax look like?如果一个查询不可能,那么只查询 CImax 的值会是什么样子?

Thank you in advance.先感谢您。 My Turtle file was very, very big, so I decided to not upload it here, but if it's necessary, please let me know.我的 Turtle 文件非常非常大,所以我决定不在这里上传,但如果有必要,请告诉我。

How do I filter on MetaAnalysis?如何过滤 MetaAnalysis? So that only 'MetaAnalysis wasAttributedTo (name of author)' relations show up, and not Paper2.所以只有“MetaAnalysis wasAttributedTo(作者姓名)”关系出现,而不是 Paper2。

You can do this using filter expressions .您可以使用过滤器表达式来做到这一点。 For example, in your case you could add something like:例如,在您的情况下,您可以添加如下内容:

FILTER(?property = lol:MetaAnalysis)

I say "something like" this because in your screenshots, it's not clear what namespace the resource MetaAnalysis is in. I'm guessing it's the default ontology namespace created by Protege (abbreviated to lol going by the first image), but you may need to double-check that.我说“类似”是因为在您的屏幕截图中,不清楚MetaAnalysis资源所在的命名空间。我它是 Protege 创建的默认本体命名空间(第一张图片缩写为lol ),但您可能需要仔细检查。

How do I filter on Author, let's say for example Biederman?我如何过滤作者,例如比德曼? So that only the relation 'MetaAnalysis wasAttributedTo Biederman' shows up.所以只有关系“MetaAnalysis wasAttributedTo Biederman”出现。

Same idea, just different variable and value:相同的想法,只是不同的变量和值:

FILTER(?object = lol:Biederman) 

(this is assuming that Biederman is a resource URI in your data, and not a literal value - it's not clear from your screenshots) (这是假设Biederman是您数据中的资源 URI,而不是文字值 - 从您的屏幕截图中不清楚)

Put either filter condition in the WHERE clause (after the statement pattern) and you should be good to go.将任一过滤条件放在 WHERE 子句中(在语句模式之后),您应该对 go 很好。

I want an output that gives me the value (0.39) of the CImax and the value (0.12) of the CImin.我想要一个 output,它给我 CImax 的值 (0.39) 和 CImin 的值 (0.12)。 Is it possible to get just both these outputs with one query?是否可以通过一个查询同时获得这两个输出? What would this query look like?这个查询会是什么样子? And if it isn't possible with one query, what would the query for just the value of CImax look like?如果一个查询不可能,那么只查询 CImax 的值会是什么样子?

Yes, that's possible, in multiple ways.是的,这是可能的,有多种方式。 One thing you could do is create a SPARQL query that gets all individuals of type ConfidenceInterval (something like ?ci rdf:type lol:ConfidenceInterval. ) and grab their values (eg ?ci lol:value?value ).您可以做的一件事是创建一个 SPARQL 查询,该查询获取所有类型为ConfidenceInterval的个人(类似于?ci rdf:type lol:ConfidenceInterval. )并获取他们的值(例如?ci lol:value?value )。 Combine both patterns in a single SPARQL query to get all things that match both patterns.在单个 SPARQL 查询中组合这两种模式,以获得与这两种模式匹配的所有内容。 Add additional filters and patterns as you go to make your query more specific, as needed.根据需要添加其他过滤器和模式 go 以使您的查询更加具体。

More generally speaking: this is really basic SPARQL that you're asking for here.更一般地说:这确实是您在这里要求的基本 SPARQL。 I'd recommend you do a tutorial, there's several really good ones available online, a quick Google will sort you out.我建议你做一个教程,网上有几个非常好的教程,一个快速的谷歌会帮你解决。

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

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