WikiTask Tutorial/Triple Query

From BITPlan Wiki
Revision as of 08:35, 27 April 2020 by Wf (talk | contribs) (pushed from https://partner.bitplan.com)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How to use TripleQueries

The TripleQuery Javadoc page shows the available functions for a TripleQuery. Using these functions you can select data from a TripleStore as you see fit.

Example SiDIF input

This example SiDIF has id='ex1'. It shows the 27 possible combinations of subject1-3, predicate1-3 and object1-3

subject1 predicate1 object1
subject1 predicate1 object2
subject1 predicate1 object3
subject2 predicate1 object1
subject2 predicate1 object2
subject2 predicate1 object3
subject3 predicate1 object1
subject3 predicate1 object2
subject3 predicate1 object3
subject1 predicate2 object1
subject1 predicate2 object2
subject1 predicate2 object3
subject2 predicate2 object1
subject2 predicate2 object2
subject2 predicate2 object3
subject3 predicate2 object1
subject3 predicate2 object2
subject3 predicate2 object3
subject1 predicate3 object1
subject1 predicate3 object2
subject1 predicate3 object3
subject2 predicate3 object1
subject2 predicate3 object2
subject2 predicate3 object3
subject3 predicate3 object1
subject3 predicate3 object2
subject3 predicate3 object3

default query

The statement:

<#assign query=tripleStore.query()/>

gets the default query for the tripleStore. This query selects all triples of the tripleStore. The triples of a query are accessible with query.getTriples().

Example template for default query

The following template with the id='query1' shows how all triples of the tripleStore are selected:

<#assign query=tripleStore.query()/>
<#list query.getTriples() as triple>
${triple_index+1} subject: ${triple.subject} predicate: ${triple.predicate} object: ${triple.object}<br>
</#list>

Example wikitask for default query

{{wikitask|cmd=runtemplate|input=ex1|template=query1|targetpage=WikiTask Tutorial/query1 result}}

runtemplate -> WikiTask Tutorial/query1 result

expected result for default query

1 subject: subject1 predicate: predicate1 object: object1
2 subject: subject1 predicate: predicate1 object: object2
3 subject: subject1 predicate: predicate1 object: object3
4 subject: subject1 predicate: predicate2 object: object1
5 subject: subject1 predicate: predicate2 object: object2
...

Specific query

The statement:

<#assign query=tripleStore.query()/>
<#assign qSubjects=query.query(null,"predicate1","object1")/>
<#list qSubjects.getTriples() as triple>
${triple_index+1} subject: ${triple.subject} predicate: ${triple.predicate} object: ${triple.object}<br>
</#list>

gets a specific query for the tripleStore. This query selects all triples of the tripleStore, which contain "predicate1" and "object1". The triples of this query are accessible with qSubjects.getTriples().

Example wikitask for specific query

{{wikitask|cmd=runtemplate|input=ex1|template=query2|targetpage=WikiTask Tutorial/query2 result}}

runtemplate -> WikiTask Tutorial/query2 result

expected result

1 subject: subject1 predicate: predicate1 object: object1

2 subject: subject2 predicate: predicate1 object: object1

3 subject: subject3 predicate: predicate1 object: object1

Union of queries

The statement:

<#assign query=tripleStore.query()/>
<#assign qSubjects1=query.query(null,"predicate1","object1")/>
<#assign qSubjects2=query.query(null,"predicate2","object1")/>
<#assign qSubjects3=query.query(null,"predicate3","object1")/>
<#assign qAllSubjects=qSubjects1.union(qSubjects2).union(qSubjects3)/>
<#list qAllSubjects.getTriples() as triple>
${triple_index+1} subject: ${triple.subject} predicate: ${triple.predicate} object: ${triple.object}<br>
</#list>

gets a specific query for the tripleStore. This query selects all triples of the tripleStore, which contain "predicate1","predicate2","predicate3" and "object1". To make an union of two different queries, you can use the method union() e.g. queryAll=query1.union(query2) The triples of this query are accessible with qAllSubjects.getTriples().

Example wikitask for a union of queries

{{wikitask|cmd=runtemplate|input=ex1|template=query3|targetpage=WikiTask Tutorial/query3 result}}

runtemplate -> WikiTask Tutorial/query3 result

expected result

1 subject: subject1 predicate: predicate1 object: object1
2 subject: subject2 predicate: predicate1 object: object1
3 subject: subject3 predicate: predicate1 object: object1
4 subject: subject1 predicate: predicate2 object: object1
5 subject: subject2 predicate: predicate2 object: object1
6 subject: subject3 predicate: predicate2 object: object1
7 subject: subject1 predicate: predicate3 object: object1
8 subject: subject2 predicate: predicate3 object: object1
9 subject: subject3 predicate: predicate3 object: object1