More examples
Here are some examples of PyQL program.
Example 1
Question
Is the ship with the largest payload among Cristóbal Colón, HMS Good Hope, and SMS Scharnhorst the slowest one?
Program
a=PyQL()
a.add_assignment(['Q1140473','Q1032039','Q533999'],'x2')
a.add_quantity('x2','P2109','x0')
a.add_max('x0')
b=PyQL()
b.add_assignment(['Q1140473','Q1032039','Q533999'],'x3')
b.add_quantity('x3','P2052','x1')
b.add_min('x1')
c=PyQL()
c.add_compare('x0','=','x1')
c.add_sub_query(a,b)
print(c.sparql)
sparql generated by the program above
SELECT ?x0 {
{
SELECT DISTINCT * {
Values ?x1 {wd:Q1140473 wd:Q1032039 wd:Q533999}
?x1 p:P2109 ?x2.
?x2 psv:P2109 ?x3.
?x3 wikibase:quantityAmount ?x1_playload.
}
ORDER BY DESC(?x1_playload)
LIMIT 1
}
{
SELECT DISTINCT * {
Values ?x5 {wd:Q1140473 wd:Q1032039 wd:Q533999}
?x5 p:P2052 ?x6.
?x6 psv:P2052 ?x7.
?x7 wikibase:quantityAmount ?x5_speed.
}
ORDER BY (?x5_speed)
LIMIT 1
}
BIND( (IF(?x1_playload = ?x5_speed, "TRUE", "FALSE")) AS ?x0 )
}
Example 2
Question
How many times does the difference in the longest span of Dardanelles Bridge and Morandi Bridge of that of Millau Viaduct?
Program
a=PyQL()
a.add_quantity('Q8077503','P2787','x4')
a.add_quantity('Q3907993','P2787','x3')
a.add_quantity('Q99236','P2787','x5')
a.add_bind(sub('x4','x3'),'x1')
a.add_bind(abs('x1'),'x2')
a.add_bind(div('x2','x5'),'x0')
print(a.sparql)
sparql generated by the program above
SELECT DISTINCT ?x0 {
wd:Q8077503 p:P2787 ?x1.
?x1 psv:P2787 ?x2.
?x2 wikibase:quantityAmount ?x3.
wd:Q3907993 p:P2787 ?x4.
?x4 psv:P2787 ?x5.
?x5 wikibase:quantityAmount ?x6.
wd:Q99236 p:P2787 ?x7.
?x7 psv:P2787 ?x8.
?x8 wikibase:quantityAmount ?x9.
BIND( ((?x3 - ?x6)) AS ?x10 )
BIND( (ABS(?x10)) AS ?x11 )
BIND( (?x11 / ?x9) AS ?x0 )
}
Last updated