简体   繁体   English

Sparql VS XQuery(MarkLogic)

[英]Sparql VS XQuery (MarkLogic)

After playing with MarkLogic I realized results from triples can be obtained in several ways for example by fully using either Xquery or SPARQL. 在玩完MarkLogic之后,我意识到可以通过多种方式(例如,完全使用Xquery或SPARQL)获得三元组的结果。 So the question is that, are there any advantages using SPARQL over XQuery? 所以问题是,与XQuery相比,使用SPARQL有什么优势吗? Is there some indexing going on which makes SPARQL much faster then searching for a certain semantic query? 是否正在进行一些索引编制,这使SPARQL比搜索特定语义查询快得多?

For instance if we are retrieving all semantic documents with the predicate "/like". 例如,如果我们以谓词“ / like”检索所有语义文档。

SPARQL SPARQL

SELECT *
WHERE {
  ?s </like> ?o
}

XQuery XQuery

cts:search(fn:doc(), cts:element-query(xs:QName("sem:predicate"), "/like"))

Therefore, is there any difference in efficiency between these two? 因此,两者的效率有何不同?

Yes, there are definitely differences. 是的,肯定有区别。 Whether XQuery or SPARQL is most efficient however fully depends on the problem you are trying to solve. XQuery或SPARQL是最有效的还是完全取决于您要解决的问题。 XQuery is best at querying and processing document data, while SPARQL really allows you to reason easily over RDF data. XQuery最适合查询和处理文档数据,而SPARQL确实使您可以轻松地推理RDF数据。

It is true that RDF data is serialized as XML in MarkLogic, and you can full-text search it, and even put range indexes on it if you like, but RDF data is already indexed in the triple index, which would give you more accurate results than the full-text search of above. 的确,RDF数据在MarkLogic中被序列化为XML,您可以对其进行全文搜索,甚至可以在其上放置范围索引,但是RDF数据已经在三重索引中建立了索引,这将使您更加准确结果比上面的全文搜索要多。

Also note that SPARQL allows you to follow predicate paths, which involves a lot of joining. 还要注意,SPARQL允许您遵循谓词路径,这涉及很多连接。 That will be much more efficient if done via SPARQL than via XQuery, because it is mostly resolved via the triple index. 如果通过SPARQL进行操作,则比通过XQuery进行操作更为有效,因为它主要是通过三重索引解决的。 Image a SPARQL query like this one: 像这样的一个SPARQL查询图像:

PREFIX pers: <http://my.persons/>;
PREFIX topic: <http://my.topics/>;
PREFIX pred: <http://my.predicates/>;
SELECT DISTINCT *
WHERE {
  ?person pred:likes topic:Chocolate;
          pred:friendOf+ ?friend.
  FILTER( ?friend = (pres:WhiteSolstice) )
  FILTER( ?friend != ?person )
}

It tries to find all direct and indirect friends that like chocolate. 它试图找到所有喜欢巧克力的直接和间接朋友。 I wouldn't write something like that in XQuery. 我不会在XQuery中写类似的东西。

Then again, there are other things that are easy in XQuery, and practically impossible in SPARQL. 再说一遍,还有其他事情在XQuery中很容易实现,而在SPARQL中几乎是不可能的。 And sometimes most efficient is to combine the two, doing a sem:sparql from inside XQuery, and using the results to direct further processing in XQuery. 有时最有效的方法是将两者结合起来,在XQuery内部执行sem:sparql,然后使用结果指导XQuery中的进一步处理。 It also sometimes comes down to what shape your data is in.. 有时也取决于您的数据的形状。

HTH! HTH!

A little nuance here: search is about searching for documents. 这里有些细微差别:搜索是关于搜索文档的。 Unless you have one triple per document, fetching just the triples that match out of a bunch in a document will involving pulling the whole document from disk (although it may be in cache). 除非每个文档有一个三元组,否则仅从一个文档堆中取出匹配的三元组会涉及从磁盘中拉出整个文档(尽管它可能在缓存中)。 SPARQL is about selecting triple data from the triple indexes, which may involve less disk IO. SPARQL用于从三重索引中选择三重数据,这可能会涉及较少的磁盘IO。 Certainly if you are doing anything other than a simple fetch of a simple triple pattern, you're going to need the understanding of relationships that SPARQL gives you. 当然,如果您要执行的工作不是简单地获取简单的三重模式,您将需要了解SPARQL为您提供的关系。

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

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