Compare models for identity, but with variables? Construct with minus?

旧街凉风 提交于 2019-12-02 02:01:20

Once again bailed out by a comment from @AKSW, who doesn't seem to be especially obsessed with earning reputation points.

This CONSTRUCT, with an embedded SELECT, gets all triples from my model, depleted of any triples in the MINUS block, even when they contain variables. I'm pretty sure I can flesh out the MINUS block and finish my task.

PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT 
  { 
    ?s ?p ?o .
  }
WHERE
  { SELECT  ?s ?p ?o
    WHERE
      { { ?s  ?p  ?o }
        MINUS
          { ?s  rdf:type  ?o }
      }
  }

In order to determine that the triple-store contains only the triples which you expect and nothing more, you could test for the exact triples which you expect while simultaneously counting the number of triples which appear in the database before and after you run your program. If the difference in triples is higher or lower than you expect, you will know that you have some extraneous or missing data.

Use SPARQL SELECT Count function:

SELECT (count(?triples) as ?count)
WHERE {
?triples ?p ?o .}

Pseudocode:

val beforeTripleCount = countTriplesInDatabase()
//run your program, test for expected triples
val afterTripleCount = countTriplesInDatabase()
val diff = afterTripleCount - beforeTripleCount
//diff should be equal to the number of triples you expect to be added/removed

Additionally, if you are resistant to using variables in your tests, you could write additional queries to capture the URI of the node you have created, then add the results to your test queries using String concatenation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!